gseps-app-mqtt-s3/main.py

86 lines
2.3 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 = "ture"
else:
openValue = "false"
pngIndex = random.randint(0,2)
pngList = ["./test1.png", "./test2.png", "./test3.png"]
result = sdtcloudS3Client.uploadData(pngList[pngIndex], {"ContentType": "image/png"})
timedata = int(time.time()*1000)
data = {
"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
}
}
sdtcloudMqttClient.pubMessage(mqttClient, data)
time.sleep(10)
if __name__ == "__main__":
runAction()