https://github.com/jhughes1010/weather
Version log on master branch and notable development commits
Date | Version | BRANCH | Comments/Known issues |
---|---|---|---|
| 0.9 | Master | Initial release for basic user testing and feedback. Known issues:
|
| 1.0 | Master | Thingspeak operational, low battery voltage code corrected. |
| 1.1 (release candidate) | Develop | Math error corrected in wind speed measurement. IRAM_ATTR added in ISRs to move interrupt code processing to SRAM per ESP32 documentation. Testing now. |
| 1.1 (release candidate) | Develop | Found an attribute to copy ISR to SRAM. Code is stable at 1000 boot cycles now. WDT code added for 60s watchdog. |
| 1.1 | Master | Develop merged to master for 1.1 release |
| 1.2 RC1 | Master |
|
| 1.2 RC2 | Master |
|
Ensure you download from the MASTER branch. I’m actively working on DEVELOP.
Create a folder called ‘weather’ where you keep your Arduino projects
Download files from GitHub and place them all inside the weather folder
rename sec.h to secrets.h
this file contains WiFi details, api keys for internet data destinations, and configuration options
I’m actively working on this project and secrets.h contain my specific information
secrets.h
//=========================================== //Controls supression of the MonPrintf function to serial //=========================================== #define SerialMonitor |
line #4 contains a flag that controls printing to the serial console. I use it for debug, but commenting this line out can save time when the processor is drawing high current by suppressing all serial printing.
//=========================================== //WiFi connection //=========================================== char ssid[] = "ssid"; // WiFi Router ssid char pass[] = "password"; // WiFi Router password //=========================================== //Blynk connection //=========================================== char auth[] = "Blynk_password"; const char* server = "api.blynk.com"; //=========================================== //Thinkspeak connection //=========================================== //const char* server = "api.thingspeak.com"; const char* api_key = "THinkspeak_API_key"; //=========================================== //MQTT broker connection //=========================================== //const char* mqttServer = "test.mosquitto.org"; const char* mqttServer = "your_MQTT_broker"; const int mqttPort = 1883; const char* mqttUser = "username"; const char* mqttPassword = "password"; const char mainTopic[20] = "MainTopic_for_MQTT_subtopics to reside/"; |
Comment this #define to use imperial measurements
//=========================================== //Metric or Imperial measurements //=========================================== #define METRIC |
I’m publishing data to an e-ink display, so 15 min updates are fine for my needs. Set it to what you desire, but remember weather conditions do not change that rapidly.
//=========================================== //Set how often to wake and read sensors //=========================================== const int UpdateIntervalSeconds = 15 * 60; //Sleep timer (900s) for my normal operation //const int UpdateIntervalSeconds = 5 * 60; //Sleep timer (60s) testing |
I had an interesting observation where my anemometer closes the switch we use to observe revolutions twice instead of once per revolution.
//=========================================== //Anemometer Calibration //=========================================== //I see 2 switch pulls to GND per revolation. Not sure what others see #define WIND_TICKS_PER_REVOLUTION 2 |
You need to chose Blynk or Thingspeak, but not both. MQTT is optional and can be commented out if not used.
Please be certain to comment out the #define MQTT if you are not using it. It may cause RESET issues with the ESP. |
//========================= Enable Blynk or Thingspeak =================================== // configuration control constant for use of either Blynk or Thingspeak const String App = "BLYNK"; // alternative is line below //const String App = "Thingspeak"; // alternative is line above #define MQTT |
This is the calibration factor for the ADC pin that monitors the battery voltage via the voltage divider pin. There are non-linearities in the ADC and we are not supplying a reference voltage. Much easier to just make the math work.
Measure voltage at the battery
Locate the ADC reading via MQTT
Divide battery voltage by ADC value
//=========================================== //Battery calibration //=========================================== //measured battery voltage/ADC reading #define batteryCalFactor .001167 |
I added an I2C based EEPROM for backup storage of rainfall history data. There are situations where the controller can RESET that are out of my control. For instance, if my MQTT broker goes offline, the unit will RESET. I decided to use EEPROM memory outside the ESP32 to absolutely ensure I do not run into write endurance concerns.
//=========================================== //Use optional NVM for backup //This is a failsafe for RESET events out of //system control //=========================================== //#define USE_EEPROM |