Wifi/BLE Paxcounter Project with ESP32 boards

By the way: The wifi / ble counting magics was removed from the paxcounter project. It was outsourced as an independent library, called libpax , which you can use for own projects. Paxcounter v3 is based on libpax.

PM sent

HI, Great project, fun to play around with. Is it possible to adjust the RSSI value via config files without connecting to a Lora network. I have a TTGO device with LED so just watching the counts on screen for now.

Hi i’m new here, i bought a LILYGO TTGO Lora V2.1_1.6 868 Mhz OLED 0.96 inch SD Card esp32 Wi-Fi & Bluetooth and i tried to flash paxcounter. I followed the tutorial and i dont’ have error during this, but now the board it’s in loop. This is the log.

[11:14:21]Backtrace:0x40083ff1:0x3ffcf5000x40096be5:0x3ffcf520 0x4009d3b5:0x3ffcf540 0x40096bdb:0x3ffcf5c0 0x400da8c5:0x3ffcf5e0 0x400da714:0x3ffcf6d0 0x400d4c94:0x3ffcf6f0 0x400d5f09:0x3ffcf710 0x400f35c2:0x3ffcf7f0
[11:14:21]
[11:14:21]
[11:14:21]
[11:14:21]
[11:14:21]ELF file SHA256: 0000000000000000
[11:14:21]
[11:14:21]Rebooting…
[11:14:21]ets Jun 8 2016 00:22:57
[11:14:21]
[11:14:21]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[11:14:21]configsip: 188777542, SPIWP:0xee
[11:14:21]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[11:14:21]mode:DIO, clock div:2
[11:14:21]load:0x3fff0018,len:4
[11:14:21]load:0x3fff001c,len:1044
[11:14:21]load:0x40078000,len:8896
[11:14:21]load:0x40080400,len:5828
[11:14:21]entry 0x400806ac
[11:14:22][ 17][I][configmanager.cpp:96] loadConfig(): [src/configmanager.cpp] Loading device configuration from NVRAM…
[11:14:22][ 19][I][configmanager.cpp:122] loadConfig(): [src/configmanager.cpp] Runtime configuration v3.3.2 loaded
[11:14:22][ 27][I][main.cpp:114] setup(): [src/main.cpp] Starting paxcounter_7aedd1ae v3.3.2 (runmode=0 / restarts=87)
[11:14:22][ 36][I][main.cpp:115] setup(): [src/main.cpp] code build date: 1665521572
[11:14:22][ 43][I][main.cpp:131] setup(): [src/main.cpp] This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB embedded Flash
[11:14:22][ 55][I][main.cpp:133] setup(): [src/main.cpp] Internal Total heap 224192, internal Free Heap 196848
[11:14:22][ 64][I][main.cpp:139] setup(): [src/main.cpp] ChipRevision 1, Cpu Freq 240, SDK Version v4.4.2
[11:14:22][ 73][I][main.cpp:141] setup(): [src/main.cpp] Flash Size 4194304, Flash Speed 40000000
[11:14:22][ 80][I][main.cpp:143] setup(): [src/main.cpp] Wifi/BT software coexist version 1.2.0
[11:14:22][ 88][I][main.cpp:147] setup(): [src/main.cpp] IBM LMIC version 1.6.1468577746
[11:14:22][ 96][I][main.cpp:152] setup(): [src/main.cpp] Arduino LMIC version 4.1.1.0
[11:14:22][ 103][I][lorawan.cpp:170] printKey(): [src/lorawan.cpp] AppEUI: 70B3D50000000000
[11:14:22][ 110][I][lorawan.cpp:170] printKey(): [src/lorawan.cpp] DevEUI: E89F6D088850FEFF
[11:14:22][ 117][I][lorawan.cpp:170] printKey(): [src/lorawan.cpp] AppKey: 00000000000000000000000000000000
[11:14:22][ 126][I][esp32-hal-i2c.c:75] i2cInit(): Initialising I2C Master: sda=21 scl=22 freq=100000
[11:14:22][ 135][I][i2c.cpp:40] i2c_scan(): [src/i2c.cpp] Starting I2C bus scan…
[11:14:22][ 141][W][Wire.cpp:301] begin(): Bus already started in Master Mode.
[11:14:22][ 265][I][i2c.cpp:71] i2c_scan(): [src/i2c.cpp] Device found at 0x3C, type = Unknown
[11:14:22][ 266][I][i2c.cpp:74] i2c_scan(): [src/i2c.cpp] 1 I2C device(s) found
[11:14:22][ 269][W][Wire.cpp:301] begin(): Bus already started in Master Mode.
[11:14:32][ 10416][I][main.cpp:228] setup(): [src/main.cpp] Starting LED Controller…
[11:14:32][ 10417][I][power.cpp:192] calibrate_voltage(): [src/power.cpp] ADC characterization based on reference voltage stored in eFuse
[11:14:32][ 10427][I][main.cpp:274] setup(): [src/main.cpp] Starting libpax…
[11:14:32][ 10429][I][main.cpp:283] setup(): [src/main.cpp] WIFISCAN: on
[11:14:32][ 10434][I][main.cpp:289] setup(): [src/main.cpp] BLESCAN: on
[11:14:32]ESP_ERROR_CHECK failed: esp_err_t 0x102 (ESP_ERR_INVALID_ARG) at 0x40096bd8
[11:14:32]file: “.pio/libdeps/usb/libpax/lib/libpax/wifiscan.cpp” line 106
[11:14:32]func: void wifi_sniffer_init(uint16_t)
[11:14:32]expression: esp_wifi_set_country(&wifi_country)
[11:14:32]
[11:14:32]abort() was called at PC 0x40096bdb on core 1
[11:14:32]
[11:14:32]
[11:14:32]Backtrace:0x40083ff1:0x3ffcf5000x40096be5:0x3ffcf520 0x4009d3b5:0x3ffcf540 0x40096bdb:0x3ffcf5c0 0x400da8c5:0x3ffcf5e0 0x400da714:0x3ffcf6d0 0x400d4c94:0x3ffcf6f0 0x400d5f09:0x3ffcf710 0x400f35c2:0x3ffcf7f0
[11:14:32]
[11:14:32]
[11:14:32]
[11:14:32]
[11:14:32]ELF file SHA256: 0000000000000000
[11:14:32]
[11:14:32]Rebooting…
[11:14:32]ets Jun 8 2016 00:22:57
[11:14:32]
[11:14:32]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[11:14:32]configsip: 188777542, SPIWP:0xee
[11:14:32]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[11:14:32]mode:DIO, clock div:2
[11:14:32]load:0x3fff0018,len:4
[11:14:32]load:0x3fff001c,len:1044
[11:14:32]load:0x40078000,len:8896
[11:14:32]load:0x40080400,len:5828
[11:14:32]entry 0x400806ac
[11:14:33][ 17][I][configmanager.cpp:96] loadConfig(): [src/configmanager.cpp] Loading device configuration from NVRAM…
[11:14:33][ 19][I][configmanager.cpp:122] loadConfig(): [src/configmanager.cpp] Runtime configuration v3.3.2 loaded
[11:14:33][ 27][I][main.cpp:114] setup(): [src/main.cpp] Starting paxcounter_7aedd1ae v3.3.2 (runmode=0 / restarts=88)
[11:14:33][ 36][I][main.cpp:115] setup(): [src/main.cpp] code build date: 1665521572
[11:14:33][ 43][I][main.cpp:131] setup(): [src/main.cpp] This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB embedded Flash
[11:14:33][ 55][I][main.cpp:133] setup(): [src/main.cpp] Internal Total heap 224192, internal Free Heap 196848
[11:14:33][ 64][I][main.cpp:139] setup(): [src/main.cpp] ChipRevision 1, Cpu Freq 240, SDK Version v4.4.2
[11:14:33][ 73][I][main.cpp:141] setup(): [src/main.cpp] Flash Size 4194304, Flash Speed 40000000
[11:14:33][ 81][I][main.cpp:143] setup(): [src/main.cpp] Wifi/BT software coexist version 1.2.0
[11:14:33][ 88][I][main.cpp:147] setup(): [src/main.cpp] IBM LMIC version 1.6.1468577746
[11:14:33][ 96][I][main.cpp:152] setup(): [src/main.cpp] Arduino LMIC version 4.1.1.0
[11:14:33][ 103][I][lorawan.cpp:170] printKey(): [src/lorawan.cpp] AppEUI: 70B3D50000000000
[11:14:33][ 110][I][lorawan.cpp:170] printKey(): [src/lorawan.cpp] DevEUI: E89F6D088850FEFF
[11:14:33][ 117][I][lorawan.cpp:170] printKey(): [src/lorawan.cpp] AppKey: 00000000000000000000000000000000
[11:14:33][ 126][I][esp32-hal-i2c.c:75] i2cInit(): Initialising I2C Master: sda=21 scl=22 freq=100000
[11:14:33][ 135][I][i2c.cpp:40] i2c_scan(): [src/i2c.cpp] Starting I2C bus scan…
[11:14:33][ 141][W][Wire.cpp:301] begin(): Bus already started in Master Mode.
[11:14:33][ 265][I][i2c.cpp:71] i2c_scan(): [src/i2c.cpp] Device found at 0x3C, type = Unknown
[11:14:33][ 266][I][i2c.cpp:74] i2c_scan(): [src/i2c.cpp] 1 I2C device(s) found
[11:14:33][ 269][W][Wire.cpp:301] begin(): Bus already started in Master Mode.

