cyberman54 / ESP32-Paxcounter

Wifi & BLE driven passenger flow metering with cheap ESP32 boards

Home Page:https://cyberman54.github.io/ESP32-Paxcounter/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BLE Scanner not working on v3.6.0 on TTGO LoRa

littlecxm opened this issue · comments

commented

Hi, I am on build v3.6.0 and flash it, but in my board it shown BLTH: offand I'm sure configured BLECOUNTER to 1
I also found some issue in #921, but it seems the situation is different
I'm not sure its a issue or disabled by some reason?

image

my paxcounter.conf file

// 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
#define SDLOGGING                       0       // set to 1 for system logging to SD card (if device has one)

// 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
#define SYNCWAKEUP                      300     // shifts sleep wakeup to top-of-hour, when +/- X seconds off [0=off]

// 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 settings
#define BLECOUNTER                      1       // set to 0 if you do not want to start the BLE sniffer
#define WIFICOUNTER                     1       // set to 0 if you do not want to start the WIFI sniffer
#define RSSILIMIT                       0       // 0...-128, set to 0 if you do not want to filter signals

// 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_MY_COUNTRY                 "01"    // select 2-letter locale for Wifi RF settings, e.g. "DE"; use "01" for world safe mode
#define	WIFI_CHANNEL_SWITCH_INTERVAL    50      // [seconds/100] -> 0,5 sec.
#define WIFI_CHANNEL_MAP                WIFI_CHANNEL_ALL  // possible values see libpax_api.h

// 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                         0       // 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              "CST-8" // 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

platformio.ini

