Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Setting up an MQTT system for Weather Sensing and Astro Control


Gina

Recommended Posts

Tried connecting the ESP32 to my Mint box and running the Serial Monitor.  This showed that the BME280 wasn't working.  Double checked the wiring and also that the BME280 had power.  Guess it could be a duff module.  When it stops raining I can take it out to the ESP32 in the obsy and see it it works with that.

Doesn't explain why the LED doesn't come on though.  Checked D4 and logic "0".

Edited by Gina
Link to comment
Share on other sites

The BME280 module works fine with the obsy ESP32. 

Next I'm going to try a known working sketch instead of the MQTT one.  That will test the hardware.

Edited by Gina
Link to comment
Share on other sites

5 hours ago, Gina said:

Does anyone here use Node-RED and how useful do you find it?

Yep I do and its a fast RAD (Rapid App Dev) once you get used to how it works (like all things new) - like all RAD's you work with it and its ways of doijng things. Once mastered you can write Javascipt stuff as well. Hint get the ESP working first and showing data in correct packet format - JSON or RAW. Node-red "connected" just means that its talking as a client to the broker you have set up. Use the "Message" node you have to display the format ,type and content of data. I always find a quick send from MQTT-explorer can quickly test out what is or isn't working -  normally mistakes I make is to have one end RAW packets and the other expecting JSON format. First you need to make sure that your "TOPICS" are the same else clients will not speak to each other but MQTT-explorer will help there as you should see the data including TOPIC headers. There is a "catch-all" topic (top of the message tree) which will show ALL TOPICS going thru the broker and "Wildcards" - read this might help http://www.steves-internet-guide.com/understanding-mqtt-topics/

  • Thanks 1
Link to comment
Share on other sites

The BME280 is not working with the older sketch so I must have wired something wrongly but I've checked everything many times and even confirmed the connections with a DMM continuity test.

Edited by Gina
Link to comment
Share on other sites

Think I've found it!!  The BME280s I have are different from the one shown in the tutorial - SDA and SDL are reversed!!

EDIT :-  Yep, that was it.  BME280 now working!

Edited by Gina
Link to comment
Share on other sites

Uploaded the MQTT sketch and...  it works - one way.  The temperature and humidity are being displayed in the Node-RED Dashboard.  But the LED control is still not working.  I know the LED works because I added my own version of Blink to the other sketch and the LED blinked on and off as expected.

SO---  A modicum of success!!  🙂

To be sure I was seeing what I was supposed to be seeing I touched the sensor and the temperature jumped up as expected.  See the spike in the graph.

690629086_Screenshotfrom2020-08-1516-47-10.png.4a6ba35d745a59a6c21903d5d2ffb11c.png

Edited by Gina
Link to comment
Share on other sites

The current situation then is the latest ESP32/BME280 sensor unit is sending data successfully through the broker to the Node-RED Dashboard BUT the link the other way doesn't work - a switch in the Dashboard is supposed to send an "on" or "off" message to the ESP32 and light (or not) an LED - and furthermore the Output switch has got locked in the on position.  MQTT Explorer shows the ESP32 output = on but whether that is what the ESP32 has received or just what has been sent, I don't know.

Has anyone any idea how I can find out what's wrong or any suggestions?  TIA

  • Like 1
Link to comment
Share on other sites

Here's a copy of the Serial Monitor display.  Nothing showing for the output topic but nothing has been sent from the Dashboard recently as the switch is locked on.

Quote

ets Jun  8 2016 00:22:57
 
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
 
Connecting to Ubiquity
.
WiFi connected
IP address:  
192.168.1.94
Attempting MQTT connection...connected
Temperature: 25.21
Humidity: 56.18
Temperature: 25.01
Humidity: 57.09
Temperature: 24.94
Humidity: 56.99
Temperature: 24.83
Humidity: 56.68
Temperature: 24.82
Humidity: 56.74

 

Link to comment
Share on other sites

If you have seen the NodeRed -> ESP MQTT 'ON / OFF' message in the MQTT Explorer then this points to the ESP not acting on the message. Have you subscribed to the topic and set up the call-handler on the ESP ?

If you haven't seen the NodeRed message  to the ESP, then it is a NodeRed problem in the first instance.  Have you got a debug attached to the action for triggering the output ?

 

Link to comment
Share on other sites

