maintenance mode (final cleanups)

This commit is contained in:
cyberman54 2021-03-07 18:34:52 +01:00
parent ad3567df45
commit 1061ff2fd2
2 changed files with 12 additions and 13 deletions

View File

@ -118,16 +118,16 @@ Use <A HREF="https://platformio.org/">PlatformIO</A> with your preferred IDE for
# Uploading # Uploading
- **Initially, using USB/UART cable:** - **by cable, via USB/UART interface:**
To upload the code via cable to your ESP32 board this needs to be switched from run to bootloader mode. Boards with USB bridge like Heltec and TTGO usually have an onboard logic which allows soft switching by the upload tool. In PlatformIO this happenes automatically.<p> To upload the code via cable to your ESP32 board this needs to be switched from run to bootloader mode. Boards with USB bridge like Heltec and TTGO usually have an onboard logic which allows soft switching by the upload tool. In PlatformIO this happenes automatically.<p>
The LoPy/LoPy4/FiPy board needs to be set manually. See these The LoPy/LoPy4/FiPy board needs to be set manually. See these
<A HREF="https://www.thethingsnetwork.org/labs/story/program-your-lopy-from-the-arduino-ide-using-lmic">instructions</A> how to do it. Don't forget to press on board reset button after switching between run and bootloader mode.<p> <A HREF="https://www.thethingsnetwork.org/labs/story/program-your-lopy-from-the-arduino-ide-using-lmic">instructions</A> how to do it. Don't forget to press on board reset button after switching between run and bootloader mode.<p>
The original Pycom firmware is not needed, so there is no need to update it before flashing Paxcounter. Just flash the compiled paxcounter binary (.elf file) on your LoPy/LoPy4/FiPy. If you later want to go back to the Pycom firmware, download the firmware from Pycom and flash it over. The original Pycom firmware is not needed, so there is no need to update it before flashing Paxcounter. Just flash the compiled paxcounter binary (.elf file) on your LoPy/LoPy4/FiPy. If you later want to go back to the Pycom firmware, download the firmware from Pycom and flash it over.
- **During runtime, automated using OTA via WIFI:** - **over the air (OTA), download via WiFi:**
After the ESP32 board is initially flashed and has joined a LoRaWAN network, the firmware can update itself by OTA. This process is kicked off by sending a remote control command (see below) via LoRaWAN to the board. The board then tries to connect via WiFi to a cloud service (JFrog Bintray), checks for update, and if available downloads the binary and reboots with it. If something goes wrong during this process, the board reboots back to the current version. Prerequisites for OTA are: 1. You own a Bintray repository, 2. you pushed the update binary to the Bintray repository, 3. internet access via encrypted (WPA2) WiFi is present at the board's site, 4. WiFi credentials were set in ota.conf and initially flashed to the board. Step 2 runs automated, just enter the credentials in ota.conf and set `upload_protocol = custom` in platformio.ini. Then press build and lean back watching platformio doing build and upload. After the ESP32 board is initially flashed and has joined a LoRaWAN network, the firmware can update itself by OTA. This process is kicked off by sending a remote control command (see below) via LoRaWAN to the board. The board then tries to connect via WiFi to a cloud service (JFrog Bintray), checks for update, and if available downloads the binary and reboots with it. If something goes wrong during this process, the board reboots back to the current version. Prerequisites for OTA are: 1. You own a Bintray repository, 2. you pushed the update binary to the Bintray repository, 3. internet access via encrypted (WPA2) WiFi is present at the board's site, 4. WiFi credentials were set in ota.conf and initially flashed to the board. Step 2 runs automated, just enter the credentials in ota.conf and set `upload_protocol = custom` in platformio.ini. Then press build and lean back watching platformio doing build and upload.
- **During runtime, manually using OTA via WIFI:** - **over the air (OTA), upload via WiFi:**
If option *BOOTMENU* is defined in `paxcounter.conf`, the ESP32 board will try to connect to a known WiFi access point each time cold starting (after a power cycle or a reset), using the WiFi credentials given in `ota.conf`. Once connected to the WiFi it will fire up a simple webserver, providing a bootstrap menu waiting for a user interaction (pressing "START" button in menu). This process will be aborted by ESP32 hardware watchdog after *BOOTDELAY* seconds, ensuring booting the device to runmode. Once a user interaction in bootstrap menu was detected, the watchdog time will be extended to *BOOTTIMEOUT* seconds. During this time a firmware upload can be performed manually by user, e.g. using a smartphone in tethering mode providing the firmware upload file. If option *BOOTMENU* is defined in `paxcounter.conf`, the ESP32 board will try to connect to a known WiFi access point each time cold starting (after a power cycle or a reset), using the WiFi credentials given in `ota.conf`. Once connected to the WiFi it will fire up a simple webserver, providing a bootstrap menu waiting for a user interaction (pressing "START" button in menu). This process will be aborted by ESP32 hardware watchdog after *BOOTDELAY* seconds, ensuring booting the device to runmode. Once a user interaction in bootstrap menu was detected, the watchdog time will be extended to *BOOTTIMEOUT* seconds. During this time a firmware upload can be performed manually by user, e.g. using a smartphone in tethering mode providing the firmware upload file.
# Legal note # Legal note

