gseps-app-mqtt-s3/main.py

46 lines
1.2 KiB
Python

import sdtcloudpubsub
import sdtclouds3
import time
import uuid
import random
# call sdtcloudpubsub
sdtcloudMqttClient = sdtcloudpubsub.sdtcloudpubsub()
mqttClient = sdtcloudMqttClient.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
# call sdtclouds3
sdtcloudS3Client = sdtclouds3.sdtclouds3()
def runAction():
while True:
index = random.randint(0, 10) # float
if index < 5:
openValue = "open"
else:
openValue = "close"
pngIndex = random.randint(0,2)
pngList = ["./test1.png", "./test2.png", "./test3.png"]
result = sdtcloudS3Client.uploadData(pngList[pngIndex], {"ContentType": "image/png"})
data = {
"temperature": random.uniform(0, 30), # float
"water_level": random.randint(0, 30), # int,
"open": openValue, # string
"image": result,
"data": {
"temperature": random.uniform(0, 30), # float
"water_level": random.randint(0, 30), # int
"open": openValue
"image": result
}
}
sdtcloudMqttClient.pubMessage(mqttClient, data)
time.sleep(10)
if __name__ == "__main__":
runAction()