Wednesday, 17 April 2019

Sonoff restart concerns

I just posted this to the WhatsApp "Kilnageer CH 2019" for Bren and Liam to consider.

"I have concerns regarding what state the sonoffs power up into and/or restore after a reboot or wifi drop. See this excellent article:
http://www.thesmarthomehookup.com/end-random-ghost-switching-for-good-by-fixing-your-retain-settings-in-tasmota-and-home-assistant/

I think the safest but least elegant solution is to configure the sonoffs to power up/restart in off but for their controllers (Node-Red web  MQTT Dash android app) to publish retained to a shadow topic. And for a Node-Red script to loop every 5 secs to ensure the sonoffs follow these user defined shadow values.

This script can also check for safety concerns and take action. For example, if burner is on but no zones/cylinder to turn it off and e-mail registered users.

I'm setting up a spare router in Shannon to mimic the Kilnageer set-up so I can experient with this solution here before deploying in Kilnageer next visit.

Any questions/suggestions?"



Tuesday, 16 April 2019

Will demo sonoff/tasmota light switch in the Men's Shed this morning

https://github.com/arendst/Sonoff-Tasmota/wiki/Button-usage

So three short presses gets the SSID menu up on SSID sonoff_3536-3536 and IP 192.168.4.1

Then got tablet and sonoff to connect to MensShed hotspot (no internet) provided by phone.

192.168.43.103 is the sonoff when its using the MensShed SSID

Sunday, 14 April 2019

Switching from Lua to micro Python to get MQTT connect on NodeMcu to work..

(7:48) rad 11.5 / 10.6 manually turn on zone and burner

(8:11) rad 49.8 / 12.8

Why isn't MQTT Dash updating the icon status every few minutes?



Current Eir router LAN map

5C:CF:7F:40:CD:D0_Wireless 5C:CF:7F:40:CD:D0 192.168.1.100 Tony's Lamp (3536)
2C:3A:E8:07:B8:4F_Wireless 2C:3A:E8:07:B8:4F 192.168.1.103  Extension zone MV (6223)
2C:3A:E8:0F:4D:99_Wireless 2C:3A:E8:0F:4D:99 192.168.1.102 Cylinder MV (3481)
2C:3A:E8:0F:4C:E8_Wireless 2C:3A:E8:0F:4C:E8 192.168.1.101  Bedroom zone MV (3304)
EC:FA:BC:86:D5:E4_Wireless EC:FA:BC:86:D5:E4 192.168.1.108 Oil burner (5604)
2C:3A:E8:4F:4D:02_Wireless 2C:3A:E8:4F:4D:02 192.168.1.106  Living zone MV (3330)
5C:CF:7F:67:29:50_Wireless 5C:CF:7F:67:29:50 192.168.1.107  Shower pump (2384)

(8:11) rad 47.1 / 15.4 burner was off so put it back on

Currently, MQTT Dash is subscribing to "stat/sonoff_6223/POWER"  which is "ON" or "OFF" but will only see last value.

But needs to subscribe to "tele/sonoff_6223/STATE" which is published every 5 mins (300 secs) as:
{"Time":"2019-04-14T08:42:33","Uptime":"0T11:33:24","Vcc":3.495,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"vodafone-2124","BSSId":"D0:FF:98:1B:31:3C","Channel":9,"RSSI":76}}

And to change this period on each sonoff to 5 secs. But what script will extract the "ON" field?

(8:49) rad 47.8 / 16.1 but my hands are still cold

(9:25) rad 30.9 / 16.1 (I was messing with MQTT Dash and turned off zone by accident)

Made all seven sonoff static IPs in Eir router (are lamp IP jumped after reboot!)
5C:CF:7F:40:CD:D0_Ethernet 5C:CF:7F:40:CD:D0 192.168.1.115 Tony's Lamp (3536)
2C:3A:E8:07:B8:4F_Wireless 2C:3A:E8:07:B8:4F 192.168.1.101  Extension zone MV (6223)
2C:3A:E8:0F:4D:99_Wireless 2C:3A:E8:0F:4D:99 192.168.1.116 Cylinder MV (3481)
2C:3A:E8:0F:4C:E8_Wireless 2C:3A:E8:0F:4C:E8 192.168.1.103  Bedroom zone MV (3304)
EC:FA:BC:86:D5:E4_Wireless EC:FA:BC:86:D5:E4 192.168.1.105 Oil burner (5604)
2C:3A:E8:4F:4D:02_Wireless 2C:3A:E8:4F:4D:02 192.168.1.106  Living zone MV (3330)
5C:CF:7F:67:29:50_Wireless 5C:CF:7F:67:29:50 192.168.1.107  Shower pump (2384)

(9:57) rad 32.0 / 16.2 (zone was off again!)

