Now that we have our hardware soldered together and our code deployed, all that's left to glue it together is the firmware. Setting it up should be straightforward.
Clone the following repository
https://github.com/owolabioromidayo/swiss_firm
Move main/config_example.h to main/config.h.
If your hardware connections to the ESP32 are the same as the schematic in the previous section, then you have nothing to edit. If not, edit the pin configurations.
Install the ESP-IDF Framework: Link
Install the CP210x USB-UART Driver: Link
Connect your ESP32 to your PC via USB. Open Device Manager and confirm that the driver works.
Open the ESP_IDF CMD tool.
Navigate to the firmware folder.
Run idf.py flash build monitor. If you keep getting flash errors, try holding down the buttons on your ESP32. The left button is for restarting and the right button is for flashing.
The code should be configured in test mode so you should see the ESP32 attempt reads from the sensors. If this is successful, then you are more than halfway done. If not, your hardware connections might contain some mistakes.
If you are experiencing brownout errors, your hardware connections are at fault.
Now set TEST_MODE in your config.h file to 0 and HOSTNAME to the endpoint of your main service with the publish password i.e. https://herokusite.com/publish?password=PUBLISH_PASSWORD.
To setup ca_cert (the TLS/SSL certificate for your backend server), do the following:
In your Linux Terminal, run openssl s_client -showcerts -connect reqbin.com:443 < /dev/null > server_cert.pem (Ensure you have openssl installed).
Copy the second certificate from there and replace the ca_cert field in config.h. Ensure to use the same spacing mechanism (new lines and escapes), so that C can parse the string.
Navigate to src/main.c and change SLEEP_TIME_MIN to 1 so we can test the whole thing.
Recompile and run your code with idf.py flash build monitor.
Now shake your rain gauge to trigger an interrupt. You should see the system boot back up and record this.
Wait for 1 minute and the system should create a hotspot.
Connect to this hotspot with the default password in lib/esp32-wifi-manager/Kconfig which is esp32pwd. You can change this value along with the hotspot name from here if you wish.
Go to the website 10.10.0.1 while connected to the hotspot and fill in your Wifi Details.
The system should now attempt to collect all sensor values and post them to the main service.
At this point. the only other thing that is untested is the wind vane so you should see logs of the wind direction in the terminal before the system posts data.
If everything goes well, the data should be posted to the main service. You can confirm that the whole system works by checking your database information
Now that everything is working properly, set SLEEP_TIME_MIN to 30.
Also, you should clear the collections in your database except for config, and delete the last_model_update_time field in the config collection. Ensure that the mode field is set to weather_api as we need it in this mode for about 2 months to gather enough data to train a good enough model.
With that finished, all that's left is Enclosure and Deployment.