Rebooted the RPi and now the Dashboard output switch is locked in the off state.  I can slide it over with the pointer but the colour doesn't change and it goes back to off.  This seems to be a problem with the Node-RED Dashboard.  OTOH MQTT Explorer has output = on.

1062289136_Screenshotfrom2020-08-1519-30-04.png.05970d5b0af9142a478a1c665fa4bd8f.png

Edited by Gina
Link to comment
Share on other sites

I've been following THIS tutorial.  I haven't seen the NodeRed -> ESP MQTT 'ON / OFF' message in the MQTT Explorer.  I feel the problem has to be in the Node-RED Dashboard as the switch control output won't turn on.

Link to comment
Share on other sites

be careful of retained messages and QOS there are 3 types of broker working QOS -  retain message  https://community.openhab.org/t/clearing-mqtt-retained-messages/58221

QOS - https://assetwolf.com/learn/mqtt-qos-understanding-quality-of-service

If the Arduino end isn't printing on or off recvd then Node-red isn't

1. Sending the message at all - bit like (3) Broker would never get a message and MQTT EXP wouldn't see it either

2. The Topic is wrong - the MQTT explorer log should show the message from Node-red but the ESP would never get it

3. The output MQTT details(host address) on the switch leg is wrong - here the message would not even be seen by the broker and therefore nothing would get the to the ESP.

For 1 & 3 you need to see if the Node-Red status when you flick the switch in case it throws up an error. Plus you can send a message from the MQTT EXP simulating the switch message to see what the ESP does with it.

 

 

 

 

Link to comment
Share on other sites

I'm trying to use the Node-RED web interface to set other controls and see what happens.  Previously I've just been following the tutorial bit by bit - sort of "blind".  The whole point of it is to be able to set up topics etc. and link clients so I shall need to see how it works if I'm to use it in the future to expand the network,  once learned it should be easier and quicker than writing code I would think.

Link to comment
Share on other sites

Could this be the problem - the output switch has no topic?  Or does the connection (link) do that?  I think I need to read up on Node-RED.

433999347_Screenshotfrom2020-08-1520-21-03.png.83e36f3f0228d9a54406a578ca8b0a21.png

Edited by Gina
Link to comment
Share on other sites

I've noticed that Node-RED doesn't create MQTT topics, these are created in the sketch running on the client hardware.  I gather Node-RED just sets up links.

Link to comment
Share on other sites

36 minutes ago, Gina said:

Could this be the problem - the output switch has no topic?  Or does the connection (link) do that?  I think I need to read up on Node-RED.

433999347_Screenshotfrom2020-08-1520-21-03.png.83e36f3f0228d9a54406a578ca8b0a21.png

Not if you put one in the MQTT output else it uses the topic in switch to produce msg.topic - cant test MQTT right now but my test switch (with or without Topic) works

  • Thanks 1
Link to comment
Share on other sites

1 minute ago, Gina said:

I gather Node-RED just sets up links.

it does send messages for a Topic - see the properties of the MQTT Output node there is a topic - node.red produces a message payload in what ever format you want

  • Like 1
Link to comment
Share on other sites

On the subject of JSON payloads, here is an example one that I send via MQTT, if that is any help.

{"batteryPercentage": "100%", "batteryVoltage": 3.486, "cloudBase": 116.74, "cloudBaseFT": 383.02, "countAirObs": "1286 / 1440", "deviceType": "air", "dewPoint": 17.97, "firmwareRevision": 22, "frostRisk": "None", "heatIndex": "n/a", "lightningStrikeCount": 0, "maxHumidity": 99, "maxPressure": 1015.5, "maxTemperature": 18.88, "minHumidity": 93, "minPressure": 1013.3, "minTemperature": 15.82, "pressureTrend": "Falling Slowly", "relativeHumidity": 97, "reportInterval": 1, "seaLevelPressure": 1013.4, "serialNumber": "AR-00016806", "stationPressure": 1006.3, "temperature": 18.46, "thermalPerception": "Bearable", "timestampSeconds": 1597523812, "weatherTendency": "Little Change Expected"}

  • Thanks 1
Link to comment
Share on other sites

Found the problem.  "Pass through msg if payload matches new state: " was set - unset it and the switch in Dashboard now works.  This lets the switch icon show state of output.  It also lets the message through and the LED lights up!

72005254_Screenshotfrom2020-08-1521-45-12.png.3539d46a566d0ed4ea674b9297db68bb.png

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.