"event.payload" no good in "on receive" displays nothing!
"POWER" causes an error message which is something I suppose
"event[POWER]" same message
"print event" missing ; before statement
"print( event );" - print is not defined
"print event ;" missing ; before statement
"$" - $ is not defined
"@" missing name after @
"@.POWER" missing name after @
"@POWER" cannot read property "@"":POWER" from undefined
"val" is not defined
event


(10:54) 49.2 / 18.2 turned zone off

(11:16) 
event.payload = event.payload.split(',')[6].split(':')[1];

works for a text box

(14:36) rad 16.8 / 14.4

So a bit of a dilemna

So there are currently four ways to turn a sonoff on or off, say for my light
1) Using Node-Red by pointing a browser to: http://192.168.1.105:1880/ui
2) Pressing a MQTT Dash app button
3) Manually pressing the button on each unit
4) Point a browser to the IP address of a sonoff and clicking the"Toggle" button

They will each be done by or cause "ON" or "OFF" to be published to MQTT topic  "cmnd/sonoff_3536/POWER". And on being actioned to "stat/sonoff_3536/POWER". If this is done with the "retained" flag set in all four cases then anybody launching the app or going to that website and subscribing to topic "stat/sonoff_3536/POWER" will instantly get the latest sonoff status.

Great write-up
http://www.thesmarthomehookup.com/end-random-ghost-switching-for-good-by-fixing-your-retain-settings-in-tasmota-and-home-assistant/

"switchretain on" using console resulted in:
15:27:04 CMD: switchretain on
15:27:04 MQT: stat/sonoff_3536/RESULT = {"SwitchRetain":"ON"}

"buttonretain on" ..
15:28:13 CMD: buttonretain on
15:28:13 MQT: stat/sonoff_3536/RESULT = {"ButtonRetain":"ON"}

"powerretain on"
15:28:54 CMD: powerretain on
15:28:54 MQT: stat/sonoff_3536/RESULT = {"PowerRetain":"ON"}

(16:22) 16.9 / 17.5 (using the electric fan heater)

Finally trying micro Python
https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html
http://micropython.org/download#esp8266
Flashed to board using NodeMcu PyFlasher (frontend for esptool.py)
Command: esptool.py --port COM8 --baud 115200 --after no_reset write_flash --flash_mode dio 0x00000 C:\Users\kilnageer\Documents\CoderDojo\2018 Reboot\CH Project\NodeMcu\esp8266-20190125-v1.10.bin --erase-all

Worked fine then reset board and used ESPlorer for UART window

MicroPython v1.10-8-g8b7039d7d on 2019-01-26; ESP module with ESP8266
Type "help()" for more information.
>>> 
>> 
help()
help()
Welcome to MicroPython!

For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .
For diagnostic information to include in bug reports execute 'import port_diag'.

Basic WiFi configuration:

import network
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if.scan()                             # Scan for available access points
sta_if.connect("<AP_name>", "<password>") # Connect to an AP
sta_if.isconnected()                      # Check for successful connection
# Change name/password of ESP8266's AP:
ap_if = network.WLAN(network.AP_IF)
ap_if.config(essid="<AP_NAME>", authmode=network.AUTH_WPA_WPA2_PSK, password="<password>")

Control commands:
  CTRL-A        -- on a blank line, enter raw REPL mode
  CTRL-B        -- on a blank line, enter normal REPL mode
  CTRL-C        -- interrupt a running program
  CTRL-D        -- on a blank line, do a soft reset of the board
  CTRL-E        -- on a blank line, enter paste mode

For further help on a specific object, type help(obj)
>>>

Did above commands to connect
import network
import network
>>> 
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
#6 ets_task(4020f4d0, 28, 3fff9e28, 10)
>>> 
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
>>> sta_if.scan() 
sta_if.scan() 
[(b'vodafone-2124', b'\xe8\xab\xfa\xb0\xc4D', 1, -53, 3, 0)]
>>> sta_if.connect("vodafone-2124", PASSWORD )
sta_if.connect("vodafone-2124", PASSWORD )
>>> sta_if.isconnected()
sta_if.isconnected()
True
>>> 
ESP_2871DF_EthernetEC:FA:BC:28:71:DF192.168.1.112

http://micropython.org/webrepl/


(23:17) Two issues have come to light:

1) Some sonoffs drop LAN connection every few minutes (especially Extension Zone MV)
2) They don't restore their retained setting. A bug? Instead they restore the last one set by Node-Red.

So ensure that Node-Red is used to set the sonoffs. Otherwise their settings can change.

I'll investigate more tomorrow.


Saturday, 13 April 2019

New Eir router in Kilnageer..

Have new Eir router in Kilnageer (installed yesterday) so must reserved IP addresses..

