Merge pull request #25 from cyberman54/test

v1.2.9: pull request #21 + some minor fixes
This commit is contained in:
Verkehrsrot 2018-04-03 18:24:45 +02:00 committed by GitHub
commit 95759577db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 88 additions and 36 deletions

View File

@ -98,7 +98,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
1 ... 255 used for wifi scan radius (greater values increase wifi scan radius, values 50...110 make sense) 1 ... 255 used for wifi scan radius (greater values increase wifi scan radius, values 50...110 make sense)
0 = Wifi rssi limiter disabled [default] 0 = Wifi rssi limiter disabled [default]
0x02 set counter mode 0x02 set counter mode
0 = cyclic unconfirmed, mac counter reset after each wifi scan cycle, data is sent only once [default] 0 = cyclic unconfirmed, mac counter reset after each wifi scan cycle, data is sent only once [default]
@ -177,7 +177,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#L23-L38) 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)
@ -202,7 +202,18 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
0x82 get device cpu temperature 0x82 get device cpu temperature
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 and Lolin32 only):
- Yellow quick blink
- LoRaWAN join
- Blue blink
- LoRaWAN transmit (including receive windows)
- Magenta each blink
- BLE Scan, seen a device (new or not)
# License # License
Copyright 2018 Oliver Brandmueller <ob@sysadm.in> Copyright 2018 Oliver Brandmueller <ob@sysadm.in>

View File

@ -10,10 +10,10 @@
; ---> 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
;env_default = lolin32_lora ;env_default = lolin32_lora

View File

@ -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"

View File

@ -31,3 +31,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

View File

@ -30,3 +30,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

View File

@ -85,11 +85,14 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) { void onResult(BLEAdvertisedDevice advertisedDevice) {
uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative(); uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative();
rgb_set_color(COLOR_MAGENTA);
// Current devices seen on this scan session // Current devices seen on this scan session
currentScanDevice++; currentScanDevice++;
mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE);
u8x8.setCursor(12,3); u8x8.setCursor(12,3);
u8x8.printf("%d", currentScanDevice); u8x8.printf("%d", currentScanDevice);
rgb_set_color(COLOR_NONE);
} }
}; };

View File

@ -29,7 +29,7 @@ Refer to LICENSE.txt file in repository for more details.
#include <set> #include <set>
// OLED driver // OLED driver
#include <U8x8lib.h> #include <U8x8lib.h> // includes <wire.h> if needed for other on board i2c components
// LMIC-Arduino LoRaWAN Stack // LMIC-Arduino LoRaWAN Stack
#include "loraconf.h" #include "loraconf.h"
@ -259,7 +259,6 @@ void wifi_sniffer_loop(void * pvParameters) {
channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX
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); u8x8.setCursor(0,5);
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
u8x8.setCursor(11,5); u8x8.setCursor(11,5);
@ -283,13 +282,14 @@ void wifi_sniffer_loop(void * pvParameters) {
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 = random(65536); // get new 16bit random for salting hashes
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
} }
// 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) {
@ -303,11 +303,12 @@ void wifi_sniffer_loop(void * pvParameters) {
u8x8.clearLine(6); u8x8.clearLine(6);
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
@ -345,6 +346,8 @@ void init_display(const char *Productname, const char *Version) {
u8x8.begin(); u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r); u8x8.setFont(u8x8_font_chroma48medium8_r);
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
uint8_t buf[32]; uint8_t buf[32];
u8x8.clear(); u8x8.clear();
u8x8.setFlipMode(0); u8x8.setFlipMode(0);
@ -392,9 +395,9 @@ void init_display(const char *Productname, const char *Version) {
void setup() { 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 +414,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 +430,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,31 +452,56 @@ 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 // read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
salt = random(65536); // get new 16bit random for salting hashes #ifdef MCP_24AA02E64_I2C_ADDRESS
uint8_t i2c_ret;
// Init this before OLED, we just need to get value then we're done with i2c bus
Wire.begin(OLED_SDA, OLED_SDA, 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[24];
uint8_t data;
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
while (Wire.available()) {
data = Wire.read();
sprintf(deveui+strlen(deveui), "%02X ", 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);
}
#endif // MCP 24AA02E64
// 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: %4i", 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 = random(65536); // get new 16bit random 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");
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0); xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0);
@ -487,9 +515,9 @@ void setup() {
xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); xTaskCreatePinnedToCore(wifi_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);
} }
/* end Aruino SETUP ------------------------------------------------------------ */ /* end Aruino SETUP ------------------------------------------------------------ */

View File

@ -1,5 +1,5 @@
// 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.9" // use max 10 chars here!
#define PROGNAME "PAXCNT" #define PROGNAME "PAXCNT"
// Verbose enables serial output // Verbose enables serial output
@ -10,7 +10,7 @@
#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 time
#define BLESCANTIME 15 // [seconds] #define BLESCANTIME 10 // [seconds]
#define BLESCANCYCLE 2 // BLE scan once after each <BLECYCLE> wifi scans #define BLESCANCYCLE 2 // BLE scan once after each <BLECYCLE> wifi scans
// WiFi Sniffer cycle interval // WiFi Sniffer cycle interval