76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
|
import sdtcloudpubsub
|
||
|
import time
|
||
|
import uuid
|
||
|
import random
|
||
|
|
||
|
# call sdtcloudpubsub
|
||
|
sdtcloudMqttClient = sdtcloudpubsub.sdtcloudpubsub()
|
||
|
sdtcloudMqttClient.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
||
|
|
||
|
def runAction():
|
||
|
while True:
|
||
|
index = random.randint(0, 10) # float
|
||
|
if index < 5:
|
||
|
openValue = "ture"
|
||
|
else:
|
||
|
openValue = "false"
|
||
|
|
||
|
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(data)
|
||
|
time.sleep(10)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
runAction()
|
||
|
|