-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (37 loc) · 1.61 KB
/
main.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 logging
import ssl
import sys
import threading
import time
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
from src import auth, costants, data_acquisition, data_storing, mqtt_comm
def main() -> None:
"""
Turns on the back end of the project
"""
client_id = "back-end"
endpoint = "a1o1h9paav6wpy-ats.iot.eu-west-2.amazonaws.com"
port = 8883
CA_path = "./certificates/AmazonRootCA1.pem"
privateKey_path = "./certificates/privateKey.pem"
certificate_path = "./certificates/certificate.pem"
incoming_topic = "arduino/outgoing"
outgoing_topic = "backend/outgoing"
aws_client = mqtt_comm.configure_client(client_id=client_id,
endpoint=endpoint,
port=port,
CA_path=CA_path,
privateKey_path=privateKey_path,
certificate_path=certificate_path)
mqtt_comm.connect_client(client=aws_client)
#### SUBSCRIBER
#### It subscribes to the topic "arduino/outgoing" (whee the arduino publishes)
#### and when he receives a message from the arduino it automatically publish
#### a message on the topic "backend/outgoing" so that when we have the connection
#### to the DB it can query the DB a send back the result to the arduino.
mqtt_comm.subscribe_to_topic(client=aws_client,
topic=incoming_topic,
callback_function=mqtt_comm.handle_arduino_message)
if __name__=="__main__":
main()