NetworkDeviceMAC AddressIP Address
2.4GHz Wireless:android-84-B5-41-08-B2-0284:B5:41:08:B2:02192.168.1.3
5C:CF:7F:40:CD:D0_Wireless5C:CF:7F:40:CD:D0192.168.1.4
android-AC-37-43-0B-8D-81AC:37:43:0B:8D:81192.168.1.5
2C:3A:E8:07:B8:4F_Wireless2C:3A:E8:07:B8:4F192.168.1.8
mayo_rpi_zero_logger_3_WirelessB8:27:EB:C8:19:85192.168.1.9
2C:3A:E8:0F:4D:99_Wireless2C:3A:E8:0F:4D:99192.168.1.10
2C:3A:E8:0F:4C:E8_Wireless2C:3A:E8:0F:4C:E8192.168.1.11
EC:FA:BC:86:D5:E4_WirelessEC:FA:BC:86:D5:E4192.168.1.12
2C:3A:E8:4F:4D:02_Wireless2C:3A:E8:4F:4D:02192.168.1.13
5C:CF:7F:67:29:50_Wireless5C:CF:7F:67:29:50192.168.1.14

Sadly cannot use the same ones as Vodafone router so had to reconfigure all 6 sonoffs to use 192.168.1.105 as their MQTT broker.

Luckily, Node-Red was using MQTT topics and "mayo_rpi_zero_logger_3" rather than IP address.

Now back to getting the temp/humidity probes working. The one left on the window sill had died so battery only good for Wed/Thurs/Fri/Sat 4 days tops currently. I want it to be good for 6 months+

Started debug build of  "You successfully commissioned a NodeMCU custom build from the master branch. You selected the following 9 modules: dht file gpio mqtt net node tmr uart wifi." at nodemcu-build.com
nodemcu-master-9-modules-2019-04-13-21-50-11-integer.bin

May move to latest dev build if debug doesn't show anything. Also is my MQTT broker compatible? It's version 1.4.10 whereas MQTT firmware is ..

https://nodemcu.readthedocs.io/en/master/modules/mqtt/#mqttclientpublish
"The client adheres to version 3.1.1 of the MQTT protocol. Make sure that your broker supports and is correctly configured for version 3.1.1. The client is backwards incompatible with brokers running MQTT 3.1."

So that could be an issue. But I was able to publish once upon a time.


_flash_used_end:4026c000
fs.start:70000,max:38b000
_flash_used_end:4026c000
fs.start:70000,max:38a000
_flash_used_end:4026c000
fs.start:80000,max:37b000
_flash_used_end:4026c000
fs.start:80000,max:37a000
mount res: 0, 0
Task task_lua started.
nul mode, fpm auto sleep set:enalbe

NodeMCU custom build by frightanic.com
branch: master
commit: 4905381c004bdeaf744a60bb940c1906c2e052d4
SSL: false
modules: dht,file,gpio,mqtt,net,node,tmr,uart,wifi
 build created on 2019-04-13 21:49
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
NodeMcu Kilnageer probe v1.9 13-Apr-19
node ID = 2650591
time now = 277378
uptime = 0
boot reason = 2
Configuring WIFI..
nil
scandone
scandone
> Heap size:34280.

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:8)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 2
cnt

connected with vodafone-2124, channel 1
dhcp client start...

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:0)
ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
IP unavaiable, Waiting...
ip:192.168.1.112,mask:255.255.255.0,gw:192.168.1.254

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:3)
ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
Config done, IP is 192.168.1.112
Instantiating mqttBroker
enter mqtt_socket_client.
NodeMCU_2871df
length username: 4
length password: 14
MQTT: Init info: NodeMcu_2650591, tony, 2016Kilnageer!
leave mqtt_socket_client.
Setting up callbacks
enter mqtt_socket_on.
leave mqtt_socket_on.
enter mqtt_socket_on.
leave mqtt_socket_on.
Making connection to MQTT broker
enter mqtt_socket_connect.
TCP ip is set: 192.168.1.105
TCP port is set: 1883.
enter socket_connect.
leave socket_connect
leave mqtt_socket_connect.
PANIC: unprotected error in call to Lua API (init.lua:136: attempt to call field 'alarm' (a nil value))


So now have debug but still not seeing publish onMQTT.fx !
enter mqtt_socket_timer.
timer, queue size: 0
keep_alive_tick: 5
leave mqtt_socket_timer.
Function platform_gpio_mode() is called. pin_mux:1610614840, func:0
Publishing to temperatures/NodeMcu_2650591: 18
enter mqtt_socket_publish.
Sent: 36
send_if_poss, queue size: 1
publish, queue size: 1
leave mqtt_socket_publish.
Publishing to humidities/NodeMcu_2650591: 44
enter mqtt_socket_publish.
send_if_poss, queue size: 2
publish, queue size: 2
leave mqtt_socket_publish.
enter mqtt_socket_timer.
timer, queue size: 2
event_timeout: 5.
enter deep sleep

Saved code as "init.v1.10_still_doesnt_publish.lua" and tried the dev build next...

nodemcu-dev-9-modules-2019-04-13-22-30-55-integer.bin

