dazayo-app2/main.py

43 lines
1005 B
Python

import sdtcloudpubsub
import time
import uuid
import random
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
mqttClient = sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
def runAction():
while True:
msg = [
{
"house_id": "JJ59",
"device_type": "water",
"pulse_count": random.randint(0, 1)
},
{
"house_id": "JJ59",
"device_type": "electricity",
"pulse_count": random.randint(0, 1)
},
{
"house_id": "JJ59",
"device_type": "gas",
"pulse_count": random.randint(0, 1)
},
{
"house_id": "JJ58",
"device_type": "water",
"pulse_count": random.randint(0, 1)
},
{
"house_id": "JJ58",
"device_type": "electricity",
"pulse_count": random.randint(0, 1)
}
]
sdtcloud.pubMessage(mqttClient, msg)
time.sleep(10)
if __name__ == "__main__":
runAction()