-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambda_function.py
49 lines (41 loc) · 1.26 KB
/
lambda_function.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
48
49
import paho.mqtt.client as mqtt
import time
import random
import json
def publish(client,topic):
client.publish(topic)
def main(event, context):
message = event['queryStringParameters']['topic']
if message == "openDoor":
solace_topic = "openDoor"
elif message == "closeDoor":
solace_topic = "closeDoor"
elif message == "light":
solace_topic = "light"
elif message == "fan":
solace_topic = "fan"
elif message == "music":
solace_topic = "music"
elif message == "alarm":
solace_topic = "alarm"
else:
solace_topic = "blank"
# Connection parameters for Solace Event broker
solace_url = "mr2ko4me0p6h2f.messaging.solace.cloud"
solace_port = 20134
solace_user = "solace-cloud-client"
solace_passwd = "password"
solace_clientid = "lambda"
# Instantiate/connect to mqtt client
client = mqtt.Client(solace_clientid)
client.username_pw_set(username=solace_user, password=solace_passwd)
client.connect(solace_url, port=solace_port)
client.loop_start()
# Publishes message to the MQTT bridge
publish(client, solace_topic)
client.loop_stop()
client.disconnect()
return {
'statusCode': 200,
'body': "Success"
}