NodeMCU + Tasmota code + SHT30

That was cool. Let's try something a bit "easier" - a NodeMCU module, which is easy to connect and upload to, in conjunction with a new sensor, the SHT30 that does humidity and temperature over an I2C interface. This is prompted by this article, which doesn't really say how to do any of this...

Obligatory not very illustrative pic - bits are labelled pretty much!
Oh yeah, had to solder the header pins onto the SHT30 - piece of cake now :-p.

Compiled the latest Tasmota code (using the ESP 2.4.0 API + libs, which significantly improves the WiFi performance) in the Arduino IDE, it's already uploaded while I've been writing this. Gosh.

And that was probably a bit rash! Re-compiled and uploaded, now I've edited the user_config.h file to include my Wifi details and a few other useful things. I'm hoping the code uses mDNS, because that's really handy. Hmm, that didn't seem to work - using the Serial Monitor indicates it's still using the old values... OK, Saved the file, try again... aha

00:00:00 Project sonoff Sonoff (Topic sonoff, Fallback DVES_2D8173, GroupTopic sonoffs) Version 5.11.1
00:00:00 WIF: Connecting to AP2 norcot in mode 11N as sonoff-0371...
00:00:05 WIF: Connected
00:00:05 DNS: Initialized
00:00:05 HTP: Web server active on sonoff-0371.local with IP address 192.168.1.28
18:45:25 MQT: Attempting connection...
18:45:30 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
18:45:41 MQT: Attempting connection...
18:45:46 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec

I have tried pressing the Flash button on the NodeMCU board - the code does see it, and ostensibly 4 quick pushes makes it go into AP/Webserver mode. I connected ok, but then it seems to crash. Hence the continuing compile/retry cycle.

Looks like the AP code works, but it doesn't do mDNS. Bum... Quick recompile... Actually, looking at the code, I just have to use "server", not "server.local", it assumes local. Now it works. Lovely. Should also be advertising itself.

Hurray!! Appears to be working...
So - what next? Let's connect up the SHT30...
SHT30 + NodeMCU connected
Some guess work here initially, followed by a quick check online for the right pins! Gnd/3.3V no problem. The SHT30 has SCL/SDA marked as D1/D2, but not obvious which GPIO4/14 are on NodeMCU. These are of course D5 and D2! Using the Tasmota software, one has to use a few commands, which I did on the Web Console (amazing!):
  • module 1 - Sets the module to be a Sonoff Basic. I have no idea what the difference is if it's not actually a Sonoff!! 
  • gpios - Lists the current GPIO pin associations
  • gpio14 5 - Sets pin 14 to 5; I just followed the example in the Sensors doc page for Tasmota
  • gpio4 6 - Sets pin 4 to 6; likewise
The sensor was actually detected on the final restart and the software immediately started sending MQTT messages with its readings. Amazing.  

Sonoff Web Main Menu with Sensor readings displayed
Here's a listing of the console printout after the final boot and recognition of the sensor, with "gpios" and "modules" commands thrown in for good measure:

