2024-04-30 07:24:44 +00:00
|
|
|
import sdtcloudpubsub
|
2024-04-30 06:36:42 +00:00
|
|
|
import time
|
|
|
|
import uuid
|
2024-04-30 07:23:33 +00:00
|
|
|
import string
|
|
|
|
import random
|
2024-04-30 06:36:42 +00:00
|
|
|
|
2024-04-30 07:24:44 +00:00
|
|
|
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
|
|
|
sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
2024-04-30 06:36:42 +00:00
|
|
|
|
|
|
|
def runAction():
|
2024-04-30 07:23:33 +00:00
|
|
|
input_pressure = random.randint(1,3)
|
|
|
|
input_flow = random.randint(1,3)
|
|
|
|
output_pressure = random.randint(1,2)
|
|
|
|
output_flow = random.randint(1,3)
|
|
|
|
cpu_temperature = random.randint(50,60)
|
|
|
|
fan1_rpm = random.randint(500,1000)
|
|
|
|
fan2_rpm = random.randint(500,1000)
|
|
|
|
input_pressure_state = 1
|
|
|
|
input_flow_state = 1
|
|
|
|
output_pressure_state = 1
|
|
|
|
output_flow_state = 1
|
|
|
|
cpu_temperature_state = 1
|
|
|
|
fan1_rpm_state = 1
|
|
|
|
fan2_rpm_state = 1
|
|
|
|
|
|
|
|
|
|
|
|
characters1 = string.ascii_letters + string.digits
|
|
|
|
random_string1 = ''.join(random.choices(characters1, k=10))
|
|
|
|
characters2 = string.ascii_letters + string.digits
|
|
|
|
random_string2 = ''.join(random.choices(characters2, k=10))
|
|
|
|
characters3 = string.ascii_letters + string.digits
|
|
|
|
random_string3 = ''.join(random.choices(characters3, k=10))
|
|
|
|
|
2024-04-30 06:36:42 +00:00
|
|
|
while True:
|
2024-04-30 07:23:33 +00:00
|
|
|
up_value = random.uniform(1, 1.5)
|
|
|
|
|
|
|
|
if input_pressure > 10:
|
|
|
|
input_pressure_state = -1
|
|
|
|
elif input_pressure < 1:
|
|
|
|
input_pressure_state = 1
|
|
|
|
|
|
|
|
if input_flow > 10:
|
|
|
|
input_flow_state = -1
|
|
|
|
elif input_flow < 1:
|
|
|
|
input_flow_state = 1
|
|
|
|
|
|
|
|
if output_pressure > 6:
|
|
|
|
output_pressure_state = -1
|
|
|
|
elif output_pressure < 1:
|
|
|
|
output_pressure_state = 1
|
|
|
|
|
|
|
|
if output_flow > 10:
|
|
|
|
output_flow_state = -1
|
|
|
|
elif output_flow < 1:
|
|
|
|
output_flow_state = 1
|
|
|
|
|
|
|
|
if cpu_temperature > 90:
|
|
|
|
cpu_temperature_state = -1
|
|
|
|
elif cpu_temperature < 50:
|
|
|
|
cpu_temperature_state = 1
|
|
|
|
|
|
|
|
if fan1_rpm > 3600:
|
|
|
|
fan1_rpm_state = -1
|
|
|
|
elif fan1_rpm < 500:
|
|
|
|
fan1_rpm_state = 1
|
|
|
|
|
|
|
|
if fan2_rpm > 3600:
|
|
|
|
fan2_rpm_state = -1
|
|
|
|
elif fan2_rpm < 500:
|
|
|
|
fan2_rpm_state = 1
|
|
|
|
|
|
|
|
|
|
|
|
#characters1 = string.ascii_letters + string.digits
|
|
|
|
#random_string1 = ''.join(random.choices(characters1, k=10))
|
|
|
|
#characters2 = string.ascii_letters + string.digits
|
|
|
|
#random_string2 = ''.join(random.choices(characters2, k=10))
|
|
|
|
#characters3 = string.ascii_letters + string.digits
|
|
|
|
#random_string3 = ''.join(random.choices(characters3, k=10))
|
|
|
|
|
|
|
|
input_pressure = input_pressure + input_pressure_state * up_value # 1~10
|
|
|
|
input_flow = input_flow + input_flow_state * up_value # 1~10
|
|
|
|
output_pressure = output_pressure + output_pressure_state * up_value / 2 # 1~6
|
|
|
|
output_flow = output_flow + output_flow_state * up_value # 1~10
|
|
|
|
cpu_temperature = cpu_temperature + cpu_temperature_state * up_value * 4 # 50~90
|
|
|
|
fan1_rpm = fan1_rpm + fan1_rpm_state * up_value * 300 # 500~3600
|
|
|
|
fan2_rpm = fan2_rpm + fan2_rpm_state * up_value * 300 # 500~3600
|
|
|
|
|
|
|
|
|
2024-04-30 06:36:42 +00:00
|
|
|
msg = {
|
2024-04-30 07:23:33 +00:00
|
|
|
"input_pressure" : input_pressure, # 1~10
|
|
|
|
"input_flow" : input_flow, # 1~10
|
|
|
|
"output_pressure" : output_pressure, # 1~6
|
|
|
|
"output_flow" : output_flow, # 1~10
|
2024-04-30 06:36:42 +00:00
|
|
|
"Util_value":{
|
2024-04-30 07:23:33 +00:00
|
|
|
"cpu_temperature" : cpu_temperature, # 50~90
|
|
|
|
"fan1_rpm" : fan1_rpm, # 500~3600
|
|
|
|
"fan2_rpm" : fan2_rpm # 500~3600
|
2024-04-30 06:36:42 +00:00
|
|
|
},
|
|
|
|
"user_set_value":{
|
2024-04-30 07:23:33 +00:00
|
|
|
"input1_str" : characters1, # (10)string
|
|
|
|
"input2_str" : characters2, # (10)string
|
|
|
|
"input3_str" : characters3 # (10)string
|
2024-04-30 06:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-30 07:24:44 +00:00
|
|
|
sdtcloud.pubMessage(msg)
|
|
|
|
#print(msg)
|
2024-04-30 06:36:42 +00:00
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
runAction()
|
|
|
|
|