Merge branch 'master' of https://github.com/cyberman54/ESP32-Paxcounter
This commit is contained in:
commit
d4857cfce8
39
README.md
39
README.md
@ -18,13 +18,15 @@ This can all be done with a single small and cheap ESP32 board for less than $20
|
|||||||
# Hardware
|
# Hardware
|
||||||
|
|
||||||
Currently supported IoT boards:
|
Currently supported IoT boards:
|
||||||
- Heltec LoRa-32
|
- Heltec LoRa-32 {1}
|
||||||
- TTGOv1
|
- TTGOv1 {1}
|
||||||
- TTGOv2
|
- TTGOv2 {1}
|
||||||
- Pycom LoPy
|
- Pycom LoPy {2}
|
||||||
- Pycom LoPy4
|
- Pycom LoPy4 {2}
|
||||||
- LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora)
|
- LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora) {2}{3}
|
||||||
- LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora)
|
- LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora) {2}{3}
|
||||||
|
|
||||||
|
{1} on board OLED Display supported; {2} on board RGB LED supported; {3} on board Hardware unique DEVEUI supported
|
||||||
|
|
||||||
Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).<br>
|
Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).<br>
|
||||||
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory.<br>
|
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory.<br>
|
||||||
@ -48,7 +50,13 @@ These results where metered with software version 1.2.0 during active wifi scan,
|
|||||||
|
|
||||||
Use <A HREF="https://platformio.org/">PlatformIO</A> with your preferred IDE for development and building this code.
|
Use <A HREF="https://platformio.org/">PlatformIO</A> with your preferred IDE for development and building this code.
|
||||||
|
|
||||||
Before compiling the code, create file loraconf.h in the /src directory from the template [loraconf.sample.h](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/loraconf.sample.h) and populate it with your personal APPEUI und APPKEY for the LoRaWAN network. Only OTAA join is supported, not ABP. The DEVEUI will be derived from the device's MAC adress during device startup and is shown as well on the device's display (if it has one) as on the serial console for copying it to your LoRaWAN network server settings. If you enter a DEVEUI in loraconf.h it will be used instead.
|
Before compiling the code, **create file loraconf.h in your local /src directory** using the template [loraconf.sample.h](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/loraconf.sample.h) and populate it with your personal APPEUI und APPKEY for the LoRaWAN network. If you're using popular <A HREF="https://thethingsnetwork.org">TheThingsNetwork</A> you can copy&paste the keys from TTN console or output of ttnctl.
|
||||||
|
|
||||||
|
To join the network only method OTAA is supported, not ABP. The DEVEUI for OTAA will be derived from the device's MAC adress during device startup and is shown as well on the device's display (if it has one) as on the serial console for copying it to your LoRaWAN network server settings.
|
||||||
|
|
||||||
|
If your device has a fixed DEVEUI enter this in your local loraconf.h file. During compile time this DEVEUI will be grabbed from loraconf.h and inserted in the code.
|
||||||
|
|
||||||
|
If your device has silicon **Unique ID** which is stored in serial EEPROM Microchip 24AA02E64 you don't need to change anything. The Unique ID will be read during startup and DEVEUI will be generated from it, overriding settings in loraconf.h.
|
||||||
|
|
||||||
# Uploading
|
# Uploading
|
||||||
|
|
||||||
@ -77,8 +85,8 @@ Paxcounter generates identifiers for sniffed MAC adresses and collects them temp
|
|||||||
|
|
||||||
FPort1:
|
FPort1:
|
||||||
|
|
||||||
byte 1: 16-bit Wifi counter, MSB
|
byte 1: 16-bit WiFi counter, MSB
|
||||||
byte 2: 16-bit Wifi counter, LSB
|
byte 2: 16-bit WiFi counter, LSB
|
||||||
byte 3: 16-bit BLE counter, MSB
|
byte 3: 16-bit BLE counter, MSB
|
||||||
byte 4: 16-bit BLE counter, LSB
|
byte 4: 16-bit BLE counter, LSB
|
||||||
|
|
||||||
@ -177,7 +185,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
|
|||||||
|
|
||||||
0x80 get device configuration
|
0x80 get device configuration
|
||||||
|
|
||||||
device answers with it's current configuration:
|
device answers with it's current configuration. The configuration is a C structure declared in file [globals.h](src/globals.h#L24-L41) with the following definition:
|
||||||
|
|
||||||
byte 1: Lora SF (7..12)
|
byte 1: Lora SF (7..12)
|
||||||
byte 2: Lora TXpower (2..15)
|
byte 2: Lora TXpower (2..15)
|
||||||
@ -203,6 +211,15 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
|
|||||||
|
|
||||||
bytes 1-3: chip temperature in celsius (little endian format)
|
bytes 1-3: chip temperature in celsius (little endian format)
|
||||||
|
|
||||||
|
# RGB Led color description
|
||||||
|
|
||||||
|
Description of the RGB LED color (LoPy/LoPy4 and Lolin32 only):
|
||||||
|
|
||||||
|
- Yellow quick blink: joining LoRaWAN network in progress or pending
|
||||||
|
- Blue blink: LoRaWAN data transmit (including waiting for receive windows) in progress or pending
|
||||||
|
- Green each blink: seen a new Wifi device
|
||||||
|
- Magenta each blink: seen a new BLE device
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
Copyright 2018 Oliver Brandmueller <ob@sysadm.in>
|
Copyright 2018 Oliver Brandmueller <ob@sysadm.in>
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
; ---> SELECT TARGET PLATFORM HERE! <---
|
; ---> SELECT TARGET PLATFORM HERE! <---
|
||||||
[platformio]
|
[platformio]
|
||||||
;env_default = heltec_wifi_lora_32
|
env_default = heltec_wifi_lora_32
|
||||||
;env_default = ttgov1
|
;env_default = ttgov1
|
||||||
env_default = ttgov2
|
;env_default = ttgov2
|
||||||
;env_default = lopy
|
;env_default = lopy
|
||||||
;env_default = lopy4
|
;env_default = lopy4
|
||||||
;env_default = lolin32lite_lora
|
;env_default = lolin32lite_lora
|
||||||
@ -29,13 +29,15 @@ lib_deps =
|
|||||||
ESP32 BLE Arduino@>=0.4.9
|
ESP32 BLE Arduino@>=0.4.9
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
|
-Dheltec_wifi_lora_32
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/heltec.h"
|
-include "src/hal/heltec.h"
|
||||||
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
||||||
@ -46,17 +48,22 @@ platform = espressif32
|
|||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_baud = 115200
|
monitor_baud = 115200
|
||||||
|
; On my V1, upload does not works over default 115200
|
||||||
|
upload_speed = 921600
|
||||||
|
;upload_port = COM15
|
||||||
lib_deps =
|
lib_deps =
|
||||||
U8g2
|
U8g2
|
||||||
ESP32 BLE Arduino@>=0.4.9
|
ESP32 BLE Arduino@>=0.4.9
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
|
-Dttgov1
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/ttgov1.h"
|
-include "src/hal/ttgov1.h"
|
||||||
@ -75,14 +82,15 @@ lib_deps =
|
|||||||
ESP32 BLE Arduino@>=0.4.9
|
ESP32 BLE Arduino@>=0.4.9
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
|
-Dttgov2
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/ttgov2.h"
|
-include "src/hal/ttgov2.h"
|
||||||
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
||||||
@ -93,18 +101,21 @@ platform = espressif32
|
|||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_baud = 115200
|
monitor_baud = 115200
|
||||||
|
upload_speed = 921600
|
||||||
lib_deps =
|
lib_deps =
|
||||||
U8g2@>2.21.7
|
U8g2@>2.21.7
|
||||||
ESP32 BLE Arduino@>=0.4.9
|
ESP32 BLE Arduino@>=0.4.9
|
||||||
SmartLeds
|
SmartLeds
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
|
-Dlopy
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/lopy.h"
|
-include "src/hal/lopy.h"
|
||||||
@ -116,19 +127,22 @@ platform = espressif32
|
|||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_baud = 115200
|
monitor_baud = 115200
|
||||||
|
upload_speed = 921600
|
||||||
lib_deps =
|
lib_deps =
|
||||||
U8g2@>2.21.7
|
U8g2@>2.21.7
|
||||||
ESP32 BLE Arduino@>=0.4.9
|
ESP32 BLE Arduino@>=0.4.9
|
||||||
SmartLeds
|
SmartLeds
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
|
-Dlopy4
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/lopy4.h"
|
-include "src/hal/lopy4.h"
|
||||||
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
||||||
@ -146,13 +160,15 @@ lib_deps =
|
|||||||
SmartLeds
|
SmartLeds
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
|
-Dlolin32lite_lora
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/lolin32lite_lora.h"
|
-include "src/hal/lolin32lite_lora.h"
|
||||||
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
||||||
@ -170,13 +186,15 @@ lib_deps =
|
|||||||
SmartLeds
|
SmartLeds
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
|
||||||
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
|
||||||
;needed for ESP32 BLE Ardunio v0.4.9
|
;needed for ESP32 BLE Ardunio v0.4.9
|
||||||
-fexceptions
|
-fexceptions
|
||||||
-std=c++11
|
-std=c++11
|
||||||
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
;override lora settings from LMiC library in lmic/config.h and use main.h instead
|
||||||
-D_lmic_config_h_
|
-D_lmic_config_h_
|
||||||
|
-Dlolin32_lora
|
||||||
-include "src/main.h"
|
-include "src/main.h"
|
||||||
-include "src/hal/lolin32_lora.h"
|
-include "src/hal/lolin32_lora.h"
|
||||||
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* configmanager persists runtime configuration using NVRAM of ESP32*/
|
/* configmanager persists runtime configuration using NVRAM of ESP32*/
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include <nvs.h>
|
#include <nvs.h>
|
||||||
#include <nvs_flash.h>
|
#include <nvs_flash.h>
|
||||||
|
@ -13,9 +13,11 @@
|
|||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
|
|
||||||
|
// LED controls
|
||||||
#ifdef HAS_RGB_LED
|
#ifdef HAS_RGB_LED
|
||||||
#include <SmartLeds.h>
|
#include <SmartLeds.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rgb_led.h"
|
#include "rgb_led.h"
|
||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ extern configData_t cfg;
|
|||||||
extern uint8_t mydata[];
|
extern uint8_t mydata[];
|
||||||
extern uint64_t uptimecounter;
|
extern uint64_t uptimecounter;
|
||||||
extern osjob_t sendjob;
|
extern osjob_t sendjob;
|
||||||
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim, salt;
|
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||||
extern bool joinstate;
|
extern bool joinstate;
|
||||||
extern std::set<uint16_t> wifis;
|
extern std::set<uint16_t> wifis;
|
||||||
extern std::set<uint16_t> macs;
|
extern std::set<uint16_t> macs;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||||
|
//#define DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||||
#define HAS_LED GPIO_NUM_25 // white LED on board
|
#define HAS_LED GPIO_NUM_25 // white LED on board
|
||||||
#define HAS_BUTTON GPIO_NUM_0 // button "PROG" on board
|
#define HAS_BUTTON GPIO_NUM_0 // button "PROG" on board
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||||
#define HAS_LED NOT_A_PIN // Led os on same pin than Lora SS pin, to avoid pb, we don't use it
|
//#define DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||||
|
#define HAS_LED NOT_A_PIN // Led os on same pin as Lora SS pin, to avoid problems, we don't use it
|
||||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||||
// Anyway shield is on over the LoLin32 board, so we won't be able to see this LED
|
// Anyway shield is on over the LoLin32 board, so we won't be able to see this LED
|
||||||
#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
||||||
@ -31,3 +32,7 @@
|
|||||||
#define OLED_RST U8X8_PIN_NONE // Not reset pin
|
#define OLED_RST U8X8_PIN_NONE // Not reset pin
|
||||||
#define OLED_SDA 21 // ESP32 GPIO21 (Pin21) -- OLED SDA
|
#define OLED_SDA 21 // ESP32 GPIO21 (Pin21) -- OLED SDA
|
||||||
#define OLED_SCL 22 // ESP32 GPIO22 (Pin22) -- OLED SCL
|
#define OLED_SCL 22 // ESP32 GPIO22 (Pin22) -- OLED SCL
|
||||||
|
|
||||||
|
// I2C config for Microchip 24AA02E64 DEVEUI unique address
|
||||||
|
#define MCP_24AA02E64_I2C_ADDRESS 0x50 // I2C address for the 24AA02E64
|
||||||
|
#define MCP_24AA02E64_MAC_ADDRESS 0xF8 // Memory adress of unique deveui 64 bits
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||||
|
//#define DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||||
#define HAS_LED 22 // ESP32 GPIO12 (pin22) On Board LED
|
#define HAS_LED 22 // ESP32 GPIO12 (pin22) On Board LED
|
||||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||||
#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
||||||
@ -30,3 +31,7 @@
|
|||||||
#define OLED_RST U8X8_PIN_NONE // Not reset pin
|
#define OLED_RST U8X8_PIN_NONE // Not reset pin
|
||||||
#define OLED_SDA 14 // ESP32 GPIO14 (Pin14) -- OLED SDA
|
#define OLED_SDA 14 // ESP32 GPIO14 (Pin14) -- OLED SDA
|
||||||
#define OLED_SCL 12 // ESP32 GPIO12 (Pin12) -- OLED SCL
|
#define OLED_SCL 12 // ESP32 GPIO12 (Pin12) -- OLED SCL
|
||||||
|
|
||||||
|
// I2C config for Microchip 24AA02E64 DEVEUI unique address
|
||||||
|
#define MCP_24AA02E64_I2C_ADDRESS 0x50 // I2C address for the 24AA02E64
|
||||||
|
#define MCP_24AA02E64_MAC_ADDRESS 0xF8 // Memory adress of unique deveui 64 bits
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// Hardware related definitions for Pycom LoPy Board (not: LoPy4)
|
// Hardware related definitions for Pycom LoPy Board (not: LoPy4)
|
||||||
|
|
||||||
#define CFG_sx1272_radio 1
|
#define CFG_sx1272_radio 1
|
||||||
#define HAS_RGB_LED 0 // WS2812B RGB LED
|
#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4
|
||||||
|
#define HAS_RGB_LED 0 // WS2812B RGB LED on GPIO0
|
||||||
|
|
||||||
// Hardware pin definitions for Pycom LoPy board
|
// Hardware pin definitions for Pycom LoPy board
|
||||||
#define PIN_SPI_SS 17
|
#define PIN_SPI_SS 17
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// Hardware related definitions for Pycom LoPy Board (not: LoPy4)
|
// Hardware related definitions for Pycom LoPy Board (not: LoPy4)
|
||||||
|
|
||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
#define HAS_RGB_LED 0 // WS2812B RGB LED
|
#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4
|
||||||
|
#define HAS_RGB_LED 0 // WS2812B RGB LED on GPIO0
|
||||||
|
|
||||||
// Hardware pin definitions for Pycom LoPy4 board
|
// Hardware pin definitions for Pycom LoPy4 board
|
||||||
#define PIN_SPI_SS 18
|
#define PIN_SPI_SS 18
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||||
|
//#define DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||||
#define HAS_LED GPIO_NUM_2 // white LED on board
|
#define HAS_LED GPIO_NUM_2 // white LED on board
|
||||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||||
#define HAS_BUTTON GPIO_NUM_0 // button "PRG" on board
|
#define HAS_BUTTON GPIO_NUM_0 // button "PRG" on board
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
||||||
|
//#define DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||||
#define HAS_LED NOT_A_PIN // on-board LED is wired to SCL (used by display) therefore totally useless
|
#define HAS_LED NOT_A_PIN // on-board LED is wired to SCL (used by display) therefore totally useless
|
||||||
|
|
||||||
// disable brownout detection (needed on TTGOv2 for battery powered operation)
|
// disable brownout detection (needed on TTGOv2 for battery powered operation)
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
// Set your DEVEUI here, if you have one. You can leave this untouched,
|
// Set your DEVEUI here, if you have one. You can leave this untouched,
|
||||||
// then the DEVEUI will be generated during runtime from device's MAC adress
|
// then the DEVEUI will be generated during runtime from device's MAC adress
|
||||||
// Note: Use same format as in TTN console (cut & paste, for your convenience)
|
// Note: Use same format as in TTN console (cut & paste, for your convenience)
|
||||||
|
// *** Take care : If Using a board with Microchip 24AA02E64 Uinique ID for deveui, **
|
||||||
|
// *** this DEVEUI will be overwriten 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 DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
// Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience)
|
// Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience)
|
||||||
|
162
src/lorawan.cpp
162
src/lorawan.cpp
@ -1,5 +1,4 @@
|
|||||||
// Basic Config
|
// Basic Config
|
||||||
#include "main.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
// LMIC-Arduino LoRaWAN Stack
|
// LMIC-Arduino LoRaWAN Stack
|
||||||
@ -7,7 +6,9 @@
|
|||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
|
|
||||||
uint8_t mydata[] = "0000";
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
|
#include <Wire.h> // Needed for 24AA02E64, does not hurt anything if included and not used
|
||||||
|
#endif
|
||||||
|
|
||||||
// Local logging Tag
|
// Local logging Tag
|
||||||
static const char *TAG = "lorawan";
|
static const char *TAG = "lorawan";
|
||||||
@ -46,6 +47,37 @@ void RevBytes(unsigned char* b, size_t c)
|
|||||||
b[c - 1 - i] = t; }
|
b[c - 1 - i] = t; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_hard_deveui(uint8_t *pdeveui) {
|
||||||
|
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
|
||||||
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
|
uint8_t i2c_ret;
|
||||||
|
// Init this just in case, no more to 100KHz
|
||||||
|
Wire.begin(OLED_SDA, OLED_SCL, 100000);
|
||||||
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
|
i2c_ret = Wire.endTransmission();
|
||||||
|
// check if device seen on i2c bus
|
||||||
|
if (i2c_ret == 0) {
|
||||||
|
char deveui[32]="";
|
||||||
|
uint8_t data;
|
||||||
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
|
Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8);
|
||||||
|
while (Wire.available()) {
|
||||||
|
data = Wire.read();
|
||||||
|
sprintf(deveui+strlen(deveui), "%02X ", data) ;
|
||||||
|
*pdeveui++ = data;
|
||||||
|
}
|
||||||
|
i2c_ret = Wire.endTransmission();
|
||||||
|
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret);
|
||||||
|
}
|
||||||
|
// Set back to 400KHz to speed up OLED
|
||||||
|
Wire.setClock(400000);
|
||||||
|
#endif // MCP 24AA02E64
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
|
|
||||||
// Display a key
|
// Display a key
|
||||||
@ -79,9 +111,10 @@ void printKeys(void) {
|
|||||||
#endif // VERBOSE
|
#endif // VERBOSE
|
||||||
|
|
||||||
void do_send(osjob_t* j){
|
void do_send(osjob_t* j){
|
||||||
|
uint8_t mydata[4];
|
||||||
uint16_t data;
|
uint16_t data;
|
||||||
// Total BLE+WIFI unique MACs seen
|
// Sum of unique WIFI MACs seen
|
||||||
data = (uint16_t) macs.size();
|
data = (uint16_t) wifis.size();
|
||||||
mydata[0] = (data & 0xff00) >> 8;
|
mydata[0] = (data & 0xff00) >> 8;
|
||||||
mydata[1] = data & 0xff;
|
mydata[1] = data & 0xff;
|
||||||
|
|
||||||
@ -90,59 +123,47 @@ void do_send(osjob_t* j){
|
|||||||
mydata[2] = (data & 0xff00) >> 8;
|
mydata[2] = (data & 0xff00) >> 8;
|
||||||
mydata[3] = data & 0xff;
|
mydata[3] = data & 0xff;
|
||||||
|
|
||||||
// Sum of unique WIFI MACs seen
|
// Total BLE+WIFI unique MACs seen
|
||||||
// TBD ?
|
// TBD ?
|
||||||
//data = (uint16_t) wifis.size();
|
//data = (uint16_t) macs.size();
|
||||||
//mydata[4] = (data & 0xff00) >> 8;
|
//mydata[4] = (data & 0xff00) >> 8;
|
||||||
//mydata[5] = data & 0xff;
|
//mydata[5] = data & 0xff;
|
||||||
|
|
||||||
// Check if there is not a current TX/RX job running
|
// Check if there is not a current TX/RX job running
|
||||||
|
u8x8.clearLine(7);
|
||||||
if (LMIC.opmode & OP_TXRXPEND) {
|
if (LMIC.opmode & OP_TXRXPEND) {
|
||||||
ESP_LOGI(TAG, "OP_TXRXPEND, not sending");
|
ESP_LOGI(TAG, "OP_TXRXPEND, not sending");
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "LORA BUSY");
|
u8x8.drawString(0, 7, "LORA BUSY");
|
||||||
} else {
|
} else {
|
||||||
// Prepare upstream data transmission at the next possible time.
|
// Prepare upstream data transmission at the next possible time.
|
||||||
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02));
|
LMIC_setTxData2(1, mydata, sizeof(mydata), (cfg.countermode & 0x02));
|
||||||
ESP_LOGI(TAG, "Packet queued");
|
ESP_LOGI(TAG, "Packet queued");
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "PACKET QUEUED");
|
u8x8.drawString(0, 7, "PACKET QUEUED");
|
||||||
}
|
}
|
||||||
// Next TX is scheduled after TX_COMPLETE event.
|
// Next TX is scheduled after TX_COMPLETE event.
|
||||||
}
|
}
|
||||||
|
|
||||||
void onEvent (ev_t ev) {
|
void onEvent (ev_t ev) {
|
||||||
|
char buff[24]="";
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case EV_SCAN_TIMEOUT:
|
case EV_SCAN_TIMEOUT: strcpy_P(buff, PSTR("SCAN TIMEOUT")); break;
|
||||||
ESP_LOGI(TAG, "EV_SCAN_TIMEOUT");
|
case EV_BEACON_FOUND: strcpy_P(buff, PSTR("BEACON FOUND")); break;
|
||||||
u8x8.clearLine(7);
|
case EV_BEACON_MISSED: strcpy_P(buff, PSTR("BEACON MISSED")); break;
|
||||||
u8x8.drawString(0, 7, "SCAN TIMEOUT");
|
case EV_BEACON_TRACKED: strcpy_P(buff, PSTR("BEACON TRACKED")); break;
|
||||||
break;
|
case EV_JOINING: strcpy_P(buff, PSTR("JOINING")); break;
|
||||||
case EV_BEACON_FOUND:
|
case EV_LOST_TSYNC: strcpy_P(buff, PSTR("LOST TSYNC")); break;
|
||||||
ESP_LOGI(TAG, "EV_BEACON_FOUND");
|
case EV_RESET: strcpy_P(buff, PSTR("RESET")); break;
|
||||||
u8x8.clearLine(7);
|
case EV_RXCOMPLETE: strcpy_P(buff, PSTR("RX COMPLETE")); break;
|
||||||
u8x8.drawString(0, 7, "BEACON FOUND");
|
case EV_LINK_DEAD: strcpy_P(buff, PSTR("LINK DEAD")); break;
|
||||||
break;
|
case EV_LINK_ALIVE: strcpy_P(buff, PSTR("LINK ALIVE")); break;
|
||||||
case EV_BEACON_MISSED:
|
case EV_RFU1: strcpy_P(buff, PSTR("RFUI")); break;
|
||||||
ESP_LOGI(TAG, "EV_BEACON_MISSED");
|
case EV_JOIN_FAILED: strcpy_P(buff, PSTR("JOIN FAILED")); break;
|
||||||
u8x8.clearLine(7);
|
case EV_REJOIN_FAILED: strcpy_P(buff, PSTR("REJOIN FAILED")); break;
|
||||||
u8x8.drawString(0, 7, "BEACON MISSED");
|
|
||||||
break;
|
|
||||||
case EV_BEACON_TRACKED:
|
|
||||||
ESP_LOGI(TAG, "EV_BEACON_TRACKED");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "BEACON TRACKED");
|
|
||||||
break;
|
|
||||||
case EV_JOINING:
|
|
||||||
ESP_LOGI(TAG, "EV_JOINING");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "JOINING");
|
|
||||||
break;
|
|
||||||
case EV_JOINED:
|
case EV_JOINED:
|
||||||
ESP_LOGI(TAG, "EV_JOINED");
|
strcpy_P(buff, PSTR("JOINED"));
|
||||||
u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp
|
u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "JOINED");
|
|
||||||
// Disable link check validation (automatically enabled
|
// Disable link check validation (automatically enabled
|
||||||
// during join, but not supported by TTN at this time).
|
// during join, but not supported by TTN at this time).
|
||||||
LMIC_setLinkCheckMode(0);
|
LMIC_setLinkCheckMode(0);
|
||||||
@ -154,35 +175,20 @@ void onEvent (ev_t ev) {
|
|||||||
// show effective LoRa parameters after join
|
// show effective LoRa parameters after join
|
||||||
ESP_LOGI(TAG, "ADR=%i, SF=%i, TXPOWER=%i", cfg.adrmode, cfg.lorasf, cfg.txpower);
|
ESP_LOGI(TAG, "ADR=%i, SF=%i, TXPOWER=%i", cfg.adrmode, cfg.lorasf, cfg.txpower);
|
||||||
break;
|
break;
|
||||||
case EV_RFU1:
|
|
||||||
ESP_LOGI(TAG, "EV_RFU1");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "RFUI");
|
|
||||||
break;
|
|
||||||
case EV_JOIN_FAILED:
|
|
||||||
ESP_LOGI(TAG, "EV_JOIN_FAILED");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "JOIN FAILED");
|
|
||||||
break;
|
|
||||||
case EV_REJOIN_FAILED:
|
|
||||||
ESP_LOGI(TAG, "EV_REJOIN_FAILED");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "REJOIN FAILED");
|
|
||||||
break;
|
|
||||||
case EV_TXCOMPLETE:
|
case EV_TXCOMPLETE:
|
||||||
ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)");
|
ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)");
|
||||||
u8x8.clearLine(7);
|
u8x8.clearLine(7);
|
||||||
u8x8.drawString(0, 7, "TX COMPLETE");
|
|
||||||
if (LMIC.txrxFlags & TXRX_ACK) {
|
if (LMIC.txrxFlags & TXRX_ACK) {
|
||||||
ESP_LOGI(TAG, "Received ack");
|
ESP_LOGI(TAG, "Received ack");
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "RECEIVED ACK");
|
u8x8.drawString(0, 7, "RECEIVED ACK");
|
||||||
|
} else {
|
||||||
|
u8x8.drawString(0, 7, "TX COMPLETE");
|
||||||
}
|
}
|
||||||
if (LMIC.dataLen) {
|
if (LMIC.dataLen) {
|
||||||
ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen);
|
ESP_LOGI(TAG, "Received %d bytes of payload", LMIC.dataLen);
|
||||||
u8x8.clearLine(6);
|
u8x8.clearLine(6);
|
||||||
u8x8.setCursor(0, 6);
|
u8x8.setCursor(0, 6);
|
||||||
u8x8.printf("Rcvd %i bytes", LMIC.dataLen);
|
u8x8.printf("Rcvd %d bytes", LMIC.dataLen);
|
||||||
u8x8.clearLine(7);
|
u8x8.clearLine(7);
|
||||||
u8x8.setCursor(0, 7);
|
u8x8.setCursor(0, 7);
|
||||||
// LMIC.snr = SNR twos compliment [dB] * 4
|
// LMIC.snr = SNR twos compliment [dB] * 4
|
||||||
@ -200,38 +206,16 @@ void onEvent (ev_t ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EV_LOST_TSYNC:
|
default: sprintf_P(buff, PSTR("UNKNOWN EVENT %d"), ev); break;
|
||||||
ESP_LOGI(TAG, "EV_LOST_TSYNC");
|
}
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "LOST TSYNC");
|
// Log & Display if asked
|
||||||
break;
|
if (*buff) {
|
||||||
case EV_RESET:
|
ESP_LOGI(TAG, "EV_%s", buff);
|
||||||
ESP_LOGI(TAG, "EV_RESET");
|
u8x8.clearLine(7);
|
||||||
u8x8.clearLine(7);
|
u8x8.drawString(0, 7, buff);
|
||||||
u8x8.drawString(0, 7, "RESET");
|
}
|
||||||
break;
|
|
||||||
case EV_RXCOMPLETE:
|
|
||||||
// data received in ping slot
|
|
||||||
ESP_LOGI(TAG, "EV_RXCOMPLETE");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "RX COMPLETE");
|
|
||||||
break;
|
|
||||||
case EV_LINK_DEAD:
|
|
||||||
ESP_LOGI(TAG, "EV_LINK_DEAD");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "LINK DEAD");
|
|
||||||
break;
|
|
||||||
case EV_LINK_ALIVE:
|
|
||||||
ESP_LOGI(TAG, "EV_LINK_ALIVE");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.drawString(0, 7, "LINK ALIVE");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ESP_LOGI(TAG, "Unknown event");
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.setCursor(0, 7);
|
|
||||||
u8x8.printf("UNKNOWN EVENT %d", ev);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
115
src/macsniff.cpp
115
src/macsniff.cpp
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
// Basic Config
|
// Basic Config
|
||||||
#include "main.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
@ -22,20 +21,24 @@ static const char *TAG = "macsniff";
|
|||||||
static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL};
|
static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL};
|
||||||
|
|
||||||
uint16_t currentScanDevice = 0;
|
uint16_t currentScanDevice = 0;
|
||||||
|
uint16_t salt;
|
||||||
|
|
||||||
|
uint16_t salt_reset(void) {
|
||||||
|
salt = random(65536); // get new 16bit random for salting hashes
|
||||||
|
return salt;
|
||||||
|
}
|
||||||
|
|
||||||
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
||||||
|
|
||||||
char counter [6]; // uint16_t -> 2 byte -> 5 decimals + '0' terminator -> 6 chars
|
char buff[16]; // temporary buffer for printf
|
||||||
char macbuf [21]; // uint64_t -> 8 byte -> 20 decimals + '0' terminator -> 21 chars
|
|
||||||
char typebuff[8];
|
|
||||||
bool added = false;
|
bool added = false;
|
||||||
uint64_t addr2int;
|
uint32_t addr2int;
|
||||||
uint32_t vendor2int;
|
uint32_t vendor2int;
|
||||||
uint16_t hashedmac;
|
uint16_t hashedmac;
|
||||||
std::pair<std::set<uint16_t>::iterator, bool> newmac;
|
|
||||||
|
|
||||||
addr2int = ( (uint64_t)paddr[0] ) | ( (uint64_t)paddr[1] << 8 ) | ( (uint64_t)paddr[2] << 16 ) | \
|
// only last 3 MAC Address bytes are used for MAC Address Anonymization
|
||||||
( (uint64_t)paddr[3] << 24 ) | ( (uint64_t)paddr[4] << 32 ) | ( (uint64_t)paddr[5] << 40 );
|
// but since it's uint32 we take 4 bytes to avoid 1st value to be 0
|
||||||
|
addr2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[3] << 8 ) | ( (uint32_t)paddr[4] << 16 ) | ( (uint32_t)paddr[5] << 24 );
|
||||||
|
|
||||||
#ifdef VENDORFILTER
|
#ifdef VENDORFILTER
|
||||||
vendor2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[1] << 8 ) | ( (uint32_t)paddr[0] << 16 );
|
vendor2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[1] << 8 ) | ( (uint32_t)paddr[0] << 16 );
|
||||||
@ -46,27 +49,31 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
// salt and hash MAC, and if new unique one, store identifier in container and increment counter on display
|
// salt and hash MAC, and if new unique one, store identifier in container and increment counter on display
|
||||||
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
||||||
|
|
||||||
addr2int |= (uint64_t) salt << 48; // prepend 16-bit salt to 48-bit MAC
|
addr2int += (uint32_t) salt; // add 16-bit salt to pseudo MAC
|
||||||
snprintf(macbuf, 21, "%llx", addr2int); // convert unsigned 64-bit salted MAC to 16 digit hex string
|
snprintf(buff, sizeof(buff), "%08X", addr2int); // convert unsigned 32-bit salted MAC to 8 digit hex string
|
||||||
hashedmac = rokkit(macbuf, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container
|
hashedmac = rokkit(&buff[3], 5); // hash MAC last string value, use 5 chars to fit hash in uint16_t container
|
||||||
newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique
|
auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique
|
||||||
added = newmac.second; // true if hashed MAC is unique in container
|
added = newmac.second ? true:false; // true if hashed MAC is unique in container
|
||||||
|
|
||||||
|
// Insert only if it was not found on global count
|
||||||
|
if (added) {
|
||||||
if (sniff_type == MAC_SNIFF_WIFI ) {
|
if (sniff_type == MAC_SNIFF_WIFI ) {
|
||||||
newmac = wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique
|
rgb_set_color(COLOR_GREEN);
|
||||||
strcpy(typebuff, "WiFi");
|
wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique
|
||||||
} else if (sniff_type == MAC_SNIFF_BLE ) {
|
} else if (sniff_type == MAC_SNIFF_BLE ) {
|
||||||
newmac = bles.insert(hashedmac); // add hashed MAC to BLE container if new unique
|
rgb_set_color(COLOR_MAGENTA);
|
||||||
strcpy(typebuff, "BLE ");
|
bles.insert(hashedmac); // add hashed MAC to BLE container if new unique
|
||||||
|
}
|
||||||
|
// Not sure user will have time to see the LED
|
||||||
|
// TBD do light off further in the code
|
||||||
|
rgb_set_color(COLOR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (added) { // first time seen this WIFI or BLE MAC
|
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s",
|
||||||
snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value
|
sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLE ",
|
||||||
u8x8.draw2x2String(0, 0, counter); // display number on unique macs total Wifi + BLE
|
rssi, buff, hashedmac,
|
||||||
ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> counted #%05i", typebuff, rssi, hashedmac, macs.size());
|
(int) wifis.size(), (int) bles.size(),
|
||||||
} else { // already seen WIFI or BLE MAC
|
added ? "New" : "Already seen");
|
||||||
ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> already seen", typebuff, rssi, hashedmac);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef VENDORFILTER
|
#ifdef VENDORFILTER
|
||||||
} else {
|
} else {
|
||||||
@ -83,32 +90,60 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
|
|
||||||
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||||
|
int lastcount = (int) macs.size();
|
||||||
uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative();
|
uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative();
|
||||||
|
|
||||||
|
/* to be done here:
|
||||||
|
#ifdef VENDORFILTER
|
||||||
|
|
||||||
|
filter BLE devices using their advertisements to get second filter additional to vendor OUI
|
||||||
|
if vendorfiltering is on, we ...
|
||||||
|
- want to count: mobile phones and tablets
|
||||||
|
- don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines
|
||||||
|
see
|
||||||
|
https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp
|
||||||
|
|
||||||
|
http://www.libelium.com/products/meshlium/smartphone-detection/
|
||||||
|
|
||||||
|
http://dev.ti.com/tirex/content/simplelink_academy_cc2640r2sdk_1_12_01_16/modules/ble_scan_adv_basic/ble_scan_adv_basic.html
|
||||||
|
|
||||||
|
http://microchipdeveloper.com/wireless:ble-link-layer-packet-types
|
||||||
|
|
||||||
|
http://microchipdeveloper.com/wireless:ble-link-layer-address
|
||||||
|
|
||||||
|
"The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of
|
||||||
|
device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can
|
||||||
|
differentiate among pedestrians and vehicles."
|
||||||
|
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
// Current devices seen on this scan session
|
// Current devices seen on this scan session
|
||||||
currentScanDevice++;
|
currentScanDevice++;
|
||||||
mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE);
|
u8x8.setCursor(11,3);
|
||||||
u8x8.setCursor(12,3);
|
u8x8.printf("%-4d", currentScanDevice);
|
||||||
u8x8.printf("%d", currentScanDevice);
|
// add this device and show new count total if it was not previously added
|
||||||
|
if ( mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE) ) {
|
||||||
|
char buff[16];
|
||||||
|
snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
|
||||||
|
u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void BLECount() {
|
void BLECount() {
|
||||||
ESP_LOGI(TAG, "BLE scan started");
|
ESP_LOGI(TAG, "BLE scan started");
|
||||||
int blenum = 0; // Total device seen on this scan session
|
|
||||||
currentScanDevice = 0; // Set 0 seen device on this scan session
|
currentScanDevice = 0; // Set 0 seen device on this scan session
|
||||||
u8x8.clearLine(3);
|
u8x8.drawString(0,3,"Scanning->");
|
||||||
u8x8.drawString(0,3,"BLE Scan...");
|
BLEDevice::init(""); // we don't want to be seen by a name
|
||||||
BLEDevice::init(PROGNAME);
|
|
||||||
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
|
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
|
||||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
||||||
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
|
pBLEScan->setActiveScan(false); // An active scan would mean that we will wish a scan response.
|
||||||
BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime);
|
pBLEScan->setWindow(BLESCANWINDOW);
|
||||||
blenum=foundDevices.getCount();
|
pBLEScan->setInterval(BLESCANINTERVAL);
|
||||||
u8x8.clearLine(3);
|
BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime); // note: this is a blocking call
|
||||||
u8x8.setCursor(0,3);
|
int blenum=foundDevices.getCount();
|
||||||
u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum);
|
ESP_LOGI(TAG, "BLE scan done, seen %d device(s)", blenum);
|
||||||
ESP_LOGI(TAG, "BLE scan done");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -138,8 +173,8 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
|
|||||||
uint8_t *p = (uint8_t *) hdr->addr2;
|
uint8_t *p = (uint8_t *) hdr->addr2;
|
||||||
mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI) ;
|
mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI) ;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "WiFi RSSI %04d -> ignoring (limit: %i)", ppkt->rx_ctrl.rssi, cfg.rssilimit);
|
ESP_LOGI(TAG, "WiFi RSSI %d -> ignoring (limit: %d)", ppkt->rx_ctrl.rssi, cfg.rssilimit);
|
||||||
}
|
}
|
||||||
yield();
|
//yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@ typedef struct {
|
|||||||
uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */
|
uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */
|
||||||
} wifi_ieee80211_packet_t;
|
} wifi_ieee80211_packet_t;
|
||||||
|
|
||||||
|
extern uint16_t currentScanDevice;
|
||||||
|
|
||||||
|
uint16_t salt_reset(void);
|
||||||
void BLECount();
|
void BLECount();
|
||||||
void wifi_sniffer_init(void);
|
void wifi_sniffer_init(void);
|
||||||
void wifi_sniffer_set_channel(uint8_t channel);
|
void wifi_sniffer_set_channel(uint8_t channel);
|
||||||
|
92
src/main.cpp
92
src/main.cpp
@ -22,7 +22,6 @@ Refer to LICENSE.txt file in repository for more details.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Basic Config
|
// Basic Config
|
||||||
#include "main.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
// std::set for unified array functions
|
// std::set for unified array functions
|
||||||
@ -30,6 +29,7 @@ Refer to LICENSE.txt file in repository for more details.
|
|||||||
|
|
||||||
// OLED driver
|
// OLED driver
|
||||||
#include <U8x8lib.h>
|
#include <U8x8lib.h>
|
||||||
|
#include <Wire.h> // Does nothing and avoid any compilation error with I2C
|
||||||
|
|
||||||
// LMIC-Arduino LoRaWAN Stack
|
// LMIC-Arduino LoRaWAN Stack
|
||||||
#include "loraconf.h"
|
#include "loraconf.h"
|
||||||
@ -45,7 +45,7 @@ configData_t cfg; // struct holds current device configuration
|
|||||||
osjob_t sendjob, initjob; // LMIC
|
osjob_t sendjob, initjob; // LMIC
|
||||||
|
|
||||||
// Initialize global variables
|
// Initialize global variables
|
||||||
int macnum = 0, salt;
|
int macnum = 0;
|
||||||
uint64_t uptimecounter = 0;
|
uint64_t uptimecounter = 0;
|
||||||
bool joinstate = false;
|
bool joinstate = false;
|
||||||
|
|
||||||
@ -85,6 +85,8 @@ void loadConfig(void);
|
|||||||
// defined in lorawan.cpp
|
// defined in lorawan.cpp
|
||||||
void gen_lora_deveui(uint8_t * pdeveui);
|
void gen_lora_deveui(uint8_t * pdeveui);
|
||||||
void RevBytes(unsigned char* b, size_t c);
|
void RevBytes(unsigned char* b, size_t c);
|
||||||
|
void get_hard_deveui(uint8_t *pdeveui);
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
void printKeys(void);
|
void printKeys(void);
|
||||||
@ -103,14 +105,22 @@ void os_getArtEui (u1_t *buf) {
|
|||||||
void os_getDevEui (u1_t* buf) {
|
void os_getDevEui (u1_t* buf) {
|
||||||
int i=0, k=0;
|
int i=0, k=0;
|
||||||
memcpy(buf, DEVEUI, 8); // get fixed DEVEUI from loraconf.h
|
memcpy(buf, DEVEUI, 8); // get fixed DEVEUI from loraconf.h
|
||||||
for (i=0; i<8 ; i++)
|
for (i=0; i<8 ; i++) {
|
||||||
k += buf[i];
|
k += buf[i];
|
||||||
if (k)
|
}
|
||||||
|
if (k) {
|
||||||
RevBytes(buf, 8); // use fixed DEVEUI and swap bytes to LSB format
|
RevBytes(buf, 8); // use fixed DEVEUI and swap bytes to LSB format
|
||||||
else
|
} else {
|
||||||
gen_lora_deveui(buf); // generate DEVEUI from device's MAC
|
gen_lora_deveui(buf); // generate DEVEUI from device's MAC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get MCP 24AA02E64 hardware DEVEUI (override default settings if found)
|
||||||
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
|
get_hard_deveui(buf);
|
||||||
|
RevBytes(buf, 8); // swap bytes to LSB format
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// LMIC enhanced Pin mapping
|
// LMIC enhanced Pin mapping
|
||||||
const lmic_pinmap lmic_pins = {
|
const lmic_pinmap lmic_pins = {
|
||||||
.mosi = PIN_SPI_MOSI,
|
.mosi = PIN_SPI_MOSI,
|
||||||
@ -243,16 +253,17 @@ void wifi_sniffer_init(void);
|
|||||||
void wifi_sniffer_set_channel(uint8_t channel);
|
void wifi_sniffer_set_channel(uint8_t channel);
|
||||||
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
|
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
|
||||||
|
|
||||||
//WiFi Sniffer Task
|
// Sniffer Task
|
||||||
void wifi_sniffer_loop(void * pvParameters) {
|
void sniffer_loop(void * pvParameters) {
|
||||||
|
|
||||||
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
||||||
uint8_t channel=0;
|
uint8_t channel=0;
|
||||||
|
char buff[16];
|
||||||
int nloop=0, lorawait=0;
|
int nloop=0, lorawait=0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
nloop++; // acutal number of wifi loops, controls cycle when data is sent
|
nloop++; // actual number of wifi loops, controls cycle when data is sent
|
||||||
|
|
||||||
vTaskDelay(cfg.wifichancycle*10 / portTICK_PERIOD_MS);
|
vTaskDelay(cfg.wifichancycle*10 / portTICK_PERIOD_MS);
|
||||||
yield();
|
yield();
|
||||||
@ -260,12 +271,22 @@ void wifi_sniffer_loop(void * pvParameters) {
|
|||||||
wifi_sniffer_set_channel(channel);
|
wifi_sniffer_set_channel(channel);
|
||||||
ESP_LOGI(TAG, "Wifi set channel %d", channel);
|
ESP_LOGI(TAG, "Wifi set channel %d", channel);
|
||||||
|
|
||||||
u8x8.setCursor(0,5);
|
snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
|
||||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE
|
||||||
u8x8.setCursor(11,5);
|
u8x8.setCursor(0,3);
|
||||||
u8x8.printf("ch:%02i", channel);
|
// We just state out of BLE scanning
|
||||||
|
if (currentScanDevice) {
|
||||||
|
u8x8.printf("BLE: %-4d %-4d", (int) bles.size(), currentScanDevice);
|
||||||
|
} else {
|
||||||
|
u8x8.printf("BLE: %-4d", (int) bles.size());
|
||||||
|
}
|
||||||
u8x8.setCursor(0,4);
|
u8x8.setCursor(0,4);
|
||||||
u8x8.printf("MAC#: %-5i", wifis.size());
|
u8x8.printf("WIFI: %-4d", (int) wifis.size());
|
||||||
|
u8x8.setCursor(11,4);
|
||||||
|
u8x8.printf("ch:%02i", channel);
|
||||||
|
u8x8.setCursor(0,5);
|
||||||
|
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit);
|
||||||
|
//u8x8.printf(" ch:%02i", channel);
|
||||||
|
|
||||||
// duration of one wifi scan loop reached? then send data and begin new scan cycle
|
// duration of one wifi scan loop reached? then send data and begin new scan cycle
|
||||||
if( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) {
|
if( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) {
|
||||||
@ -282,14 +303,16 @@ void wifi_sniffer_loop(void * pvParameters) {
|
|||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
bles.clear(); // clear BLE macs counter
|
bles.clear(); // clear BLE macs counter
|
||||||
#endif
|
#endif
|
||||||
salt = random(65536); // get new 16bit random for salting hashes
|
salt_reset(); // get new salt for salting hashes
|
||||||
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
u8x8.clearLine(0); // clear Display counter
|
||||||
|
u8x8.clearLine(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait until payload is sent, while wifi scanning and mac counting task continues
|
// wait until payload is sent, while wifi scanning and mac counting task continues
|
||||||
lorawait = 0;
|
lorawait = 0;
|
||||||
while(LMIC.opmode & OP_TXRXPEND) {
|
while(LMIC.opmode & OP_TXRXPEND) {
|
||||||
if(!lorawait) u8x8.drawString(0,6,"LoRa wait ");
|
if(!lorawait)
|
||||||
|
u8x8.drawString(0,6,"LoRa wait ");
|
||||||
lorawait++;
|
lorawait++;
|
||||||
// in case sending really fails: reset and rejoin network
|
// in case sending really fails: reset and rejoin network
|
||||||
if( (lorawait % MAXLORARETRY ) == 0) {
|
if( (lorawait % MAXLORARETRY ) == 0) {
|
||||||
@ -302,12 +325,14 @@ void wifi_sniffer_loop(void * pvParameters) {
|
|||||||
|
|
||||||
u8x8.clearLine(6);
|
u8x8.clearLine(6);
|
||||||
|
|
||||||
|
// TBD: need to check if long 2000ms pause causes stack problems while scanning continues
|
||||||
if (cfg.screenon && cfg.screensaver) {
|
if (cfg.screenon && cfg.screensaver) {
|
||||||
vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results
|
vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results
|
||||||
}
|
|
||||||
yield();
|
yield();
|
||||||
u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled
|
u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled
|
||||||
|
}
|
||||||
} // end of send data cycle
|
} // end of send data cycle
|
||||||
|
|
||||||
else {
|
else {
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
if (nloop % (WIFI_CHANNEL_MAX * cfg.blescancycle) == 0 ) // once after cfg.blescancycle Wifi scans, do a BLE scan
|
if (nloop % (WIFI_CHANNEL_MAX * cfg.blescancycle) == 0 ) // once after cfg.blescancycle Wifi scans, do a BLE scan
|
||||||
@ -364,6 +389,10 @@ void init_display(const char *Productname, const char *Version) {
|
|||||||
u8x8.setFlipMode(0);
|
u8x8.setFlipMode(0);
|
||||||
u8x8.clear();
|
u8x8.clear();
|
||||||
|
|
||||||
|
#ifdef DISPLAY_FLIP
|
||||||
|
u8x8.setFlipMode(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Display chip information
|
// Display chip information
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
esp_chip_info_t chip_info;
|
esp_chip_info_t chip_info;
|
||||||
@ -394,7 +423,7 @@ void setup() {
|
|||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
#ifdef DISABLE_BROWNOUT
|
#ifdef DISABLE_BROWNOUT
|
||||||
// Register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
// register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
||||||
(*((volatile uint32_t *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE+0xd4)))) = 0;
|
(*((volatile uint32_t *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE+0xd4)))) = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -411,10 +440,10 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
|
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
|
||||||
rgb_set_color(COLOR_NONE);
|
rgb_set_color(COLOR_NONE);
|
||||||
|
|
||||||
// system event handler for wifi task, needed for wifi_sniffer_init()
|
// initialize system event handler for wifi task, needed for wifi_sniffer_init()
|
||||||
esp_event_loop_init(NULL, NULL);
|
esp_event_loop_init(NULL, NULL);
|
||||||
|
|
||||||
// Print chip information on startup
|
// print chip information on startup if in verbose mode
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
esp_chip_info_t chip_info;
|
esp_chip_info_t chip_info;
|
||||||
esp_chip_info(&chip_info);
|
esp_chip_info(&chip_info);
|
||||||
@ -427,16 +456,16 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion());
|
ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Read settings from NVRAM
|
// read settings from NVRAM
|
||||||
loadConfig(); // includes initialize if necessary
|
loadConfig(); // includes initialize if necessary
|
||||||
|
|
||||||
// initialize hardware
|
// initialize led if needed
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
// initialize LED
|
|
||||||
pinMode(HAS_LED, OUTPUT);
|
pinMode(HAS_LED, OUTPUT);
|
||||||
digitalWrite(HAS_LED, LOW);
|
digitalWrite(HAS_LED, LOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// initialize button handling if needed
|
||||||
#ifdef HAS_BUTTON
|
#ifdef HAS_BUTTON
|
||||||
#ifdef BUTTON_PULLUP
|
#ifdef BUTTON_PULLUP
|
||||||
// install button interrupt (pullup mode)
|
// install button interrupt (pullup mode)
|
||||||
@ -449,30 +478,31 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize wifi antenna
|
// initialize wifi antenna if needed
|
||||||
#ifdef HAS_ANTENNA_SWITCH
|
#ifdef HAS_ANTENNA_SWITCH
|
||||||
antenna_init();
|
antenna_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize salt value using esp_random() called by random() in arduino-esp32 core
|
|
||||||
salt = random(65536); // get new 16bit random for salting hashes
|
|
||||||
|
|
||||||
// initialize display
|
// initialize display
|
||||||
init_display(PROGNAME, PROGVERSION);
|
init_display(PROGNAME, PROGVERSION);
|
||||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||||
u8x8.setCursor(0,5);
|
u8x8.setCursor(0,5);
|
||||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %d", cfg.rssilimit);
|
||||||
u8x8.drawString(0,6,"Join Wait ");
|
u8x8.drawString(0,6,"Join Wait ");
|
||||||
|
|
||||||
// output LoRaWAN keys to console
|
// output LoRaWAN keys to console
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printKeys();
|
printKeys();
|
||||||
#endif // VERBOSE
|
#endif
|
||||||
|
|
||||||
os_init(); // setup LMIC
|
os_init(); // setup LMIC
|
||||||
os_setCallback(&initjob, lora_init); // setup initial job & join network
|
os_setCallback(&initjob, lora_init); // setup initial job & join network
|
||||||
wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting
|
wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting
|
||||||
|
|
||||||
|
// initialize salt value using esp_random() called by random() in arduino-esp32 core
|
||||||
|
// note: do this *after* wifi has started, since gets it's seed from RF noise
|
||||||
|
salt_reset(); // get new 16bit for salting hashes
|
||||||
|
|
||||||
// Start FreeRTOS tasks
|
// Start FreeRTOS tasks
|
||||||
#if CONFIG_FREERTOS_UNICORE // run all tasks on core 0 and switch off core 1
|
#if CONFIG_FREERTOS_UNICORE // run all tasks on core 0 and switch off core 1
|
||||||
ESP_LOGI(TAG, "Starting Lora task on core 0");
|
ESP_LOGI(TAG, "Starting Lora task on core 0");
|
||||||
@ -484,10 +514,10 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
||||||
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
|
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
|
||||||
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
||||||
xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0);
|
xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Kickoff first sendjob, use payload "0000"
|
// Finally: kickoff first sendjob and join, then send initial payload "0000"
|
||||||
uint8_t mydata[] = "0000";
|
uint8_t mydata[] = "0000";
|
||||||
do_send(&sendjob);
|
do_send(&sendjob);
|
||||||
}
|
}
|
||||||
|
34
src/main.h
34
src/main.h
@ -1,35 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
// program version - note: increment version after modifications to configData_t struct!!
|
// program version - note: increment version after modifications to configData_t struct!!
|
||||||
#define PROGVERSION "1.2.88" // use max 10 chars here!
|
#define PROGVERSION "1.2.95" // use max 10 chars here!
|
||||||
#define PROGNAME "PAXCNT"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
// Verbose enables serial output
|
// Verbose enables serial output
|
||||||
//#define VERBOSE 1 // comment out to silence the device, for mute use build option
|
#define VERBOSE 1 // comment out to silence the device, for mute use build option
|
||||||
|
|
||||||
// set this to include BLE counting and vendor filter functions
|
// set this to include BLE counting and vendor filter functions
|
||||||
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
||||||
#define BLECOUNTER 1 // comment out if you don't want BLE count
|
#define BLECOUNTER 1 // comment out if you don't want BLE count
|
||||||
|
|
||||||
// BLE scan time
|
// BLE scan parameters
|
||||||
#define BLESCANTIME 15 // [seconds]
|
|
||||||
#define BLESCANCYCLE 2 // BLE scan once after each <BLECYCLE> wifi scans
|
#define BLESCANCYCLE 2 // BLE scan once after each <BLECYCLE> wifi scans
|
||||||
|
#define BLESCANTIME 11 // [seconds] scan duration, see note below
|
||||||
|
#define BLESCANWINDOW 10 // [milliseconds] scan window, see below, 3 .. 10240, default 10
|
||||||
|
#define BLESCANINTERVAL 10 // [milliseconds] how long to wait between scans, 3 .. 10240, default 10
|
||||||
|
|
||||||
// WiFi Sniffer cycle interval
|
/* Note: guide for setting bluetooth parameters
|
||||||
#define SEND_SECS 120 // [seconds/2] -> 240 sec.
|
*
|
||||||
//#define SEND_SECS 30 // [seconds/2] -> 60 sec.
|
* |< Scan Window > |< Scan Window > |< Scan Window > |
|
||||||
|
* |< Scan Interval >|< Scan Interval >|< Scan Interval >|
|
||||||
|
* |< Scan duration >|
|
||||||
|
*
|
||||||
|
* Scan duration sets how long scanning should be going on, interrupting a wifi scan cycle.
|
||||||
|
* Scan window sets how much of the interval should be occupied by scanning.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
// WiFi sniffer config
|
// WiFi scan parameters
|
||||||
#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings
|
#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings
|
||||||
#define WIFI_CHANNEL_MAX 13 // total channel number to scan
|
#define WIFI_CHANNEL_MAX 13 // total channel number to scan
|
||||||
#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings
|
#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings
|
||||||
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
|
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
|
||||||
|
|
||||||
|
// LoRa payload send cycle
|
||||||
|
#define SEND_SECS 120 // [seconds/2] -> 240 sec.
|
||||||
|
//#define SEND_SECS 30 // [seconds/2] -> 60 sec.
|
||||||
|
|
||||||
// Default LoRa Spreadfactor
|
// Default LoRa Spreadfactor
|
||||||
#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs
|
#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs
|
||||||
#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy
|
#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy
|
||||||
#define RCMDPORT 2 // LoRaWAN Port on which device listenes for remote commands
|
#define RCMDPORT 2 // LoRaWAN Port on which device listenes for remote commands
|
||||||
|
|
||||||
// Default RGB LED luminosity (in %)
|
// Default RGB LED luminosity (in %)
|
||||||
#define RGBLUMINOSITY 50 // 50%
|
#define RGBLUMINOSITY 30 // 30%
|
||||||
|
|
||||||
// LMIC settings
|
// LMIC settings
|
||||||
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored
|
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// checks commands and executes each command with 1 argument per command
|
// checks commands and executes each command with 1 argument per command
|
||||||
|
|
||||||
// Basic Config
|
// Basic Config
|
||||||
#include "main.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
// LMIC-Arduino LoRaWAN Stack
|
// LMIC-Arduino LoRaWAN Stack
|
||||||
@ -70,7 +69,7 @@ void set_reset(int val) {
|
|||||||
macs.clear(); // clear all macs container
|
macs.clear(); // clear all macs container
|
||||||
wifis.clear(); // clear Wifi macs container
|
wifis.clear(); // clear Wifi macs container
|
||||||
bles.clear(); // clear BLE macs container
|
bles.clear(); // clear BLE macs container
|
||||||
salt = random(65536); // get new 16bit random for salting hashes
|
salt_reset(); // get new 16bit salt
|
||||||
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
||||||
u8x8.clearLine(5);
|
u8x8.clearLine(5);
|
||||||
u8x8.setCursor(0, 5);
|
u8x8.setCursor(0, 5);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// Basic Config
|
// Basic Config
|
||||||
#include "main.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#ifdef HAS_RGB_LED
|
#ifdef HAS_RGB_LED
|
||||||
|
Loading…
Reference in New Issue
Block a user