112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
#import sdtcloudpubsub
|
|
import time
|
|
import uuid
|
|
import string
|
|
import random
|
|
|
|
#sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
|
#sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
|
|
|
def runAction():
|
|
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))
|
|
|
|
while True:
|
|
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
|
|
|
|
|
|
msg = {
|
|
"input_pressure" : input_pressure, # 1~10
|
|
"input_flow" : input_flow, # 1~10
|
|
"output_pressure" : output_pressure, # 1~6
|
|
"output_flow" : output_flow, # 1~10
|
|
"Util_value":{
|
|
"cpu_temperature" : cpu_temperature, # 50~90
|
|
"fan1_rpm" : fan1_rpm, # 500~3600
|
|
"fan2_rpm" : fan2_rpm # 500~3600
|
|
},
|
|
"user_set_value":{
|
|
"input1_str" : characters1, # (10)string
|
|
"input2_str" : characters2, # (10)string
|
|
"input3_str" : characters3 # (10)string
|
|
}
|
|
}
|
|
#sdtcloud.pubMessage(msg)
|
|
print(msg)
|
|
time.sleep(2)
|
|
|
|
if __name__ == "__main__":
|
|
runAction()
|
|
|