00:00:00 Project sonoff Sonoff (Topic sonoff, Fallback DVES_2D8173, GroupTopic sonoffs) Version 5.11.1
00:00:00 WIF: Connecting to AP2 xxxxxx in mode 11N as sonoff-0371...
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff-0371.local with IP address 192.168.1.28
14:03:54 MQT: Attempting connection...
14:03:54 MQT: Connected
14:03:54 MQT: tele/sonoff/LWT = Online (retained)
14:03:54 MQT: cmnd/sonoff/POWER = 
14:03:54 MQT: tele/sonoff/INFO1 = {"Module":"Sonoff Basic","Version":"5.11.1","FallbackTopic":"DVES_2D8173","GroupTopic":"sonoffs"}
14:03:54 MQT: tele/sonoff/INFO2 = {"WebServerMode":"Admin","Hostname":"sonoff-0371","IPAddress":"192.168.1.28"}
14:03:54 MQT: tele/sonoff/INFO3 = {"RestartReason":"Software/System restart"}
14:03:55 MQT: stat/sonoff/RESULT = {"POWER":"OFF"}
14:03:55 MQT: stat/sonoff/POWER = OFF
14:04:02 MQT: tele/sonoff/STATE = {"Time":"2018-01-15T14:04:02","Uptime":0,"Vcc":3.039,"POWER":"OFF","Wifi":{"AP":2,"SSId":"xxxxxx","RSSI":68,"APMac":"84:16:F9:F4:DB:B4"}}
14:04:02 MQT: tele/sonoff/SENSOR = {"Time":"2018-01-15T14:04:02","SHT3X":{"Temperature":19.5,"Humidity":53.0},"TempUnit":"C"}
14:04:16 CMD: gpios
14:04:16 MQT: stat/sonoff/RESULT = {"GPIOs1":["0 (None)","1 (DHT11)","2 (AM2301)","3 (SI7021)","4 (DS18x20)","5 (I2C SCL)","6 (I2C SDA)","7 (WS2812)","8 (IRsend)","9 (Switch1)","10 (Switch2)","11 (Switch3)","12 (Switch4)","13 (Button1)","14 (Button2)","15 (Button3)","16 (Button4)","17 (Relay1)","18 (Relay2)","19 (Relay3)","20 (Relay4)"]}
14:04:16 MQT: stat/sonoff/RESULT = {"GPIOs2":["21 (Relay5)","22 (Relay6)","23 (Relay7)","24 (Relay8)","25 (Relay1i)","26 (Relay2i)","27 (Relay3i)","28 (Relay4i)","29 (Relay5i)","30 (Relay6i)","31 (Relay7i)","32 (Relay8i)","33 (PWM1)","34 (PWM2)","35 (PWM3)","36 (PWM4)","37 (PWM5)","38 (Counter1)","39 (Counter2)","40 (Counter3)","41 (Counter4)"]}
14:04:16 MQT: stat/sonoff/RESULT = {"GPIOs3":["42 (PWM1i)","43 (PWM2i)","44 (PWM3i)","45 (PWM4i)","46 (PWM5i)","47 (IRrecv)","48 (Led1)","49 (Led2)","50 (Led3)","51 (Led4)","52 (Led1i)","53 (Led2i)","54 (Led3i)","55 (Led4i)","56 (MHZ Tx)","57 (MHZ Rx)","58 (PZEM Tx)","59 (PZEM Rx)","60 (SAir Tx)","61 (SAir Rx)","62 (SPI CS)","63 (SPI DC)"]}
14:04:16 MQT: stat/sonoff/RESULT = {"GPIOs4":["64 (BkLight)"]}
14:09:02 MQT: tele/sonoff/STATE = {"Time":"2018-01-15T14:09:02","Uptime":0,"Vcc":3.041,"POWER":"OFF","Wifi":{"AP":2,"SSId":"xxxxx","RSSI":64,"APMac":"84:16:F9:F4:DB:B4"}}
14:09:02 MQT: tele/sonoff/SENSOR = {"Time":"2018-01-15T14:09:02","SHT3X":{"Temperature":20.2,"Humidity":52.4},"TempUnit":"C"}
14:11:52 CMD: modules
14:11:52 MQT: stat/sonoff/RESULT = {"Modules1":["1 (Sonoff Basic)","2 (Sonoff RF)","3 (Sonoff SV)","4 (Sonoff TH)","5 (Sonoff Dual)","6 (Sonoff Pow)","7 (Sonoff 4CH)","8 (S20 Socket)","9 (Slampher)","10 (Sonoff Touch)","11 (Sonoff LED)","12 (1 Channel)","13 (4 Channel)","14 (Motor C/AC)","15 (ElectroDragon)","16 (EXS Relay)","17 (WiOn)"]}
14:11:52 MQT: stat/sonoff/RESULT = {"Modules2":["18 (WeMos D1 mini)","19 (Sonoff Dev)","20 (H801)","21 (Sonoff SC)","22 (Sonoff BN-SZ)","23 (Sonoff 4CH Pro)","24 (Huafan SS)","25 (Sonoff Bridge)","26 (Sonoff B1)","27 (AiLight)","28 (Sonoff T1 1CH)","29 (Sonoff T1 2CH)","30 (Sonoff T1 3CH)","31 (Supla Espablo)","32 (Witty Cloud)","33 (Yunshan Relay)"]}
14:11:52 MQT: stat/sonoff/RESULT = {"Modules3":["34 (MagicHome)","35 (Luani HVIO)","36 (KMC 70011)","37 (Arilux LC01)","38 (Arilux LC11)","39 (Sonoff Dual R2)","40 (Arilux LC06)"]}

Marked in bold, you can see
  • the Modules setting to Basic
  • Two temp/humidity telematic sends
  • gpios and modules commands and responses
I might try setting up a chart in NodeRED that uses these figures, just for a laugh.











Comments

Popular posts from this blog

Replacing Coffee Machine Pump (Dualit Espressivo)

Multiple SHT30 sensors on a single I2C bus with Sonoff-Tasmota