No difference! So is it a MQTT version issue? Try a different MQTT broker?

nodemcu-master-7-modules-2019-03-30-20-05-51-integer.bin
master: modules: file,gpio,net,node,tmr,uart,wifi

nodemcu-master-10-modules-2019-03-31-09-32-28-integer.bin
master: modules: dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi

init.lua.working_tolapark


Trying without debug and I'll add lots of delays and print() s ! And let's make sure we are really connected before we try to publish! or deep sleep

nodemcu-master-9-modules-2019-04-14-00-03-50-integer.bin


Wednesday, 10 April 2019

Fixing MQTT temp probes..

(7:41) 33.6 / 11.8 (after extn zone and burner on for 10 mins)

Today I must find out why the NodeMcu thinks it has successfully published to the MQTT broker but the broker has seen nothing.

So I can change QoS from 0 to 2 and/or try a different broker.

(8:02) rad 50.3 / 14.6 and very sunny out streaming in through window

(8.07) rad 50.8 / 15.2

(8.18) rad 50.2 / 16.1 (warm enough - so off burner and zone using MQTT Dash app :) )

(8:31) rad 44.1 / 17.1

Also I'm using old firmware because I couldn't get the timer working with the latest stuff!

Good next the DHT11 probe is still working since yesterday afternoon? even with red LED on all the time :)

(8:52) rad 34.8/ 17.4 -still comfortable - so CH staying off

(10:03) rad 20.3 / 16.7 still sun streaming in and comfortable (no CH on)



Tuesday, 9 April 2019

Updated the Kilnageer CH hot press

1) Put back the original three miniature sonoffs as they now have Tasmota firmware
This means physically:

sonoff_7932 replaced by sonoff_3481 (192.168.1.49) - controls cylinder MV
sonoff_2613 replaced by sonoff_6223 (192.168.1.50) - controls XX zone MV (see below)
sonoff_3330 replaced by sonoff_3304 (192.168.1.51) - controls YY zone MV (see below)

But as the live output wires of sonoff_6223 and sonoff_3304 are swapped over from the originals, functionally we have:

sonoff_2613 did power yellow/green live wire to zone XX (now handled by sonoff_3304)
sonoff_3330 did power blue live wire to Extension zone (now handled by sonoff_6223)


2) Also wired the shower pump to sonoff_2384 (192.168.1.6)


Here's a complete list of active sonoffs on the LAN:
sonoff_3330-3330 192.168.1.8 2C:3A:E8:4F:4D:02 Living zone MV
sonoff_2384-2384 192.168.1.6 5C:CF:7F:67:29:50 Shower pump
sonoff_5604-5604 192.168.1.2 EC:FA:BC:86:D5:E4 Oil burner
sonoff-3304 192.168.1.49 2C:3A:E8:0F:4C:E8 Bedroom zone MV
sonoff-6223 192.168.1.50 2C:3A:E8:07:B8:4F Extension zone MV
sonoff-3481 192.168.1.51 2C:3A:E8:0F:4D:99    Cylinder MV

And of Raspberry Pi's on the LAN
mayo_rpi_zero_logger_3 192.168.1.4 B8:27:EB:C8:19:85   function?
tola_living_room 192.168.1.48 B8:27:EB:EB:F1:B6   function?

And of NodeMcu temperature/humidity sensors:
NODE-E9F4A 192.168.1.42 68:C6:3A:E9:F4:0A Function?
NODE-2871DF 192.168.1.43 EC:FA:BC:28:71:DF   Function?
NODE-927154 192.168.1.44 84:0D:8E:92:71:54 Function?
NODE-2743B4 192.168.1.45 EC:FA:BC:27:43:B4 Function?

NOTE: Vodafone router also shows old devices which have since been removed:
sonoff_2613 ?
sonoff_2932-2934 192.168.1.10 5C:CF:7F:67:2B:76 function?
sonoff_3536-3536 192.168.1.41 5C:CF:7F:40:CD:D0 Tony's bedroom lamp
sonoff_7932 ?
sonoff_7613-7613 192.168.1.9 2C:3A:E8:4E:7D:BD
sonoff_5cf5 192.168.1.7 5C:CF:7F:42:8F:F5 Living zone MV (not tasmota)

Node-Red
Uses switch nodes to publish "ON" or "OFF" to sonoff topics like "cmnd/sonoff_5604/POWER" (with QoS not defined) which will directly control the Wifi switch (if it is powered on). But displays the switch's status by subscribing to a different topic "+/sonoff_5604/+" QoS 2

sonoff_5604    burner on/off
sonoff_6223    extension zone MV
sonoff_7613    living zone MV
sonoff_3481    cylinder MV
sonoff_3304    Bedroom zone MV

Continued on Kilnageer CH temp probes...

This blog will have its detail removed in a few days... I'm just grabbing everything for now :)

(7:15) rad 13,0 / 12.0