View File

@ -21,13 +21,13 @@ void start_boot_menu(void) {
const char *ssid = WIFI_SSID; const char *ssid = WIFI_SSID;
const char *password = WIFI_PASS; const char *password = WIFI_PASS;
RTC_runmode = RUNMODE_NORMAL; RTC_runmode = RUNMODE_NORMAL; // if watchdog fires, boot to production
hw_timer_t *timer = NULL; hw_timer_t *timer = NULL;
timer = timerBegin(2, 80, true); // timer 2, div 80, countup timer = timerBegin(2, 80, true); // timer 2, div 80, countup
timerAttachInterrupt(timer, &esp_restart, true); // callback device reset timerAttachInterrupt(timer, &esp_restart, true); // apply watchdog reset
timerAlarmWrite(timer, BOOTDELAY * 1000000, false); // set time in us timerAlarmWrite(timer, BOOTDELAY * 1000000, false); // watchdog time in us
timerAlarmEnable(timer); // enable interrupt timerAlarmEnable(timer); // enable watchdog
WebServer server(80); WebServer server(80);
@ -100,8 +100,9 @@ void start_boot_menu(void) {
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
// Connect to WiFi network // Connect to WiFi network
// workaround applied here to avoid WIFI_AUTH failure // workaround applied here to bypass WIFI_AUTH failure
// see https://github.com/espressif/arduino-esp32/issues/2501 // see https://github.com/espressif/arduino-esp32/issues/2501
// 1st try // 1st try
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
while (WiFi.status() == WL_DISCONNECTED) { while (WiFi.status() == WL_DISCONNECTED) {
@ -117,28 +118,26 @@ void start_boot_menu(void) {
MDNS.begin(host); MDNS.begin(host);
// send start button page
server.on("/", HTTP_GET, [&server, &loginMenu]() { server.on("/", HTTP_GET, [&server, &loginMenu]() {
server.sendHeader("Connection", "close"); server.sendHeader("Connection", "close");
server.send(200, "text/html", loginMenu); server.send(200, "text/html", loginMenu);
}); });
// send upload button page
server.on("/serverIndex", HTTP_GET, [&server, &serverIndex, &timer]() { server.on("/serverIndex", HTTP_GET, [&server, &serverIndex, &timer]() {
timerAlarmWrite(timer, BOOTTIMEOUT * 1000000, false); timerAlarmWrite(timer, BOOTTIMEOUT * 1000000, false);
server.sendHeader("Connection", "close"); server.sendHeader("Connection", "close");
server.send(200, "text/html", serverIndex); server.send(200, "text/html", serverIndex);
}); });
server.onNotFound([&server, &loginMenu]() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", loginMenu);
});
// handling uploading firmware file // handling uploading firmware file
server.on( server.on(
"/update", HTTP_POST, "/update", HTTP_POST,
[&server]() { [&server]() {
server.sendHeader("Connection", "close"); server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
delay(5000);
WiFi.disconnect(true); WiFi.disconnect(true);
if (!Update.hasError()) if (!Update.hasError())
RTC_runmode = RUNMODE_POWERCYCLE; RTC_runmode = RUNMODE_POWERCYCLE;