; ---> SELECT ONE TARGET BOARD FROM FOLLOWING ROWS <---
;
; Note: For "LILYGO TTGO ESP32-Paxcounter LoRa32 V2.1 1.6.1" select board ttgov21new.h
; Note: For "LILYGO TTGO ESP32-Paxcounter LoRa32 V2.0 1.6.0" select board ttgov2.h and add bodge wire from LORA_IO1 to GPIO33
;
;
[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.6.0
; 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:src/build.py
otakeyfile = ota.conf
lorakeyfile = loraconf.h
lmicconfigfile = lmic_config.h
platform_espressif32 = espressif32@6.3.1
monitor_speed = 115200
upload_speed = 115200 ; set by build.py and taken from hal file
lib_deps_lora =
    mcci-catena/MCCI LoRaWAN LMIC library @ ^4.1.1
lib_deps_display =
    bitbank2/OneBitDisplay @ ^2.3.1
    bitbank2/bb_spi_lcd @ ^2.4.1
    ricmoo/QRCode @ ^0.0.1
lib_deps_ledmatrix =
    seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0
lib_deps_rgbled =
    fastled/FastLED @ ^3.6.0
lib_deps_gps =
    mikalhart/TinyGPSPlus @ ^1.0.3
lib_deps_sensors =
    adafruit/Adafruit Unified Sensor @ ^1.1.9
    adafruit/Adafruit BME280 Library @ ^2.2.2
    adafruit/Adafruit BMP085 Library @ ^1.2.2
    boschsensortec/BSEC Software Library @ 1.8.1492
    lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1
lib_deps_basic =
    greyrook/libpax @ ^1.1.0
    https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
    bblanchon/ArduinoJson @ ^6.21.2
    makuna/RTC @ 2.3.7
    mathertel/OneButton @ ^2.0.3
    lewisxhe/XPowersLib @ ^0.1.7
    256dpi/MQTT @ ^2.5.1
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_all =
    -include "src/paxcounter.conf"
    '-D CORE_DEBUG_LEVEL=${common.debug_level}'
    '-D LOG_LOCAL_LEVEL=${common.debug_level}'
    '-D PROGVERSION="${common.release_version}"'
    '-D LIBPAX_WIFI'
    '-D LIBPAX_BLE'
    '-D LIBPAX_ARDUINO'
    '-D USE_ESP_IDF_LOG'
    '-D TAG=__FILE__'
    '-U BOARD_HAS_PSRAM'

[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 =
    -include "src/hal/${board.halfile}"
    ${common.build_flags_all}
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
upload_speed = 921600
monitor_speed = 115200
; necessary for macos - adjust devicename accordingly
;upload_port = /dev/tty.usbserial-xxxxxxx
;monitor_port = /dev/tty.usbserial-xxxxxxx

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

[env:ci]
build_flags =
    -include "src/hal/${sysenv.CI_HALFILE}" ; set by CI
    ${common.build_flags_all}
upload_protocol = esptool

and build log

Processing usb (framework: arduino; board: esp32dev; platform: espressif32@6.3.1)
----------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Parsing hardware configuration from /Users/[username]/ESP32-Paxcounter/src/hal/ttgov21new.h
Parsing LMIC configuration from /Users/[username]/ESP32-Paxcounter/src/lmic_config.h
Parsing LORAWAN keys from /Users/[username]/ESP32-Paxcounter/src/loraconf.h
Parsing OTA keys from /Users/[username]/ESP32-Paxcounter/src/ota.conf
Target board: esp32dev @ 921600bps
Partition table: min_spiffs.csv
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.3.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20009.0 (2.0.9) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-mkfatfs @ 2.0.1 
 - tool-mklittlefs @ 1.203.210628 (2.3) 
 - tool-mkspiffs @ 2.230.0 (2.30) 
 - tool-openocd-esp32 @ 2.1100.20220706 (11.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 55 compatible libraries
Scanning dependencies...
Dependency Graph
|-- libpax @ 1.1.0
|-- RokkitHash @ 20151212.0.0+sha.8500494
|-- ArduinoJson @ 6.21.2
|-- RTC @ 2.3.7
|-- OneButton @ 2.0.3
|-- XPowersLib @ 0.1.7
|-- MQTT @ 2.5.1
|-- MCCI LoRaWAN LMIC library @ 4.1.1
|-- OneBitDisplay @ 2.3.1
|-- bb_spi_lcd @ 2.4.1
|-- QRCode @ 0.0.1
|-- FastLED @ 3.6.0
|-- TinyGPSPlus @ 1.0.3
|-- Adafruit Unified Sensor @ 1.1.9
|-- Adafruit BME280 Library @ 2.2.2
|-- Adafruit BMP085 Library @ 1.2.2
|-- BSEC Software Library @ 1.8.1492
|-- Nova Fitness Sds dust sensors library @ 1.5.1
|-- Ultrathin_LED_Matrix @ 1.0.0
|-- Wire @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- WebServer @ 2.0.0
|-- WiFi @ 2.0.0
|-- WiFiClientSecure @ 2.0.0
|-- Ticker @ 2.0.0
|-- Preferences @ 2.0.0
|-- BitBang_I2C @ 2.2.1
|-- SPI @ 2.0.0
|-- Ethernet @ 2.0.0
|-- BintrayClient @ 1.0.0
Building in release mode
Retrieving maximum program size .pio/build/usb/firmware_ttgov21new_v3.6.0.elf
Checking size .pio/build/usb/firmware_ttgov21new_v3.6.0.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  19.5% (used 64056 bytes from 327680 bytes)
Flash: [======    ]  58.7% (used 1155009 bytes from 1966080 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/cu.wchusbserial56570273931
Uploading .pio/build/usb/firmware_ttgov21new_v3.6.0.bin
esptool.py v4.5.1
Serial port /dev/cu.wchusbserial56570273931
Connecting....
Chip is ESP32-PICO-D4 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: [mac address]
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0012bfff...
Compressed 17488 bytes to 12168...
Writing at 0x00001000... (100 %)
Wrote 17488 bytes (12168 compressed) at 0x00001000 in 0.4 seconds (effective 343.7 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 463.1 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 655.2 kbit/s)...
Hash of data verified.
Compressed 1161296 bytes to 749261...
Writing at 0x00010000... (2 %)
Writing at 0x0001b9ff... (4 %)
Writing at 0x00027494... (6 %)
Writing at 0x0003039d... (8 %)
Writing at 0x00041282... (10 %)
Writing at 0x00046a8b... (13 %)
Writing at 0x0004b7ee... (15 %)
Writing at 0x00050893... (17 %)
Writing at 0x000561c9... (19 %)
Writing at 0x0005bb2e... (21 %)
Writing at 0x00061528... (23 %)
Writing at 0x00066c1a... (26 %)
Writing at 0x0006c7c9... (28 %)
Writing at 0x00071b63... (30 %)
Writing at 0x00076d3b... (32 %)
Writing at 0x0007c194... (34 %)
Writing at 0x0008156a... (36 %)
Writing at 0x0008684e... (39 %)
Writing at 0x0008bb81... (41 %)
Writing at 0x00090dcc... (43 %)
Writing at 0x00096067... (45 %)
Writing at 0x0009bd77... (47 %)
Writing at 0x000a1af7... (50 %)
Writing at 0x000a7eaf... (52 %)
Writing at 0x000ad9dc... (54 %)
Writing at 0x000b2c7d... (56 %)
Writing at 0x000b86bc... (58 %)
Writing at 0x000bdd6f... (60 %)
Writing at 0x000c3392... (63 %)
Writing at 0x000c85f4... (65 %)
Writing at 0x000cd9d6... (67 %)
Writing at 0x000d2ed6... (69 %)
Writing at 0x000d8503... (71 %)
Writing at 0x000ddd5e... (73 %)
Writing at 0x000e3b84... (76 %)
Writing at 0x000e95b5... (78 %)
Writing at 0x000eed75... (80 %)
Writing at 0x000f7a17... (82 %)
Writing at 0x001001b4... (84 %)
Writing at 0x00105a8e... (86 %)
Writing at 0x0010b35b... (89 %)
Writing at 0x00111197... (91 %)
Writing at 0x001166f2... (93 %)
Writing at 0x0011c64f... (95 %)
Writing at 0x00121a49... (97 %)
Writing at 0x0012730a... (100 %)
Wrote 1161296 bytes (749261 compressed) at 0x00010000 in 11.5 seconds (effective 806.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
================================================== [SUCCESS] Took 19.15 seconds ==================================================

Environment    Status    Duration
-------------  --------  ------------
usb            SUCCESS   00:00:19.155
================================================== 1 succeeded in 00:00:19.155 ==================================================
 *  Terminal will be reused by tasks, press any key to close it.

Make sure you do not have BLE disabled in NVRAM runtime parameters as a result from an earlier run by either

  • clear NVRAM (pio run -t erase), or
  • send rcommand to enable BLE and persitent save BLE state
commented

it works now after I clean the NVRAM
Thanks a lot!