From ef268df60426ca31498a300f486216b4bcefe8d1 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Sat, 9 Dec 2023 15:41:05 +0800 Subject: [PATCH] update --- sensor_to_local.py | 45 +++++++++++++++++++++++-------------------- sensor_to_server.py | 47 ++++++++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/sensor_to_local.py b/sensor_to_local.py index 98b258f..c61b694 100755 --- a/sensor_to_local.py +++ b/sensor_to_local.py @@ -195,27 +195,30 @@ def local(): def test(): while True: - data = {'ambient_temperature': 1, - 'ambient_humidity': 1, - 'carbon_dioxide': 1, - 'ambient_air_pressure': 1, - 'ambient_lighting': 1, - 'soil_moisture': 1, - 'soil_temperature': 1, - 'soil_conductivity': 1, - 'soil_PH': 1, - 'soil_potassium_phosphate_nitrogen': 1, - 'soil_potassium_phosphate_phosphorus': 1, - 'soil_potassium_phosphate_potassium': 1, - 'rainfall': 1, - 'wind_speed': 1, - 'wind_direction': 1, - 'create_time': int(time.time()), - 'device_name': device_name - } - t2 = LOT_DATA(**data) - add(t2) - time.sleep(1) + try: + data = {'ambient_temperature': 1, + 'ambient_humidity': 1, + 'carbon_dioxide': 1, + 'ambient_air_pressure': 1, + 'ambient_lighting': 1, + 'soil_moisture': 1, + 'soil_temperature': 1, + 'soil_conductivity': 1, + 'soil_PH': 1, + 'soil_potassium_phosphate_nitrogen': 1, + 'soil_potassium_phosphate_phosphorus': 1, + 'soil_potassium_phosphate_potassium': 1, + 'rainfall': 1, + 'wind_speed': 1, + 'wind_direction': 1, + 'create_time': int(time.time()), + 'device_name': device_name + } + t2 = LOT_DATA(**data) + add(t2) + time.sleep(10) + except: + pass if __name__ == '__main__': diff --git a/sensor_to_server.py b/sensor_to_server.py index 22b3065..4107c82 100755 --- a/sensor_to_server.py +++ b/sensor_to_server.py @@ -198,28 +198,31 @@ def t(): def test(): while True: - data = {'ambient_temperature': 1, - 'ambient_humidity': 1, - 'carbon_dioxide': 1, - 'ambient_air_pressure': 1, - 'ambient_lighting': 1, - 'soil_moisture': 1, - 'soil_temperature': 1, - 'soil_conductivity': 1, - 'soil_PH': 1, - 'soil_potassium_phosphate_nitrogen': 1, - 'soil_potassium_phosphate_phosphorus': 1, - 'soil_potassium_phosphate_potassium': 1, - 'rainfall': 1, - 'wind_speed': 1, - 'wind_direction': 1, - 'create_time': int(time.time()), - 'device_name': device_name - } - t2 = LOT_DATA(**data) - client.publish('demo', payload=json.dumps(data, ensure_ascii=False), qos=0) - add(t2) - time.sleep(1) + try: + data = {'ambient_temperature': 1, + 'ambient_humidity': 1, + 'carbon_dioxide': 1, + 'ambient_air_pressure': 1, + 'ambient_lighting': 1, + 'soil_moisture': 1, + 'soil_temperature': 1, + 'soil_conductivity': 1, + 'soil_PH': 1, + 'soil_potassium_phosphate_nitrogen': 1, + 'soil_potassium_phosphate_phosphorus': 1, + 'soil_potassium_phosphate_potassium': 1, + 'rainfall': 1, + 'wind_speed': 1, + 'wind_direction': 1, + 'create_time': int(time.time()), + 'device_name': device_name + } + t2 = LOT_DATA(**data) + client.publish('demo', payload=json.dumps(data, ensure_ascii=False), qos=0) + add(t2) + time.sleep(10) + except: + pass def on_connect(client, userdata, flags, rc):