Put zone + burner on for an hour

(7:39) rad 35.2 / 12.8

Looking at MQTT.fx no temp/humidity posting from 2x nodemcu probes left at top of hall overnight. But they weren't posting when I left them there at midnight.

(7:45) Examining them one was dead (was it continually trying to get online and so never sleeping?)  and the other was still running but doing what?

So today 1 want to:-
1) Get 3x nodemcu probes running and deployed(Liam living room & bedroom and my kitchen in extension) with spare batteries
2) Program all Sonoffs with correct firmware
3) Get shower pump on a snoff
4) Ensure temp posting script runs on startup
5) Make the MQTT databse secure (username/password)
6) Change over to MQTT based operations

This will mean that the http://192.168.1.4:1880/ui app can still be used internal to the house to control the CH.

(7:54) rad 42.5 / 14.2

Examining the probe that still had power using ESPlorer in the kitchen it it still trying to get on to Wifi (makes sense as it cannot see vodafone-2124 from there)

(8:13) rad 44.2 / 15.8
changed repeater SSID from voadafone_repeater to vodafone-2124 so I can use the same nodemcu code all over the house.

Cannot connect to wifi! Is it because of adc module?

NodeMCU custom build by frightanic.com
branch: master
commit: 4905381c004bdeaf744a60bb940c1906c2e052d4
SSL: false
modules: adc,dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi
 build created on 2019-04-08 20:52
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
NodeMcu temp/humidity/battery monitor v1.1 09-Apr-19
Configuring WIFI..
nil
>
PORT CLOSED

So let's drop that! If probe doesn't phone home in a hour we can report it dead and so needs battery changing

nodemcu-master-11-modules-2019-04-05-20-53-50-integer.bin
modules: adc,dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi
non-debug non-adc build? nope still has adc

nodemcu-master-7-modules-2019-03-30-20-05-51-integer.bin
modules: file,gpio,net,node,tmr,uart,wifi

nodemcu-master-10-modules-2019-03-31-09-32-28-integer.bin
modules: dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi
Hurrah!
Still getting same wifi issue!
NodeMcu temp/humidity/battery monitor v1.1 09-Apr-19
Configuring WIFI..
nil

(8:34) Going back to code without deep sleep.

(8:34) rad 44.6 / 16.9 (my rads in Tola go up to 50+??)
I re-wedges rad temp probe. Burner has hit on/off cycle some time ago.

So after 90 mins the kitchen still isn't at 18 C. Fan heater would have done this in 10 mins!

Using old build original "tmr.alarm(1, 5000, 1, function().." "init.lua.working_kilnageer_2124_SSID" code works which didn't in later one! Happy days. Now lets just add 5 min deep sleep to it an be done!

I think we have a winner! ....

> w([==[print( "NodeMcu Kilnageer probe v1.3 09-Apr-19" )]==]);
> w([==[print( "node ID = "..node.chipid() )]==]);
> w([==[print( "time now = "..tmr.now() )]==]);
> w([==[print( "uptime = "..tmr.time() )]==]);
> w([==[print( "boot reason = "..node.bootreason())]==]);
> w([==[configWifi()]==]);
> file.close();
> dofile("init.lua");
NodeMcu Kilnageer probe v1.3 09-Apr-19
node ID = 2650591
time now = 3917433
uptime = 3
boot reason = 2
Configuring WIFI..
192.168.1.43 255.255.255.0 192.168.1.1
> ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
IP unavaiable, Waiting...
ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
Config done, IP is 192.168.1.43
Instantiating mqttBroker
Setting up callbacks
Making connection to MQTT broker
connected
Publishing to /temperatures/NodeMcu_2650591: 17
Publishing to /humidities/NodeMcu_2650591: 57


NodeMCU custom build by frightanic.com
branch: master
commit: 11592951b90707cdcb6d751876170bf4da82850d
SSL: false
modules: dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi
 build created on 2019-03-31 09:31
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
NodeMcu Kilnageer probe v1.3 09-Apr-19
node ID = 2650591
time now = 258436
uptime = 0
boot reason = 2
Configuring WIFI..
nil
> ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
IP unavaiable, Waiting...
ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
Config done, IP is 192.168.1.43
Instantiating mqttBroker
Setting up callbacks
Making connection to MQTT broker
connected
Publishing to /temperatures/NodeMcu_2650591: 17
Publishing to /humidities/NodeMcu_2650591: 58

So will deploy in kitchen today with fully charged battery pack and move on to sonoffs :)

(9:03) rad 45.4 / 18.1
Turning off burner and then zone

But MQTT.fx not seeing this still! Huh? As it's not among the 28 topics its seen published in the last 30 mins or so.


(9:40) Programmed 2nd nodemcu print-out all OK on laptop but MQTT.fx sees nothing! Will park up for now and try publishing to a different broker later today

(9:40) rad 31.3 / 17.9


