From 0d332cb66939747237ce374275f5719acc2354f5 Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Tue, 2 Jun 2020 17:16:25 +0300 Subject: [PATCH] =?utf8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?utf8?q?=D0=B0=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= =?utf8?q?=20MQTT=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B5=20?= =?utf8?q?rtl=5F433?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- server/weathermon-mqtt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/weathermon-mqtt b/server/weathermon-mqtt index 025deec..809b4e9 100755 --- a/server/weathermon-mqtt +++ b/server/weathermon-mqtt @@ -15,15 +15,25 @@ end function process_MSG(mid, topic, payload) print(topic, payload) pcall(function(topic,payload) + print(payload) payload = json.decode(payload) local time = os.date(payload['Time']) + if not time then time = os.date(payload['time']); end + local model = payload['model'] + local id = payload['id'] for sensor_type,sensor_data in pairs(payload) do - if sensor_type ~= "Time" and sensor_type ~= "TempUnit" then - for param,value in pairs(sensor_data) do - conn:execute(string.format("CALL meteo.submit_mqtt('%s','%s','%s','%s',NULL)", topic,sensor_type,param,value)) + if sensor_type ~= "Time" and sensor_type ~= "TempUnit" and sensor_type ~= "model" and sensor_type ~="id" and sensor_type ~= "time" then + if model then + conn:execute(string.format("CALL meteo.submit_mqtt('%s','%s','%s','%s',NULL)", topic,model,sensor_type,sensor_data)) conn:commit() - print(topic,sensor_type,param,value) - end + print(topic,model,sensor_type,sensor_data) + else + for param,value in pairs(sensor_data) do + conn:execute(string.format("CALL meteo.submit_mqtt('%s','%s','%s','%s',NULL)", topic,sensor_type,param,value)) + conn:commit() + print(topic,sensor_type,param,value) + end + end end end end, topic, payload) -- 2.34.1