From de2440e167bacd1cebff432611d5d837dfeddffd Mon Sep 17 00:00:00 2001
From: Roman Bazalevsky <rvb@rvb.name>
Date: Wed, 14 Nov 2018 19:06:22 +0300
Subject: [PATCH] =?utf8?q?=D0=9E=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?=
 =?utf8?q?=D0=B8=D0=B5=20=D0=B1=D1=83=D1=84=D0=B5=D1=80=D0=B8=D0=B7=D0=B0?=
 =?utf8?q?=D1=86=D0=B8=D0=B8=20=D1=88=D1=82=D0=B0=D1=82=D0=BD=D1=8B=D0=BC?=
 =?utf8?q?=D0=B8=20=D1=81=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B2=D0=B0=D0=BC?=
 =?utf8?q?=D0=B8=20lua.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 bin/weathermon     | 10 +++++++---
 bin/weathermon-iio |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/bin/weathermon b/bin/weathermon
index 6980cc8..b8be15f 100755
--- a/bin/weathermon
+++ b/bin/weathermon
@@ -118,7 +118,9 @@ end
 
 function submitValue(type,id,param,val)
 
-  if web_url then
+  val = tonumber(val)
+
+  if web_url and val then
 
     local url = web_url.."?stype="..url_encode(type).."&sid="..url_encode(id).."&param="..url_encode(param).."&value="..url_encode(val)
 
@@ -133,8 +135,8 @@ function submitValue(type,id,param,val)
         return req_sock
       end})
 
-    if code ~= 200 then
-      print("writing record to backlog...")
+    if code ~= 200 and backlog_con then
+      printLog("writing record to backlog...")
       backlog_con:execute(string.format("INSERT INTO queue(time_stamp,sensor_id,sensor,param,value) VALUES (datetime('now','localtime'),'%s','%s','%s',%f)",id,type,param,val))
     end
 
@@ -385,6 +387,8 @@ else
   return
 end  
 
+serialin:setvbuf('no')
+
 records = {}
 
 while 1 do
diff --git a/bin/weathermon-iio b/bin/weathermon-iio
index df32c3a..cbf21f0 100755
--- a/bin/weathermon-iio
+++ b/bin/weathermon-iio
@@ -188,6 +188,8 @@ if not delay then
   delay = 60
 end
 
+io.stdout:setvbuf('no')
+
 while true do
   if pcall(function () values = get_parameters(parameters) end) then
     records = {}
-- 
2.34.1