Now to program the sonoffs!..

I have 2 large and 3 small with me (others in hot press)

(10:08) I turned CH zone and burner back on
(10:08) 25.5 / 17.2

(10:21) 33.9 / 17.1

How to program a sonoff with tasmota? I'll check my e-mails,,

12 February 2019 at 09:26:

https://ruclip.com/video/kKtLKjI4wA0/sonoff-s31-smart-plug-flashing-tasmota-and-openhab-mqtt-configuration.html

C:\Users\kilnageer\Downloads\ESPEasy_mega-20190212
In win 10 from file explore run FlashESP8266.exe from this directory
and choose COM6 and ./sonoff.bin blue LED on sonoff will
flashafterwards! :) and webserver up on Wifi as SSID "sonoff-2934"

Get video

Remember to hold button sonoff button when inserting USB dongle!

(10:45) 51.2 / 18.7
turn off CH


Sonoff WiFi Smart Switch With I2C Port – JackenHack


(10:56) 45.3 / 19.2

(12:08) My lamp works brilliantly even from MQTT Dash using:
cmnd/sonoff_5604/POWER
and message of "ON" and "OFF" (but I think caps unimportant and 1/0 also works)


(12:11) 24.2 / 17.8

(12:42) 21.2 / 17.0


Monday, 8 April 2019

Back in Mayo working on the Kilnageer central heating..

Well the CH controller was offline. Not accessible on 192.168.1.4
Found not plugged in properly as it was disturbed when the shower pump plug was pulled in/out.
Once the shower pump is under Sonoff control this won't be necessary :)

http://192.168.1.4:1880/ui/ is now back online and I've started the script to report the temperatures :)
pi@mayo_rpi_zero_logger_3:~ $ ./ds18b20_temp_logger.py > /dev/null &
(I must make this run automatically on power/start up)


And here's the temp in the extension starting to build up..

And it looks like we've been hacked!

So I've turned off remote access as not password protected. Also will be replacing this Node-Red web access by an Android app to control the CH in a few days :)

Now to get NodeMcu working as a thermostat for the extension kitchen.

And to get MQTT server on 192.168.1.4. Already running but no username/password. (Must secure this for MQTT Dash android app use)

So used MQTT.fx to monitor temp reading from NodeMcu. Kitchen rad now (17:53) at 42.4 and room at 14.4 (was 11.5 and 11.8 at 14:58) and heating been on since..? Cannot tell when topic"cmnd/sonoff_5604/POWER" was posted to :(

But examining:
pi@mayo_rpi_zero_logger_3:~ $ vim /home/pi/4ca4.txt
it was around 1554739841089 which is about 17:10 according to:
https://www.unixtimestamp.com/index.php

Just cannot get NodeMcu to obtain an IP address from KILNAGEER_002 SSID :(

Kitchen rad now (18:19) at 49.5 and room at 16.8. This rad has a TRV on it which should kick in after a while keeping the kitchen at a steady temp but at that time I'd like to turn of the zone and if no other zone is active the burner,

Tried the same code in another NodeMcu... but same issue. Tried the 1st one next to the Wifi repeated and monitored Vodafone router to see if it popped up in LAN table or in MQTT.fx traffic. Nope :(

Also Vodafone router is rejecting static IP mappings! Blast!

18:28 turned of burner and zone and went for a walk (rad at 50.2 / 17.4)

19:39 (rad at 24.9 /15.9) Will trying connecting to SSID vodafone-2124 from the hallway :)

and can see the following topics being published:
/humidities/NodeMcu_2650591          59
/temperatures/NodeMcu_2650591       13

So now making a ADC module build

This was built against the master branch and includes the following modules: adc, dht, ds18b20, file, gpio, mqtt, net, node, tmr, uart, wifi.
nodemcu-master-11-modules-2019-04-08-19-27-34-integer.bin

It also have developer's debug turned on. I can now see the issue. It cannot see the SSID "KILNAGEER_002"

stack traceback:
init.lua:32: in function 'configWifi'
init.lua:134: in main chunk
[C]: ?
> Heap size:36304.

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:8)
scandone
no KILNAGEER_002 found, reconnect after 1s

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:1)
reconnect
scandone
no KILNAGEER_002 found, reconnect after 1s

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:1)
reconnect

I can sometime see it a bit. So I moved repeater on CAT-5 cable to kitchen.

NodeMCU custom build by frightanic.com
branch: master
commit: 4905381c004bdeaf744a60bb940c1906c2e052d4
SSL: false
modules: adc,dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi
 build created on 2019-04-08 19:26
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
NodeMcu Kilnageer extension kitchen temperature monitor v0.8 02-Apr-19
Use alternate output format: 0
scandone
> Heap size:34848.

 EVENT_DBG(wifi_event_monitor_handle_event_cb): was called (Event:8)
