Skip to content

Preparing

Install Platformio

Install PlatformIO IDE for embedded development to build this project. Platformio integrates with your favorite IDE, choose e.g. Visual Studio Code, Atom, Eclipse etc.

Compile time configuration is spread across several files. Before compiling the code, edit or create the following files:

platformio.ini

Edit platformio_orig.ini (for ESP32 CPU based boards) or platformio_orig_s3.ini (for ESP32-S3 CPU based boards) and select desired board in section board. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in section board. Copy or rename to platformio.ini in the root directory of the project. Now start Platformio.

Selecting a board

Uncomment your board
;
[board]
;halfile = generic.h
;halfile = ebox.h
;halfile = eboxtube.h
;halfile = ecopower.h
;halfile = heltec.h
;halfile = heltecv2.h
;halfile = heltecv21.h
;halfile = ttgov1.h
;halfile = ttgov2.h
;halfile = ttgov21old.h
halfile = ttgov21new.h
;halfile = ttgofox.h
;halfile = ttgobeam.h
;halfile = ttgobeam10.h
;halfile = ttgotdisplay.h
;halfile = ttgotwristband.h
;halfile = fipy.h
;halfile = lopy.h
;halfile = lopy4.h
;halfile = lolin32litelora.h
;halfile = lolin32lora.h
;halfile = lolin32lite.h
;halfile = wemos32oled.h
;halfile = wemos32matrix.h
;halfile = octopus32.h
;halfile = tinypico.h
;halfile = tinypicomatrix.h
;halfile = m5core.h
;halfile = m5fire.h
cp platformio_orig.ini platformio.ini
mv platformio_orig.ini platformio.ini
platformio_orig_s3.ini
cp platformio_orig_s3.ini platformio.ini
mv platformio_orig_s3.ini platformio.ini

Info

Platformio is looking for platformio.ini in the root directory and won't start if it does not find this file!

paxcounter.conf

Edit shared/paxcounter_orig.conf and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Copy or rename to shared/paxcounter.conf.

cp shared/paxcounter_orig.conf shared/paxcounter.conf
mv shared/paxcounter_orig.conf shared/paxcounter.conf

If your device has a real time clock it can be updated by either LoRaWAN network or GPS time, according to settings TIME_SYNC_INTERVAL and TIME_SYNC_LORAWAN in paxcounter.conf.

paxcounter.conf
#define RESPONSE_TIMEOUT_MS             60000   // firmware binary server connection timeout [milliseconds]

shared/lmic_config.h

Edit shared/lmic_config.h and tailor settings in this file according to your country and device hardware. Please take care of national regulations when selecting the frequency band for LoRaWAN.

national regulations in shared/lmic_config.h
#define CFG_eu868 1 // Europe (high band)
//#define CFG_us915 1 // USA, Canada and South America
//#define CFG_in866 1 // India
//#define CFG_au915 1 // Australia
//#define CFG_as923 1 // Asia
//#define CFG_kr920 1 // Korea

// LMIC LORAWAN STACK SETTINGS
// --> adapt to your device only if necessary

shared/loraconf.h

Create file shared/loraconf.h using the template shared/loraconf_sample.h and adjust settings to use your personal values. To join the network and activate your paxcounter, you must configure either OTAA or ABP join method. You should use OTAA, whenever possible. To understand the differences of the two methods, this article may be useful.

cp shared/loraconf_sample.h shared/loraconf.h
mv shared/loraconf_sample.h shared/loraconf.h

To configure OTAA, leave #define LORA_ABP deactivated (commented). To use ABP, activate (uncomment) #define LORA_ABP in the file shared/loraconf.h. The file shared/loraconf_sample.h contains more information about the values to provide.

shared/loraconf.h
//#define LORA_ABP
shared/loraconf.h
#define LORA_ABP

shared/ota.conf

Create file shared/ota.conf using the template shared/ota_sample.conf and enter your WIFI network & key. These settings are used for downloading updates via WiFi, either from a remote https server, or locally via WebUI. If you want to use a remote server, you need a PAX.express repository. Enter your PAX.express credentials in ota.conf. If you don't need wireless firmware updates just rename ota.sample.conf to ota.conf.

cp shared/ota_sample.conf shared/ota.conf
mv shared/ota_sample.conf shared/ota.conf

Building

Use PlatformIO with your preferred IDE for development and building this code. Make sure you have latest PlatformIO version.

Uploading

Warning

  1. After editing paxcounter.conf, use "clean" button before "build" in PlatformIO!
  2. Clear NVRAM of the board to delete previous stored runtime settings (pio run -t erase)
  • 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.

    The LoPy/LoPy4/FiPy board needs to be set manually. See these instructions how to do it. Don't forget to press on board reset button after switching between run and bootloader mode.

    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.

  • 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 (PAX.express), 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 PAX.express repository, 2. you pushed the update binary to your PAX.express 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.

  • 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 time out after BOOTDELAY seconds, ensuring booting the device to runmode. Once a user interaction in bootstrap menu was detected, the timeout 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.