optimizations
optimizations

 Binary files a/barometer-forecasting-table.jpg and /dev/null differ
file:a/config.lua -> file:b/config.lua
--- a/config.lua
+++ b/config.lua
@@ -18,8 +18,8 @@
 mqttConfig.host = ''
 mqttConfig.port = ''
 mqttConfig.user = ''
-mqttConfig.pass = 'iot'
-mqttConfig.secure = 0
+mqttConfig.pass = ''
+mqttConfig.secure = false
 mqttConfig.connected = false
 
 sData = {}
@@ -31,6 +31,7 @@
 sData.altitude = 0
 sData.pageName = "Comana weather station"
 sData.pageId = 50
+sData.pageOrder = 100
 sData.widget = "data"
 sData.title = "Summer kitchen temperature"
 sData.topic = prefix .. device ..'/ws1'

file:a/func.lua -> file:b/func.lua
--- a/func.lua
+++ b/func.lua
@@ -24,10 +24,11 @@
     return string.format("%02d/%02d/%04d %02d:%02d",  tm["day"], tm["mon"], tm["year"], tm["hour"], tm["min"])
 end
 
-function lcdPrint(txt)
-    if serialDebug then print(txt) end
-    disp:setColor(255, 0, 0);
-    disp:drawBox(0, 210, 320, 20);
+function lcdPrint(txt, txt1)
+    txt1 = txt1 or ''
+    if serialDebug then print(txt, txt1) end
+    disp:setColor(255, 0, 0)
+    disp:drawBox(0, 210, 320, 20)
     disp:setPrintPos(2, 225)
     disp:setColor(255, 255, 255);
     disp:setFont(ucg.font_7x13B_tr)
@@ -36,7 +37,7 @@
     tmr.stop(2)
     tmr.alarm(2, 10000, 1, function()
         disp:setColor(0, 0, 0);
-        disp:drawBox(0, 201, 320,30);
+        disp:drawBox(0, 205, 320, 25);
         tmr.stop(2)
     end)
 end
@@ -124,6 +125,8 @@
     end
 
     if mqttConfig.connected == true then
+        sData.value = sData.temperature
+        sData.valueappend = " C"
         mqtt:publish(sData.topic .. "/config", sjson.encode(sData), 1, 0, function(conn)
         end)
     end

 Binary files /dev/null and b/info/barometer-forecasting-table.jpg differ
 Binary files /dev/null and b/info/screenshot.jpg differ
 Binary files /dev/null and b/info/wifiweatherstation.jpg differ
file:a/init.lua -> file:b/init.lua
--- a/init.lua
+++ b/init.lua
@@ -21,7 +21,7 @@
     disp:setRotate90()
 
     disp:setFont(ucg.font_helvB18_hr)
-    disp:setColor(255, 255, 255);
+    disp:setColor(255, 255, 255)
     disp:setPrintPos((disp:getWidth() - disp:getStrWidth(deviceTitle)) / 2, 25)
     disp:print(deviceTitle)
 
@@ -29,7 +29,7 @@
     printText("Humidity", 18, 5, 120)
     printText("Pressure", 18, 5, 150)
     printText("50", 10, 292, 47)
-    printText("-20", 10, 290, 204)
+    printText("-20", 10, 290, 206)
 
     --disp:drawFrame(20, 93, 42, 102)
 
@@ -82,7 +82,7 @@
             function(err, str)
                 lcdPrint("enduser_setup: Err #" .. err .. ": " .. str)
             end
-        );
+        )
 
         tmr.alarm(0, 3000, 1, function()
             if wifi.sta.getip()==nil then

file:a/mqtt.lua -> file:b/mqtt.lua
--- a/mqtt.lua
+++ b/mqtt.lua
@@ -15,12 +15,21 @@
 
 -- initiate the mqtt client and set keepalive timer to 120sec
 if mqttConfig.enabled == true then
-    mqtt = mqtt.Client(device, 120, mqttConfig.user, mqttConfig.pass, 1)
 
-    mqtt:on("connect", function(con)
+    function onConnect()
         lcdPrint("\tConnected to " .. mqttConfig.host .. ":" .. mqttConfig.port .. " MQTT broker\n")
+        mqttConfig.connected = true
+        -- subscribe topic with qos = 1
+        mqtt:subscribe({[prefix .. "/+/+/data"]=1, [prefix .. "/device"]=1}, function(conn)
+        end)
+    end
+
+    mqtt = mqtt.Client(device, 120, mqttConfig.user, mqttConfig.pass, true)
+
+    mqtt:on("connect", function(conn)
+        onConnect()
     end)
-    mqtt:on("offline", function(con)
+    mqtt:on("offline", function(conn)
         lcdPrint("\tDisconected from " .. mqttConfig.host .. ":" .. mqttConfig.port .. " MQTT broker, reconnecting\n")
         mqttConfig.connected = false
     end)
@@ -38,23 +47,24 @@
         end
 
         if topic == prefix .. "/device" then
-            lcdPrint('\tNew request from IoT Control Center: clientId="' .. json.clientId .. '"');
+            lcdPrint('\tNew request from IoT Control Center: clientId="' .. json.clientId .. '"')
             if json.time then
                 rtctime.set(json.time + timezoneHours * 60 * 60, 0)
                 update()
             end
-            mqtt:publish(prefix .. device .. "/device", '{"pages" : [{"pageId" : 50, "pageName" : "Weather stations", "icon": "fa fa-thermometer-quarter"}]}', 1, 0, function(conn)
+            mqtt:publish(prefix .. device .. "/device", '{"pages" : [{"id" : 50, "name" : "Weather stations", "icon": "fa fa-thermometer-quarter", "order": "1000"}]}', 1, 0, function(conn)
             end)
             update()
         end
     end)
 
     mqtt:connect(mqttConfig.host, mqttConfig.port, mqttConfig.secure, function(conn)
-        lcdPrint("\tConnected to " .. mqttConfig.host .. ":" .. mqttConfig.port .. " MQTT broker\n")
-        mqttConfig.connected = true
-        -- subscribe topic with qos = 1
-        mqtt:subscribe({[prefix .. "/+/+/data"]=1, [prefix .. "/device"]=1}, function(conn)
-        end)
+            onConnect()
+        end,
+        function(conn, reason)
+            print("\tCould not connect to MQTT server")
+            print("\tClient ", conn)
+            print("\tReason ", reason)
     end)
 end
 

file:a/readme.md -> file:b/readme.md
--- a/readme.md
+++ b/readme.md
@@ -4,11 +4,11 @@
 * integrated with IoTCC using mqtt
 * display on SPI TFT LCD
 * NTP time sync
-* debug un serial and LCD
+* debug on serial and LCD
 
 ## WIP
 * integration with PWS
-* forcast
+* forcast via external webservice (based on pressure) due to low memory
 
 ## SPI setup to connect display in func.lua
 Initialize the matching driver for your display. All available are here http://nodemcu.readthedocs.io/en/master/en/modules/ucg/#display-drivers
@@ -48,3 +48,5 @@
 * wifi
 * tls
 
+### Comana weather station
+![Alt text](/info/screenshot.jpg?raw=true "Comana weather station")

file:a/wifiweatherstation.jpg (deleted)
 Binary files a/wifiweatherstation.jpg and /dev/null differ
comments