|
Post by gb0101010101 on Mar 24, 2019 15:53:07 GMT -8
Was disappointed to see that OurWeather does not implement a generic MQTT client so I added one. This snowballed as the readings were not always in the correct units so I added Measurement Systems for UK, USA, and Europe (SI). This is a work in progress and will change. You can get the source from:
If you are not a programmer then just download the Zip file. Otherwise fork it if you can provide code changes.
Look at build instructions here:
MQTT
To setup MQTT edit the Mqtt.h file and set the IP. If your MQTT uses username and login then add those too. Then change 'mqtt_configured' to true. Do not change anything else.
I plan on adding a way to configure this without editing code but did not want to mess with EEPROM to save the inputs.
UNITS
Metric remains the same and you should not see any difference in readings. English is UK (British) units. New USA units.
You can use the existing REST calls: e.g.
and now added:
Units have been updated everywhere they are displayed EXCEPT for the individual REST variables. The FULL REST string has been updated. I will complete this but I have done too much coding this weekend and my butt is sore.
I made minor changes to Blynk and Weather Underground code. Do not use Blynk so not tested. Weather Underground is also not tested by the POST URL looks good.
Let me know if you find any bugs.
|
|
|
Post by gb0101010101 on Mar 24, 2019 16:02:11 GMT -8
Sample MQTT:
/Weather/State/AM2315/Temperature 80.60 /Weather/State/AM2315/Humidity 32.40 /Weather/State/BMP180/Temperature 85.05 /Weather/State/BMP180/Pressure 31.28 /Weather/State/BMP180/Altitude 1331.47 /Weather/State/Wind/Speed/Current 0.00 /Weather/State/Wind/Speed/Minimum 0.00 /Weather/State/Wind/Speed/Maximum 1.96 /Weather/State/Wind/Gust/Current 0.00 /Weather/State/Wind/Gust/Minimum 0.00 /Weather/State/Wind/Gust/Maximum 7.12 /Weather/State/Wind/Direction/Current 225.00 /Weather/State/Wind/Direction/Minimum 225.00 /Weather/State/Wind/Direction/Maximum 225.00 /Weather/State/Rain/Total 0.00 /Weather/State/Station/Units 2 /Weather/State/Station/Time 2019-03-24 16:57:49 /Weather/State/Station/Name Weather /Weather/State/Debug/TemperatureValid V:1
The first part of topic 'Weather' is my station ID and will change to your settings. My readings are in USA format. I plan on adding JSON output to add the Units. If you have other addons then you should see more topics. Anything that is in the Full REST parameter will be included.
|
|
|
Post by gb0101010101 on Mar 24, 2019 16:35:30 GMT -8
Sample Serial output
---------------
DS3231 Clock
---------------
2019-03-24 17:33:50
---------------
AM2315
---------------
Temperature: 80.6 F
Humidity: 32 %
Dewpoint: 56.1 F
---------------
BMP280
---------------
Pressure: 31.27 inHg
Temperature: 85.4 F
Altitude: 1340.0 ft
---------------
SunAirPlus Not Present
---------------
---------------
WXLink Not Present
---------------
---------------
WeatherRack
---------------
Wind Speed: Min: 0.00 mph Max: 0.00 mph
Wind Gust: Min: 0.00 mph Max: 0.00 mph
Wind Direction: Min: 225.00 Max: 225.00
Current Wind: Speed: 0.00 mph Gust: 0.00 mph Direction: 225.00
Cumulative Rain: 0.00 in
|
|
|
Post by SDL on Mar 25, 2019 9:07:13 GMT -8
Excellent work! Messing around with the EEPROM is a pain in the butt. I wish preferences.h worked with the ESP8266!
If you could write up a one page implementation and setup document, I will merge the code into the master and do some publicity.
BP
|
|
|
Post by gb0101010101 on Mar 26, 2019 8:50:57 GMT -8
Will certainly write some docs once I am done making changes. Still want to add some missing data such as rainfall (hourly, daily). Also was to make MQTT user configurable without editing code. To do this I would like to save data to EEPROM. Could you please provide code to do this?
IP address: Can be 4 x 3 digits (uint8_t) OR 15 character string NNN.NNN.NNN.NNN Username & Password: Saved separately with length at least 12 characters each. Support any characters.
Thanks.
|
|
|
Post by SDL on Mar 28, 2019 6:34:10 GMT -8
Adding more to the EEPROM is a very tricky thing to do. Tell me more about what these parameters would do specifically. I think I get it (this is the IP of the MQTT broker, right?) but fill me in.
BP
|
|
|
Post by gb0101010101 on Mar 30, 2019 11:02:05 GMT -8
Yes the IP address is to the MQTT Server and is required. The Username and Password are optional, but highly recommended, and the lengths (12) I just decided.
Let me know if you need any more info.
|
|
|
Post by SDL on Mar 30, 2019 13:07:11 GMT -8
Thank you! I love MQTT. Dr. Shovic uses it all the time up at the university. He runs a ton of robots on ROS, which is also a publish/subscribe system very similar to MQTT.
BP
|
|
|
Post by gb0101010101 on Apr 2, 2019 15:17:02 GMT -8
I read up on EEPROM and determined the following. Please let me know if this is correct so I can implement MQTT save variables.
Each address in EEPROM can store a byte (of value 0-255) of information. So if I want to store and IP address I will need to write four bytes.
e.g. the numbers 192, 168, 1, 100 would written to four bytes.
For text, each character takes up a byte, so I have my 12 character char array for MQTT password and write each character.
Looking at EEPROM write code in Utils.h I see that the last written address is 349 for BlynkAuthCode. This is a String that does not have a set length and your code writes each character of the string. So how do you know what the next safe address is?
Should all strings be converted to fixed char array before being written so that you know the addresses it will use?
e.g.
WeatherUnderground_StationID starts at address 200 and reads 15 bytes. What if someone enters a station ID that is 30 characters long? It looks like this will overwrite the address space used for WeatherUnderground_StationKey which starts at 215. There is nothing in aREST setWUSID() function or writeEEPROMstate function that limits the input length and and the max address it could write to.
Please let me know so I can understand this and finish the MQTT implementation. Thanks.
|
|
|
Post by SDL on Apr 3, 2019 11:05:17 GMT -8
Yes, the EEPROM code is a mess and touchy. Every one of those entries needs to be checked.
BP
|
|
|
Post by gb0101010101 on Apr 4, 2019 22:46:05 GMT -8
Attached screenshot of OpenHAB data logging using MQTT. No rain in sample time. Attachments:
|
|
|
Post by SDL on Apr 5, 2019 8:51:51 GMT -8
Love it! Have you looked at Zabbix IT? It looks somewhat similar to the output above.
BP
|
|
|
Post by gb0101010101 on Apr 6, 2019 20:25:05 GMT -8
I know of Zabbix but have not used it. My location is remote and Internet can be spotty so I focus on local data storage with upload to Cloud when available. That is why I use OpenHAB and MQTT. Since I had OpenHAB already setup for home automation I quickly configured it to draw those graphs from MQTT data. There are other 'widgets' in OpenHAB for displaying weather related data, such as compass style wind direction, but I have not played with that yet.
I'm sure others love the Cloud but for me it is a constant problem.
|
|
|
Post by gb0101010101 on Apr 8, 2019 9:40:25 GMT -8
Did more research on EEPROM and came up with the following code to save and read MQTT settings. Please let me know if you think this is good as I do not want to corrupt the EEPROM. // ADD to writeEEPROMState()
// MQTT server IP: IPAddress[4] 392-396. EEPROM.put(392, mqtt_server);
// MQTT user: char[12] 397-409. EEPROM.put(397, mqtt_user);
// MQTT user: char[12] 410-422. EEPROM.put(410, mqtt_pass); And then to read: // ADD to readEEPROMState()
// MQTT server IP: char[4] 392-396. EEPROM.get(392, mqtt_server);
// MQTT user: char[12] 397-409. EEPROM.get(397, mqtt_user);
// MQTT pass: char[12] 410-422. EEPROM.get(410, mqtt_pass); Also does OurWeather board support using IPV6?
I have not coded for it. Thanks.
|
|
|
Post by SDL on Apr 8, 2019 13:42:21 GMT -8
Haven't even looked at IPV6. I seem to remember that the latest version of the ESP8266/ESP32 does support it however.
BP
|
|