This commit is contained in:
Klaus K Wilting 2018-04-03 17:05:44 +02:00
commit f266da5a9f
6 changed files with 96 additions and 27 deletions

View File

@ -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)
@ -203,6 +203,17 @@ 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 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

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

@ -27,6 +27,8 @@ Refer to LICENSE.txt file in repository for more details.
// std::set for unified array functions // std::set for unified array functions
#include <set> #include <set>
#include <Wire.h>
// OLED driver // OLED driver
#include <U8x8lib.h> #include <U8x8lib.h>
@ -195,8 +197,6 @@ void lorawan_loop(void * pvParameters) {
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA); HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA);
#else
U8X8_NULL u8x8;
#endif #endif
#ifdef HAS_ANTENNA_SWITCH #ifdef HAS_ANTENNA_SWITCH
@ -260,16 +260,20 @@ 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);
#ifdef HAS_DISPLAY
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);
u8x8.printf("ch:%02i", channel); u8x8.printf("ch:%02i", channel);
u8x8.setCursor(0,4); u8x8.setCursor(0,4);
u8x8.printf("MAC#: %-5i", wifis.size()); u8x8.printf("MAC#: %-5i", wifis.size());
#endif
// 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 ) {
#ifdef HAS_DISPLAY
u8x8.setPowerSave(!cfg.screenon); // set display on if enabled u8x8.setPowerSave(!cfg.screenon); // set display on if enabled
#endif
nloop=0; channel=0; // reset wifi scan + channel loop counter nloop=0; channel=0; // reset wifi scan + channel loop counter
do_send(&sendjob); // Prepare and execute LoRaWAN data upload do_send(&sendjob); // Prepare and execute LoRaWAN data upload
vTaskDelay(500/portTICK_PERIOD_MS); vTaskDelay(500/portTICK_PERIOD_MS);
@ -283,13 +287,19 @@ 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
#ifdef HAS_DISPLAY
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
#endif
} }
// 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 "); #ifdef HAS_DISPLAY
if(!lorawait) {
u8x8.drawString(0,6,"LoRa wait ");
}
#endif
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) {
@ -300,6 +310,7 @@ void wifi_sniffer_loop(void * pvParameters) {
yield(); yield();
} }
#ifdef HAS_DISPLAY
u8x8.clearLine(6); u8x8.clearLine(6);
if (cfg.screenon && cfg.screensaver) { if (cfg.screenon && cfg.screensaver) {
@ -307,6 +318,10 @@ void wifi_sniffer_loop(void * pvParameters) {
} }
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
#else
yield();
#endif
} // end of send data cycle } // end of send data cycle
else { else {
#ifdef BLECOUNTER #ifdef BLECOUNTER
@ -331,6 +346,8 @@ uint64_t uptime() {
// Print a key on display // Print a key on display
void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) { void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) {
#ifdef HAS_DISPLAY
uint8_t start=lsb?len:0; uint8_t start=lsb?len:0;
uint8_t end = lsb?0:len; uint8_t end = lsb?0:len;
const uint8_t * p ; const uint8_t * p ;
@ -339,12 +356,13 @@ void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) {
u8x8.printf("%02X", *p); u8x8.printf("%02X", *p);
} }
u8x8.printf("\n"); u8x8.printf("\n");
#endif
} }
void init_display(const char *Productname, const char *Version) { void init_display(const char *Productname, const char *Version) {
#ifdef HAS_DISPLAY
u8x8.begin(); u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r); u8x8.setFont(u8x8_font_chroma48medium8_r);
#ifdef HAS_DISPLAY
uint8_t buf[32]; uint8_t buf[32];
u8x8.clear(); u8x8.clear();
u8x8.setFlipMode(0); u8x8.setFlipMode(0);
@ -454,15 +472,44 @@ void setup() {
antenna_init(); antenna_init();
#endif #endif
// ======================================
// READ Microchip 24AA02E64 EEP DEVEUI
// ======================================
#ifdef MCP_24AA02E64_I2C_ADDRESS
//#if 0
uint8_t i2c_ret;
// Init this before OLED, we just need to get value then we done
Wire.begin(OLED_SDA, OLED_SDA, 100000);
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
i2c_ret = Wire.endTransmission();
// device seen
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, "24AA02E64 found DEVEUI %s", deveui);
} else {
ESP_LOGI(TAG, "24AA02E64 not found ret=%d", i2c_ret);
}
#endif // MCP 24AA02E64
// initialize salt value using esp_random() called by random() in arduino-esp32 core // initialize salt value using esp_random() called by random() in arduino-esp32 core
salt = random(65536); // get new 16bit random for salting hashes salt = random(65536); // get new 16bit random for salting hashes
// initialize display // initialize display
#ifdef HAS_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 ");
#endif
// output LoRaWAN keys to console // output LoRaWAN keys to console
#ifdef VERBOSE #ifdef VERBOSE

View File

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