Add forwarder
This commit is contained in:
parent
517decc31e
commit
58916d7f87
@ -61,6 +61,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./configuration/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
|
- ./configuration/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
|
||||||
|
|
||||||
|
forwarder:
|
||||||
|
build: ./forwarder
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgresqldata:
|
postgresqldata:
|
||||||
redisdata:
|
redisdata:
|
||||||
|
12
forwarder/Dockerfile
Normal file
12
forwarder/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
FROM python:3.7-slim-buster
|
||||||
|
COPY requirements.txt ./
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y cmake
|
||||||
|
RUN pip install -r ./requirements.txt
|
||||||
|
|
||||||
|
COPY app.py ./
|
||||||
|
|
||||||
|
CMD ["python", "app.py"]
|
||||||
|
|
||||||
|
RUN adduser --system forwarder
|
||||||
|
USER forwarder
|
38
forwarder/app.py
Normal file
38
forwarder/app.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
# import awsiot.greengrasscoreipc
|
||||||
|
# import awsiot.greengrasscoreipc.client as client
|
||||||
|
# import awsiot.greengrasscoreipc.model as model
|
||||||
|
import json
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
# ipc_client = awsiot.greengrasscoreipc.connect()
|
||||||
|
|
||||||
|
print(os.environ)
|
||||||
|
|
||||||
|
def on_connect(client, userdata, flags, rc):
|
||||||
|
print("Connected with result code "+str(rc))
|
||||||
|
client.subscribe("application/+/device/+/event/up")
|
||||||
|
|
||||||
|
def on_message(client, userdata, msg):
|
||||||
|
payload = json.loads(str(msg.payload.decode("utf-8")))
|
||||||
|
print(payload['object'])
|
||||||
|
message = {
|
||||||
|
payload: payload['object']
|
||||||
|
}
|
||||||
|
print(message)
|
||||||
|
# publish_operation = ipc_client.new_publish_to_iot_core()
|
||||||
|
# publish_operation.activate(
|
||||||
|
# request = model.PublishToIoTCoreRequest(
|
||||||
|
# topic_name = 'MCT/PY/FD',
|
||||||
|
# qos = model.QOS.AT_MOST_ONCE,
|
||||||
|
# payload = json.dumps(message).encode()
|
||||||
|
# )
|
||||||
|
# )
|
||||||
|
|
||||||
|
client = mqtt.Client()
|
||||||
|
client.on_connect = on_connect
|
||||||
|
client.on_message = on_message
|
||||||
|
|
||||||
|
client.connect("mosquitto", 1883, 60)
|
||||||
|
|
||||||
|
client.loop_forever()
|
2
forwarder/requirements.txt
Normal file
2
forwarder/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
awsiotsdk==1.7.1
|
||||||
|
paho-mqtt==1.6.1
|
Loading…
Reference in New Issue
Block a user