gseps-app-mqtt-s3/main.py

86 lines
2.3 KiB
Python
Raw Permalink Normal View History

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:
2024-03-08 05:45:25 +00:00
openValue = "ture"
2024-03-07 09:33:19 +00:00
else:
2024-03-08 05:45:25 +00:00
openValue = "false"
2024-03-07 09:33:19 +00:00
pngIndex = random.randint(0,2)
pngList = ["./test1.png", "./test2.png", "./test3.png"]
result = sdtcloudS3Client.uploadData(pngList[pngIndex], {"ContentType": "image/png"})
2024-03-08 05:45:25 +00:00
timedata = int(time.time()*1000)
2024-03-07 09:33:19 +00:00
data = {
2024-03-08 05:45:25 +00:00
"rssi": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"gas_o2": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"gas_h2s": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"rsrp": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"battery": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"sinr": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"rsrq": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"temperature": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"ph": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"humidity": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"water_level": {
"value": random.uniform(0, 30), # float,
"timestamp": timedata
},
"open": {
"value": openValue,
"timestamp": timedata
2024-03-07 09:33:19 +00:00
}
}
2024-03-08 05:45:25 +00:00
2024-03-07 09:33:19 +00:00
sdtcloudMqttClient.pubMessage(mqttClient, data)
time.sleep(10)
if __name__ == "__main__":
runAction()