scandone
KILNAGEER_OO2 : þÿ?Nu#@xÜþ?
KILNAGEER_OO2 4 -47 e8:ab:fa:b0:c4:44 6
reconnect
scandone
no KILNAGEER_002 found, reconnect after 1s

(21:46) Reprogrammed the repeater. Now SSID is vodafone_repeater same password as vodafone-2124.

NodeMcu now connects but doesn't MQTT publish! Why? Not fully connected? Trying non-debug build

CH on at 21:55 rad 16.4 / 14.4 but I turned all other TRVs to 0. So hopefully hot water goes straight to kitchen rad.

This was built against the master branch and includes the following modules: adc, dht, ds18b20, file, gpio, mqtt, net, node, tmr, uart, wifi.

nodemcu-master-11-modules-2019-04-08-20-53-26-integer.bin

CH on at 22:54 rad 47.2 / 18.9 so turned off zone and burner.

(23:30) some success using noder.dsleep( 10000000 ) -- 20 sec with wire between D0 and RST.
Left two probes on vodafone-2124 overnight but cannot see any readings on MQTT.fx :(

Giving up for the night.


Friday, 5 April 2019

Need to monitor NodeMcu power and use deep sleep mode

Made another firmware build at nodemcu-build.com.

You successfully commissioned a NodeMCU custom build from the master branch. You selected the following 11 modules: adc dht ds18b20 file gpio mqtt net node tmr uart wifi.

I included "adc" this time so I can try the following statement in my function pubEvent()
              print( adc.readvdd33() )

Found building with adc causes the code to crash at
    tmr.alarm(1, 1000, 1, function()

So switched to non-master build:
You successfully commissioned a NodeMCU custom build from the 1.5.4.1-final branch. You selected the following 10 modules: adc dht file gpio mqtt net node tmr uart wifi.

That fixes it. Maybe. But cannot connect over Wifi now...

Also I can flash firmware and do Lua programming using ESPlorer using just the microUSB connector. Great! No need for 3-wire USB to serial connection :)

Nope "adc" definitely seems to upset "wifi". So giving up.

But this code worked:
if adc.force_init_mode(adc.INIT_VDD33) then node.restart() return -- don't bother continuing, the restart is scheduled end print("System voltage (mV):", adc.readvdd33(0))


By producing..
NodeMCU custom build by frightanic.com
branch: 1.5.4.1-final
commit: b9436bdfa452c098d5cb42a352ca124c80b91b25
SSL: false
modules: adc,dht,file,gpio,mqtt,net,node,tmr,uart,wifi
 build created on 2019-04-05 21:10
 powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)
NodeMcu temperature monitor v0.4 05-Apr-19
System voltage (mV): 3014
Configuring WIFI..
nil
> IP unavaiable, Waiting...
IP unavaiable, Waiting...
IP unavaiable, Waiting...
IP unavaiable, Waiting...

Was only nice to have though later voltage monitoring will need it?

Will try one more "dev" firmware build
You successfully commissioned a NodeMCU custom build from the dev branch. You selected the following 11 modules: adc dht file gpio mqtt net node tmr uart wifi.
Fails to build :(

So on to deep sleep mode next :) I will try this first




Thursday, 4 April 2019

Finally got 2x NodeMcu temp sensor working

Fixed my NodeMcu Wifi not connecting error:

> w([==[tmr.alarm(1, 2500, 1, configWifi)]==]);
> file.close();
> dofile("init.lua");
NodeMcu temperature monitor v0.3 02-Apr-19
> Configuring WIFI..
nil
Configuring WIFI..
nil
Configuring WIFI..
nil
Configuring WIFI..

By using the following code:
https://www.limpkin.fr/index.php?post/2016/04/17/A-Small-Collection-of-NodeMCU-Lua-Scripts-for-Data-Collection

function GetSensorData()
    -- print( "Trying to get temperature..." )
    pin = 4
    error = 0 
    status, temp, humi, temp_dec, humi_dec = dht.read(pin)
    if status == dht.OK then
        --print("DHT Temperature:"..temp..";".."Humidity:"..humi)
        error = 0
    elseif status == dht.ERROR_CHECKSUM then
        -- print( "DHT Checksum error." )
        error = 1
    elseif status == dht.ERROR_TIMEOUT then
        -- print( "DHT timed out." )
        error = 2
    end
    return error, temp, humi 
end

function configWifi()
      print("Configuring WIFI..")
      print(wifi.sta.getip()) 
      wifi.setmode(wifi.STATION)
      station_cfg={} 
      station_cfg.ssid=SSID
      -- station_cfg.ssid="Wifi-Repeater(2.4G)"
      station_cfg.pwd=PASSWORD
      station_cfg.save=true
      wifi.sta.config(station_cfg)
      wifi.sta.connect()
      tmr.alarm(1, 1000, 1, function()
          if wifi.sta.getip() == nil then
              print("IP unavaiable, Waiting...")
          else
              tmr.stop(1)
              print("ESP8266 mode is: " .. wifi.getmode())
              print("The module MAC address is: " .. wifi.ap.getmac())
              print("Config done, IP is "..wifi.sta.getip())
              makeConn() -- can now startt publishing results
          end
      end)