Can someone help me?

Please post log, code… and all other thing you can using </>

It makes it more readable for us trying to help you.

I use this code and toutorial (GitHub - cyberman54/ESP32-Paxcounter: Wifi & BLE driven passenger flow metering with cheap ESP32 boards) and i use this board (https://www.amazon.it/LILYGO-V2-1_1-6-Pollici-Bluetooth-Sviluppo/dp/B09FXHSS6P/ref=sr_1_1?__mk_it_IT=ÅMÅŽÕÑ&crid=347HC1VW7WSL5&keywords=lilygo&qid=1665569124&qu=eyJxc2MiOiI1LjIyIiwicXNhIjoiNC4wNiIsInFzcCI6IjIuNTIifQ%3D%3D&sprefix=lilygo%2Caps%2C91&sr=8-1). The logs are the ones I posted above.

The point made was that there are code formatting tools </> to make the code or logs more readable …

Can you tell me a few?

There aren’t a few to name - the </> tool is on the toolbar of the entry box where you type responses in this Discourse forum software.

ToolbarCodeFormatting

It turns this:

[11:14:21]Backtrace:0x40083ff1:0x3ffcf5000x40096be5:0x3ffcf520 0x4009d3b5:0x3ffcf540 0x40096bdb:0x3ffcf5c0 0x400da8c5:0x3ffcf5e0 0x400da714:0x3ffcf6d0 0x400d4c94:0x3ffcf6f0 0x400d5f09:0x3ffcf710 0x400f35c2:0x3ffcf7f0
[11:14:21]
[11:14:21]ELF file SHA256: 0000000000000000
[11:14:21]
[11:14:21]Rebooting…
[11:14:21]ets Jun 8 2016 00:22:57
[11:14:21]
[11:14:21]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[11:14:21]configsip: 188777542, SPIWP:0xee

in to this:

[11:14:21]Backtrace:0x40083ff1:0x3ffcf5000x40096be5:0x3ffcf520 0x4009d3b5:0x3ffcf540 0x40096bdb:0x3ffcf5c0 0x400da8c5:0x3ffcf5e0 0x400da714:0x3ffcf6d0 0x400d4c94:0x3ffcf6f0 0x400d5f09:0x3ffcf710 0x400f35c2:0x3ffcf7f0
[11:14:21]
[11:14:21]ELF file SHA256: 0000000000000000
[11:14:21]
[11:14:21]Rebooting…
[11:14:21]ets Jun 8 2016 00:22:57
[11:14:21]
[11:14:21]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[11:14:21]configsip: 188777542, SPIWP:0xee

which also turns it in to a scroll box when there is a lot of text.

Ok sorry i did not understand, my english it’s bad sorry.
Now i try to flash old firmware the 3.3.1 and the board it’s exit from the loop but don’t comunicate with the things network console.

This is my platformio.ini, i change only the board in ttgov21new.h

; ---> SELECT ONE TARGET BOARD FROM FOLLOWING ROWS <---
;
; Note: For "LILYGO TTGO ESP32-Paxcounter LoRa32 V2.1 1.6.1" select board ttgov21new.h
;
;
[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
;halfile = olimexpoeiso.h

[platformio]
; upload firmware to board with usb cable
default_envs = usb
; upload firmware to a paxexpress repository
;default_envs = ota
; use upstream version of arduino-espressif32 framework
;default_envs = dev
description = Paxcounter is a device for metering passenger flows in realtime. It counts how many mobile devices are around.

[common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 3.3.1
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 3
extra_scripts = pre:build.py
otakeyfile = ota.conf
lorakeyfile = loraconf.h
lmicconfigfile = lmic_config.h
platform_espressif32 = espressif32@5.1.0
monitor_speed = 115200
upload_speed = 115200 ; set by build.py and taken from hal file
display_library = ; set by build.py and taken from hal file
lib_deps_lora =
    mcci-catena/MCCI LoRaWAN LMIC library @ ^4.1.1
lib_deps_display =
    https://github.com/bitbank2/OneBitDisplay.git
    https://github.com/bitbank2/bb_spi_lcd.git
    ricmoo/QRCode @ ^0.0.1
lib_deps_ledmatrix =
    seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0
lib_deps_rgbled =
    https://github.com/RoboticsBrno/SmartLeds.git
lib_deps_gps =
    mikalhart/TinyGPSPlus @ ^1.0.2
lib_deps_sensors =
    adafruit/Adafruit Unified Sensor @ ^1.1.4
    adafruit/Adafruit BME280 Library @ ^2.2.1
    adafruit/Adafruit BMP085 Library @ ^1.2.0
    boschsensortec/BSEC Software Library @ 1.6.1480
    https://github.com/cyberman54/sds-dust-sensors-arduino-library.git
lib_deps_basic =
    https://github.com/dbSuS/libpax.git
    https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
    bblanchon/ArduinoJson @ ^6
    makuna/RTC @ ^2.3.5
    spacehuhn/SimpleButton 
    https://github.com/lewisxhe/XPowersLib.git
    256dpi/MQTT @ ^2.4.8
lib_deps_all =
    ${common.lib_deps_basic}
    ${common.lib_deps_lora}
    ${common.lib_deps_display}
    ${common.lib_deps_rgbled}
    ${common.lib_deps_gps}
    ${common.lib_deps_sensors}
    ${common.lib_deps_ledmatrix}
build_flags_basic =
    -include "src/hal/${board.halfile}"
    -include "src/paxcounter.conf"
    '-DCORE_DEBUG_LEVEL=${common.debug_level}'
    '-DLOG_LOCAL_LEVEL=${common.debug_level}'
    '-DPROGVERSION="${common.release_version}"'
    '-D LIBPAX_WIFI'
    '-D LIBPAX_BLE'
    '-D LIBPAX_ARDUINO'
build_flags_all =
    ${common.build_flags_basic}
    -mfix-esp32-psram-cache-issue

[env]
framework = arduino
board = esp32dev
board_build.partitions = min_spiffs.csv
build_type = release
upload_speed = ${common.upload_speed}
;upload_port = COM12
platform = ${common.platform_espressif32}
lib_deps = ${common.lib_deps_all}
build_flags = ${common.build_flags_all}
upload_protocol = ${common.upload_protocol}
extra_scripts = ${common.extra_scripts}
monitor_speed = ${common.monitor_speed}
monitor_filters = time, esp32_exception_decoder, default

[env:ota]
upload_protocol = custom

[env:usb]
upload_protocol = esptool

[env:dev]
upload_protocol = esptool
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git

This is my loraconf.h file

#ifndef __LORACONF_H__
#define __LORACONF_H__

#if (HAS_LORA)

/************************************************************
 * LMIC LoRaWAN configuration
 *
 * Read the values from TTN console (or whatever applies), insert them here,
 * and rename this file to src/loraconf.h
 *
 * You can configure OTAA or ABP Activation. In order to use ABP, uncomment
 * (enable) the following line, but you should only do so, if you have good 
 * reasons for not using OTAA.
 * 
 *************************************************************/
static const u1_t DEVEUI[8] = {0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x05, 0x65, 0x77};

static const u1_t APPEUI[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static const u1_t APPKEY[16] = {0xFF, 0x84, 0x04, 0x4A, 0x49, 0xC6, 0xA0, 0x7D, 0xA0, 0x42, 0x34, 0x57, 0x4B, 0xE4, 0x27, 0x34};

//#define LORA_ABP

#ifndef LORA_ABP
/************************************************************
 * OTAA configuration
 * 
 * DEVEUI, APPEUI and APPKEY should all be specified in MSB format as 
 * displayed in TTN console, so you can cut & paste from there. This is different
 * from standard LMIC-Arduino which expects DEVEUI and APPEUI in LSB format.
 * For TTN, APPEUI in MSB format always starts with 0x70, 0xB3, 0xD5.
 * Set your DEVEUI here, if your device has have a fixed one. 
 * If you leave this untouched, then the DEVEUI will be derived from device's 
 * MAC adress during startup and will be displayed on device's screen as well as
 * on serial console, if you set 'verbose 1' in paxcounter.conf and 
 * 'debug_level 3' in platformio.ini.
 * If using a board with Microchip 24AA02E64 Uinique ID for deveui, the DEVEUI 
 * will be overwritten by the one contained in the Microchip module.
 *
 ************************************************************/

//static const u1_t DEVEUI[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

//static const u1_t APPEUI[8] = {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00};

//static const u1_t APPKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

#endif

#ifdef LORA_ABP
/************************************************************
 * ABP configuration (for development)
 *
 * Get your
 *   - Network Session Key (NWKSKEY)
 *   - App Session Key and your (APPSKEY)
 *   - Device Address (DEVADDR)
 * from e.g. TTN console and replace the example values below.
 * 
 * NOTE: Use MSB format (as displayed in TTN console, so you can cut & paste
 * from there)
 *
 * NOTE: You may also need to adjust lorawan_abp.cpp in order to configure
 * different channels and data rate channels to match your country's regulations
 * and your network's settings.
 * 
 ************************************************************/

// ID of LoRaAlliance assigned Network (for a list, see e.g. here
// https://www.thethingsnetwork.org/docs/lorawan/prefix-assignments.html)
static const u1_t NETID = 0x13; // TTN

static const u1_t NWKSKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00};

static const u1_t APPSKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00};

static const u4_t DEVADDR =
    0x00000000; // <-- Change this address for every node!

// set additional ABP parameters in loraconf_abp.cpp
void setABPParameters();

#endif

#endif // HAS_LORA

#endif // __LORACONF_H__

And this is my ota.conf file where i change mywifi and password with my wifi name and my wifi password

[ota]
OTA_WIFI_SSID = mywifi
OTA_WIFI_PASS = password

[paxexpress]
PAXEXPRESS_USER = MyPaxexpressUser
PAXEXPRESS_REPO = MyPaxexpressRepo
PAXEXPRESS_API_TOKEN = 3894a7a51d70c6523c1b7479261c34845ebf7878

And in paxcounter.conf file i don’t change anything

// clang-format off

// ----- Paxcounter user config file ------
//
// --> adapt to your needs and use case <--
//
// Notes:
// 1. After editing, before "build", use "clean" button in PlatformIO!
// 2. Clear NVRAM of the board to delete previous stored runtime settings (pio run -t erase)

// Device options
#define VERBOSE                         1       // set to 0 to silence the device, 1 enables additional debug output
#define BOOTMENU                        0       // 0 = no bootmenu, 1 = device brings up boot menu before starting application
#define BOOTDELAY                       30      // time [seconds] while devices waits in boot menue for input
#define BOOTTIMEOUT                     300     // time [seconds] while devices waits to finish upload a firmware file

// Payload send cycle and encoding
#define SENDCYCLE                       30      // payload send cycle [seconds/2], 0 .. 255
#define SLEEPCYCLE                      0       // sleep time after a send cycle [seconds/10], 0 .. 65535; 0 means no sleep [default = 0]
#define PAYLOAD_ENCODER                 2       // payload encoder: 1=Plain, 2=Packed, 3=Cayenne LPP dynamic, 4=Cayenne LPP packed
#define COUNTERMODE                     0       // 0=cyclic, 1=cumulative, 2=cyclic confirmed

// default settings for transmission of sensor data (first list = data on / second line = data off)
#define PAYLOADMASK                                                                             \
            ((GPS_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) & \
            (~BATT_DATA) & (~RESERVED_DATA))

// MAC sniffing parameters
#define BLECOUNTER                      1       // set to 0 if you do not want to install the BLE sniffer
#define WIFICOUNTER                     1       // set to 0 if you do not want to install the WIFI sniffer

// BLE scan parameters
#define BLESCANTIME                     0       // [seconds] scan duration, 0 means infinite [default], see note below
#define BLESCANWINDOW                   80      // [milliseconds] scan window, see below, 3 .. 10240, default 80ms
#define BLESCANINTERVAL                 80      // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle

/* Note: guide for setting bluetooth parameters
*
* |< Scan Window >       |< Scan Window >       | ... |< Scan Window >       |
* |<    Scan Interval   >|<    Scan Interval   >| ... |<    Scan Interval   >|
* |<                   Scan duration                                        >|
*
* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default).
* Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL.
* Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising.
* -> Adjust these values with power consumption in mind if power is limited.
* -> Scan interval can be changed during runtime by remote comammand.
*/

// WiFi scan parameters
#define WIFI_CHANNEL_MIN                1       // start channel number where scan begings
#define	WIFI_CHANNEL_MAX                13      // total channel number to scan
#define WIFI_MY_COUNTRY                 "EU"    // select locale for Wifi RF settings
#define	WIFI_CHANNEL_SWITCH_INTERVAL    50      // [seconds/100] -> 0,5 sec.

// LoRa payload default parameters
#define MEM_LOW                         2048    // [Bytes] low memory threshold triggering a send cycle
#define RETRANSMIT_RCMD                 5       // [seconds] wait time before retransmitting rcommand results
#define PAYLOAD_BUFFER_SIZE             51      // maximum size of payload block per transmit
#define PAYLOAD_OPENSENSEBOX            0       // send payload compatible to sensebox.de (swap geo position and pax data)
#define LORADRDEFAULT                   5       // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5]
#define LORATXPOWDEFAULT                14      // 0 .. 255, LoRaWAN TX power in dBm [default = 14]
#define MAXLORARETRY                    500     // maximum count of TX retries if LoRa busy
#define SEND_QUEUE_SIZE                 10      // maximum number of messages in payload send queue [1 = no queue]

// Hardware settings
#define RGBLUMINOSITY                   30      // RGB LED luminosity [default = 30%]
#define DISPLAYREFRESH_MS               40      // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second
#define DISPLAYCONTRAST                 80      // 0 .. 255, OLED display contrast [default = 80]
#define DISPLAYCYCLE                    3       // Auto page flip delay in sec [default = 2] for devices without button
#define HOMECYCLE                       30      // house keeping cycle in seconds [default = 30 secs]

// Settings for BME680 environmental sensor
#define BME_TEMP_OFFSET                 5.0f    // Offset sensor on chip temp <-> ambient temp [default = 5°C]
#define STATE_SAVE_PERIOD               UINT32_C(360 * 60 * 1000) // update every 360 minutes = 4 times a day
#define BMECYCLE                        1       // bme sensor read cycle in seconds [default = 1 secs]

// OTA settings
#define USE_OTA                         1       // set to 0 to disable OTA update
#define WIFI_MAX_TRY                    5       // maximum number of wifi connect attempts for OTA update [default = 20]
#define OTA_MAX_TRY                     5       // maximum number of attempts for OTA download and write to flash [default = 3]
#define OTA_MIN_BATT                    50      // minimum battery level for OTA [percent]
#define RESPONSE_TIMEOUT_MS             60000   // firmware binary server connection timeout [milliseconds]

// settings for syncing time of node with a time source (network / gps / rtc / timeserver)
#define TIME_SYNC_LORAWAN               1       // set to 1 to use LORA network as time source, 0 means off [default = 1]
#define TIME_SYNC_LORASERVER            0       // set to 1 to use LORA timeserver as time source, 0 means off [default = 0]
#define TIME_SYNC_INTERVAL              60      // sync time attempt each .. minutes from time source [default = 60], 0 means off
#define TIME_SYNC_INTERVAL_RETRY        10      // retry time sync after lost sync each .. minutes [default = 10], 0 means off
#define TIME_SYNC_SAMPLES               1       // number of time requests for averaging, max. 255
#define TIME_SYNC_CYCLE                 60      // delay between two time samples [seconds]
#define TIME_SYNC_TIMEOUT               400     // timeout waiting for timeserver answer [seconds]
#define TIME_SYNC_COMPILEDATE           0       // set to 1 to use compile date to initialize RTC after power outage [default = 0]
#define TIME_SYNC_TIMEZONE              "CET-1CEST,M3.4.0/2,M10.4.0/3" // Timezone in POSIX format (example shows Germany/Berlin)

// Ports on which the device sends and listenes on LoRaWAN and SPI
#define COUNTERPORT                     1       // counts
#define MACPORT                         0       // network commands
#define RCMDPORT                        2       // remote commands
#define STATUSPORT                      2       // remote command results
#define CONFIGPORT                      3       // config query results
#define GPSPORT                         4       // gps - NOTE: set to 1 to send combined GPS+COUNTERPORT payload  
#define BUTTONPORT                      5       // button pressed signal
#define RESERVEDPORT                    6       // reserved (unused)
#define BMEPORT                         7       // BME680 sensor
#define BATTPORT                        8       // battery voltage
#define TIMEPORT                        9       // time query and response
#define SENSOR1PORT                     10      // user sensor #1
#define SENSOR2PORT                     11      // user sensor #2
#define SENSOR3PORT                     12      // user sensor #3

// Cayenne LPP Ports, see https://community.mydevices.com/t/cayenne-lpp-2-0/7510
#define CAYENNE_LPP1                    1       // dynamic sensor payload (LPP 1.0)
#define CAYENNE_LPP2                    2       // packed sensor payload (LPP 2.0)
#define CAYENNE_GPS                     3       // full scale GPS payload
#define CAYENNE_ACTUATOR                10	    // actuator commands
#define CAYENNE_DEVICECONFIG            11	    // device period configuration
#define CAYENNE_SENSORREAD              13	    // sensor period configuration
#define CAYENNE_SENSORENABLE            14	    // sensor enable configuration

// MQTT settings, only needed if MQTT is used (#define HAS_MQTT in board hal file)
#define MQTT_ETHERNET 1 // select PHY: set 0 for Wifi, 1 for ethernet (Wifi not yet implemented!)
#define MQTT_INTOPIC "paxin"
#define MQTT_OUTTOPIC "paxout"
#define MQTT_PORT 1883
#define MQTT_SERVER "public.cloud.shiftr.io"
#define MQTT_USER "public"
#define MQTT_PASSWD "public"
#define MQTT_RETRYSEC 20  // retry reconnect every 20 seconds
#define MQTT_KEEPALIVE 10 // keep alive interval in seconds
//#define MQTT_CLIENTNAME "my_paxcounter" // generated by default

The string EU is not supported. Use your country code, e.g. DE for Germany.

IT works ?

Sure. Did you do and test the change?

Yes it’s work, you know why in the last version there isn’t the vendor filter ?

Can anyone tell me why my paxcounter detects many more blt devices than a wifi?
image

// clang-format off

// ----- Paxcounter user config file ------
//
// --> adapt to your needs and use case <--
//
// Notes:
// 1. After editing, before "build", use "clean" button in PlatformIO!
// 2. Clear NVRAM of the board to delete previous stored runtime settings (pio run -t erase)

// Device options
#define VERBOSE                         1       // set to 0 to silence the device, 1 enables additional debug output
#define BOOTMENU                        0       // 0 = no bootmenu, 1 = device brings up boot menu before starting application
#define BOOTDELAY                       30      // time [seconds] while devices waits in boot menue for input
#define BOOTTIMEOUT                     300     // time [seconds] while devices waits to finish upload a firmware file

// Payload send cycle and encoding
#define SENDCYCLE                       30      // payload send cycle [seconds/2], 0 .. 255
#define SLEEPCYCLE                      0       // sleep time after a send cycle [seconds/10], 0 .. 65535; 0 means no sleep [default = 0]
#define PAYLOAD_ENCODER                 1       // payload encoder: 1=Plain, 2=Packed, 3=Cayenne LPP dynamic, 4=Cayenne LPP packed
#define COUNTERMODE                     1       // 0=cyclic, 1=cumulative, 2=cyclic confirmed

// default settings for transmission of sensor data (first list = data on / second line = data off)
#define PAYLOADMASK                                                                             \
            ((GPS_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) & \
            (~BATT_DATA) & (~RESERVED_DATA))

// MAC sniffing parameters
#define BLECOUNTER                      1       // set to 0 if you do not want to install the BLE sniffer
#define WIFICOUNTER                     1       // set to 0 if you do not want to install the WIFI sniffer
#define VENDORFILTER                    1       

// BLE scan parameters
#define BLESCANTIME                     0       // [seconds] scan duration, 0 means infinite [default], see note below
#define BLESCANWINDOW                   80      // [milliseconds] scan window, see below, 3 .. 10240, default 80ms
#define BLESCANINTERVAL                 80      // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle

/* Note: guide for setting bluetooth parameters
*
* |< Scan Window >       |< Scan Window >       | ... |< Scan Window >       |
* |<    Scan Interval   >|<    Scan Interval   >| ... |<    Scan Interval   >|
* |<                   Scan duration                                        >|
*
* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default).
* Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL.
* Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising.
* -> Adjust these values with power consumption in mind if power is limited.
* -> Scan interval can be changed during runtime by remote comammand.
*/

// WiFi scan parameters
#define WIFI_CHANNEL_MIN                1       // start channel number where scan begings
#define	WIFI_CHANNEL_MAX                13      // total channel number to scan
#define WIFI_MY_COUNTRY                 "IT"    // select locale for Wifi RF settings
#define	WIFI_CHANNEL_SWITCH_INTERVAL    50      // [seconds/100] -> 0,5 sec.

// LoRa payload default parameters
#define MEM_LOW                         2048    // [Bytes] low memory threshold triggering a send cycle
#define RETRANSMIT_RCMD                 5       // [seconds] wait time before retransmitting rcommand results
#define PAYLOAD_BUFFER_SIZE             51      // maximum size of payload block per transmit
#define PAYLOAD_OPENSENSEBOX            0       // send payload compatible to sensebox.de (swap geo position and pax data)
#define LORADRDEFAULT                   5       // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5]
#define LORATXPOWDEFAULT                14      // 0 .. 255, LoRaWAN TX power in dBm [default = 14]
#define MAXLORARETRY                    500     // maximum count of TX retries if LoRa busy
#define SEND_QUEUE_SIZE                 10      // maximum number of messages in payload send queue [1 = no queue]

// Hardware settings
#define RGBLUMINOSITY                   30      // RGB LED luminosity [default = 30%]
#define DISPLAYREFRESH_MS               40      // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second
#define DISPLAYCONTRAST                 80      // 0 .. 255, OLED display contrast [default = 80]
#define DISPLAYCYCLE                    3       // Auto page flip delay in sec [default = 2] for devices without button
#define HOMECYCLE                       30      // house keeping cycle in seconds [default = 30 secs]

// Settings for BME680 environmental sensor
#define BME_TEMP_OFFSET                 5.0f    // Offset sensor on chip temp <-> ambient temp [default = 5°C]
#define STATE_SAVE_PERIOD               UINT32_C(360 * 60 * 1000) // update every 360 minutes = 4 times a day
#define BMECYCLE                        1       // bme sensor read cycle in seconds [default = 1 secs]

// OTA settings
#define USE_OTA                         1       // set to 0 to disable OTA update
#define WIFI_MAX_TRY                    5       // maximum number of wifi connect attempts for OTA update [default = 20]
#define OTA_MAX_TRY                     5       // maximum number of attempts for OTA download and write to flash [default = 3]
#define OTA_MIN_BATT                    50      // minimum battery level for OTA [percent]
#define RESPONSE_TIMEOUT_MS             60000   // firmware binary server connection timeout [milliseconds]

// settings for syncing time of node with a time source (network / gps / rtc / timeserver)
#define TIME_SYNC_LORAWAN               1       // set to 1 to use LORA network as time source, 0 means off [default = 1]
#define TIME_SYNC_LORASERVER            0       // set to 1 to use LORA timeserver as time source, 0 means off [default = 0]
#define TIME_SYNC_INTERVAL              60      // sync time attempt each .. minutes from time source [default = 60], 0 means off
#define TIME_SYNC_INTERVAL_RETRY        10      // retry time sync after lost sync each .. minutes [default = 10], 0 means off
#define TIME_SYNC_SAMPLES               1       // number of time requests for averaging, max. 255
#define TIME_SYNC_CYCLE                 60      // delay between two time samples [seconds]
#define TIME_SYNC_TIMEOUT               400     // timeout waiting for timeserver answer [seconds]
#define TIME_SYNC_COMPILEDATE           0       // set to 1 to use compile date to initialize RTC after power outage [default = 0]
#define TIME_SYNC_TIMEZONE              "CET-1CEST,M3.4.0/2,M10.4.0/3" // Timezone in POSIX format (example shows Germany/Berlin)

// Ports on which the device sends and listenes on LoRaWAN and SPI
#define COUNTERPORT                     1       // counts
#define MACPORT                         0       // network commands
#define RCMDPORT                        2       // remote commands
#define STATUSPORT                      2       // remote command results
#define CONFIGPORT                      3       // config query results
#define GPSPORT                         4       // gps - NOTE: set to 1 to send combined GPS+COUNTERPORT payload  
#define BUTTONPORT                      5       // button pressed signal
#define RESERVEDPORT                    6       // reserved (unused)
#define BMEPORT                         7       // BME680 sensor
#define BATTPORT                        8       // battery voltage
#define TIMEPORT                        9       // time query and response
#define SENSOR1PORT                     10      // user sensor #1
#define SENSOR2PORT                     11      // user sensor #2
#define SENSOR3PORT                     12      // user sensor #3

// Cayenne LPP Ports, see https://community.mydevices.com/t/cayenne-lpp-2-0/7510
#define CAYENNE_LPP1                    1       // dynamic sensor payload (LPP 1.0)
#define CAYENNE_LPP2                    2       // packed sensor payload (LPP 2.0)
#define CAYENNE_GPS                     3       // full scale GPS payload
#define CAYENNE_ACTUATOR                10	    // actuator commands
#define CAYENNE_DEVICECONFIG            11	    // device period configuration
#define CAYENNE_SENSORREAD              13	    // sensor period configuration
#define CAYENNE_SENSORENABLE            14	    // sensor enable configuration

// MQTT settings, only needed if MQTT is used (#define HAS_MQTT in board hal file)
#define MQTT_ETHERNET 1 // select PHY: set 0 for Wifi, 1 for ethernet (Wifi not yet implemented!)
#define MQTT_INTOPIC "paxin"
#define MQTT_OUTTOPIC "paxout"
#define MQTT_PORT 1883
#define MQTT_SERVER "public.cloud.shiftr.io"
#define MQTT_USER "public"
#define MQTT_PASSWD "public"
#define MQTT_RETRYSEC 20  // retry reconnect every 20 seconds
#define MQTT_KEEPALIVE 10 // keep alive interval in seconds
//#define MQTT_CLIENTNAME "my_paxcounter" // generated by default

This is my paxcounter.conf file.

May be wrong issue here, but I struggle long time to solve it before I found this
Forum entry here.
I try to get epoch Time of the TTN Network to
synchronize the local time node.
For now, I work with the “LMIC-NODE-DEMO” Code and Down- / Uplink work fine. After grabbing the whole Internet
I can’t find a working example for TTN3 to ask for TimeSync.
Searching the entire Internet, and found out that the PAX Sample had a working time sync function.
The PAX Demo here works fine and also get a TimeSync from the Network.

Be sure, the PAX Code here is fantastic and written in professional style.
But I can’t get it working in a simple LMIC code.
Maybe someone did have an example that only covers the time sync with the TTN
Network ? It would be very helpful for all.

Can someone explain what bytes and port in the PAX counter payload is?

I assume pax is the main data “persons approximately”, wifi the counted WiFi devices and ble the Bluetooth enabled and counted devices. But I struggle with bytes and port and could not find any doc.

      "decoded_payload": {
        "ble": 1,
        "bytes": [
          1,
          0,
          1,
          0
        ],
        "pax": 2,
        "port": 1,
        "wifi": 1
      },

Bytes is the raw payload and port the LoRaWAN port used for the uplink.

1 Like