Subscribes to mqtt.
More...
|
|
str | BROKER = 'rpi.local' |
| | MQTT Broker Ip address.
|
| |
|
int | PORT = 1883 |
| | Port that the broker is running on.
|
| |
|
list | MQTT_TOPIC = [("esp32/id", 2), ("esp32/walk", 2)] |
| | (MQTT topic, QoS level) tuple
|
| |
|
str | DB_PATH = "db/iot.db" |
| | Path to the.
|
| |
|
str | client_id = f'subscribe-{random.randint(0, 100)}' |
| | Generate a Client ID with the subscribe prefix.
|
| |
|
dict | devices = {} |
| | (dev_address, device.Device) MAC address to object dictionary
|
| |
|
dict | sensors = {} |
| | (sensor_address, device.Sensor) Sensor Address to object dictionary
|
| |
◆ connect_mqtt()
| mqtt_client mqtt_sub.connect_mqtt |
( |
| ) |
|
Connects a Client to the MQTT broker.
- Returns
- MQTT Client object
Connects a Client to the MQTT broker
◆ extract_from_json()
| None mqtt_sub.extract_from_json |
( |
dict |
json_dict, |
|
|
int |
indent = 0 |
|
) |
| |
Extracts the data from a JSON Object.
- Parameters
-
| json_dict | A JSON object in the form of a dict object |
| indent | Number of spaces for printing nested JSON Objects (optional) |
Extracts the data from a JSON Object
◆ json_parse_device()
Parses a JSON Dict into a tuple of device and the sensors connected.
- Parameters
-
| json_dict | JSON Object in the form of a dictionary |
- Returns
- (Device Object, List of Sensor Objects)
Parses a JSON Dict into a tuple of device and the sensors connected
◆ json_parse_reading()
@briefParses a reading JSON object.
- Parameters
-
| json_dict | JSON object as a dictionary |
- Returns
- ReadingsWriter Object
Parses a reading JSON object.
◆ main()
Connects a client to the broker and subscribes to a given topic.
Connects a client to the broker and subscribes to a given topic
◆ parse_json()
| list mqtt_sub.parse_json |
( |
dict |
json_dict | ) |
|
Parses a JSON Dctionary into a list of Objects.
- Parameters
-
| json_dict | JSON Object in the form of a dictionary |
- Returns
- list List of objects (Device/Sensor/SensorReadings)
Parses a JSON Dctionary into a list of Objects
◆ subscribe()
| mqtt_sub.subscribe |
( |
mqtt_client |
client, |
|
|
sqlite3.Connection |
con |
|
) |
| |
Subscribes to a topic on the MQTT broker.
- Parameters
-
| client | MQTT Client |
| con | Sqlite3 Database connection |
Subscribes to a topic on the MQTT broker