end





sensorID = "NodeMcu_" .. node.chipid()   -- a sensor identifier for this device
tgtHost = "192.168.1.136"    -- target host (broker)
tgtPort = 1883          -- target port (broker listening on)
mqttTimeOut = 120        -- connection timeout
mqttUserID = USERNAME        -- account to use to log into the broker
mqttPass = PASSWORD     -- broker account password
dataInt = 5           -- data transmission interval in seconds
tempQueue  = "/temperatures/" .. sensorID     -- the MQTT topic queue to use
humidQueue = "/humidities/" .. sensorID   -- the MQTT topic queue to use
connected = 0 -- not connected to MQTT broker
  
-- Function pubEvent() publishes the sensor value to the defined queue.

function pubEvent() 
    err, t, humid = GetSensorData() -- read temp
    if (err == 0) then

      print("Publishing to " .. tempQueue .. ": " .. t)   -- print a status message
      mqttBroker:publish(tempQueue, t, 0, 0)  -- publish

      print("Publishing to " .. humidQueue .. ": " .. humid)   -- print a status message
      mqttBroker:publish(humidQueue, humid, 0, 0)  -- publish
    end
end




-- Reconnect to MQTT when we receive an "offline" message.

function reconn()
    connected = 0
    print("Disconnected, reconnecting....")
    conn()
end



-- Establish a connection to the MQTT broker with the configured parameters.

function conn()
    connected = 0
    print("Making connection to MQTT broker")
    mqttBroker:connect(tgtHost, tgtPort, 0, function(client) print ("connected") end, function(client, reason) print("failed reason: "..reason) end)
end



-- Call this first! --
-- makeConn() instantiates the MQTT control object, sets up callbacks,
-- connects to the broker, and then uses the timer to send sensor data.
-- This is the "main" function in this library. This should be called 
-- from init.lua (which runs on the ESP8266 at boot), but only after
-- it's been vigorously debugged. 
--
-- Note: once you call this from init.lua the only way to change the
-- program on your ESP8266 will be to reflash the NodeCMU firmware! 

function makeConn() 
    -- Instantiate a global MQTT client object
    print("Instantiating mqttBroker")
    mqttBroker = mqtt.Client(sensorID, mqttTimeOut, mqttUserID, mqttPass, 1)

    -- Set up the event callbacks
    print("Setting up callbacks")
    mqttBroker:on("connect", 
      function(client) 
        print ("connected") 
        connected = 1
      end)
    mqttBroker:on("offline", reconn)

    -- Connect to the Broker
    conn()

    -- Use the watchdog to call our sensor publication routine
    -- every dataInt seconds to send the sensor data to the 
    -- appropriate topic in MQTT.
    tmr.alarm(0, (dataInt * 1000), 1, pubEvent)
end

-- MAIN
print( "NodeMcu temperature monitor v0.3 02-Apr-19" )
configWifi()

Now still get the odd PANIC but the unit reboots and recovers. Here's its output:


NodeMCU custom build by frightanic.com
branch: master
commit: 11592951b90707cdcb6d751876170bf4da82850d
SSL: false
modules: dht,ds18b20,file,gpio,mqtt,net,node,tmr,uart,wifi
 build created on 2019-03-31 09:31
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
NodeMcu temperature monitor v0.3 02-Apr-19
Configuring WIFI..
nil
> IP unavaiable, Waiting...
IP unavaiable, Waiting...
IP unavaiable, Waiting...
ESP8266 mode is: 1
The module MAC address is: ee:fa:bc:28:71:df
Config done, IP is 192.168.1.146
Instantiating mqttBroker
Setting up callbacks
Making connection to MQTT broker
connected
Publishing to /temperatures/NodeMcu_2650591: 20
Publishing to /humidities/NodeMcu_2650591: 35
Publishing to /temperatures/NodeMcu_2650591: 20
Publishing to /humidities/NodeMcu_2650591: 36
Publishing to /temperatures/NodeMcu_2650591: 20

Happy days! So now flashing another 3 NodeMcus :)

However, the MQTT temp and humidity values being published aren't being retained.


Also want to wire on a DHT22 rather than a DHT11

DHT22 Tutorial for Raspberry Pi | Rototron

and grab a couple of decimal points of precision on the readings. Also need to fix the MQTT retention issue and add the voltage to the ADC (so we can know when the batter is going flat! :) )

So here's Mark 2 up and running with Mark 1 :)


Finally, thought I'd monitor theses two sensors using Node-Red and found the PCB mounted one is much hotter!

I blew on the white DHT22 to get 100% humidity and to raise the temp.
Then held the blue DHT11 one for a while.