2024-03-07 09:33:19 +00:00
|
|
|
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
|
2024-03-07 09:35:23 +00:00
|
|
|
"open": openValue,
|
2024-03-07 09:33:19 +00:00
|
|
|
"image": result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sdtcloudMqttClient.pubMessage(mqttClient, data)
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
runAction()
|
|
|
|
|