-
Notifications
You must be signed in to change notification settings - Fork 0
/
EdgeServer.py
47 lines (36 loc) · 1.34 KB
/
EdgeServer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import time
import paho.mqtt.client as mqtt
HOST = "localhost"
PORT = 1883
WAIT_TIME = 0.25
class Edge_Server:
def __init__(self, instance_name):
self._instance_id = instance_name
self.client = mqtt.Client(self._instance_id)
self.client.on_connect = self._on_connect
self.client.on_message = self._on_message
self.client.connect(HOST, PORT, keepalive=60)
self.client.loop_start()
self._registered_list = []
# Terminating the MQTT broker and stopping the execution
def terminate(self):
self.client.disconnect()
self.client.loop_stop()
# Connect method to subscribe to various topics.
def _on_connect(self, client, userdata, flags, result_code):
pass
# method to process the recieved messages and publish them on relevant topics
# this method can also be used to take the action based on received commands
def _on_message(self, client, userdata, msg):
pass
# Returning the current registered list
def get_registered_device_list(self):
return self._registered_list
# Getting the status for the connected devices
def get_status(self):
pass
# Controlling and performing the operations on the devices
# based on the request received
def set(self):
pass