Merge branch 'master' of https://github.com/hallard/ESP32-Paxcounter into test
This commit is contained in:
commit
f266da5a9f
13
README.md
13
README.md
@ -177,7 +177,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
|
||||
|
||||
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 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)
|
||||
|
||||
# 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
|
||||
|
||||
Copyright 2018 Oliver Brandmueller <ob@sysadm.in>
|
||||
|
@ -31,3 +31,7 @@
|
||||
#define OLED_RST U8X8_PIN_NONE // Not reset pin
|
||||
#define OLED_SDA 21 // ESP32 GPIO21 (Pin21) -- OLED SDA
|
||||
#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
|
||||
|
@ -30,3 +30,7 @@
|
||||
#define OLED_RST U8X8_PIN_NONE // Not reset pin
|
||||
#define OLED_SDA 14 // ESP32 GPIO14 (Pin14) -- OLED SDA
|
||||
#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
|
||||
|
@ -85,11 +85,14 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||
uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative();
|
||||
|
||||
rgb_set_color(COLOR_MAGENTA);
|
||||
// Current devices seen on this scan session
|
||||
currentScanDevice++;
|
||||
mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE);
|
||||
u8x8.setCursor(12,3);
|
||||
u8x8.printf("%d", currentScanDevice);
|
||||
rgb_set_color(COLOR_NONE);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
93
src/main.cpp
93
src/main.cpp
@ -27,6 +27,8 @@ Refer to LICENSE.txt file in repository for more details.
|
||||
|
||||
// std::set for unified array functions
|
||||
#include <set>
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
// OLED driver
|
||||
#include <U8x8lib.h>
|
||||
@ -195,8 +197,6 @@ void lorawan_loop(void * pvParameters) {
|
||||
|
||||
#ifdef HAS_DISPLAY
|
||||
HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA);
|
||||
#else
|
||||
U8X8_NULL u8x8;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_ANTENNA_SWITCH
|
||||
@ -260,16 +260,20 @@ void wifi_sniffer_loop(void * pvParameters) {
|
||||
wifi_sniffer_set_channel(channel);
|
||||
ESP_LOGI(TAG, "Wifi set channel %d", channel);
|
||||
|
||||
u8x8.setCursor(0,5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
||||
u8x8.setCursor(11,5);
|
||||
u8x8.printf("ch:%02i", channel);
|
||||
u8x8.setCursor(0,4);
|
||||
u8x8.printf("MAC#: %-5i", wifis.size());
|
||||
#ifdef HAS_DISPLAY
|
||||
u8x8.setCursor(0,5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
||||
u8x8.setCursor(11,5);
|
||||
u8x8.printf("ch:%02i", channel);
|
||||
u8x8.setCursor(0,4);
|
||||
u8x8.printf("MAC#: %-5i", wifis.size());
|
||||
#endif
|
||||
|
||||
// duration of one wifi scan loop reached? then send data and begin new scan cycle
|
||||
if( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) {
|
||||
u8x8.setPowerSave(!cfg.screenon); // set display on if enabled
|
||||
#ifdef HAS_DISPLAY
|
||||
u8x8.setPowerSave(!cfg.screenon); // set display on if enabled
|
||||
#endif
|
||||
nloop=0; channel=0; // reset wifi scan + channel loop counter
|
||||
do_send(&sendjob); // Prepare and execute LoRaWAN data upload
|
||||
vTaskDelay(500/portTICK_PERIOD_MS);
|
||||
@ -283,13 +287,19 @@ void wifi_sniffer_loop(void * pvParameters) {
|
||||
bles.clear(); // clear BLE macs counter
|
||||
#endif
|
||||
salt = random(65536); // get new 16bit random for salting hashes
|
||||
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
||||
#ifdef HAS_DISPLAY
|
||||
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
||||
#endif
|
||||
}
|
||||
|
||||
// wait until payload is sent, while wifi scanning and mac counting task continues
|
||||
lorawait = 0;
|
||||
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++;
|
||||
// in case sending really fails: reset and rejoin network
|
||||
if( (lorawait % MAXLORARETRY ) == 0) {
|
||||
@ -300,13 +310,18 @@ void wifi_sniffer_loop(void * pvParameters) {
|
||||
yield();
|
||||
}
|
||||
|
||||
u8x8.clearLine(6);
|
||||
#ifdef HAS_DISPLAY
|
||||
u8x8.clearLine(6);
|
||||
|
||||
if (cfg.screenon && cfg.screensaver) {
|
||||
vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results
|
||||
}
|
||||
yield();
|
||||
u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled
|
||||
#else
|
||||
yield();
|
||||
#endif
|
||||
|
||||
if (cfg.screenon && cfg.screensaver) {
|
||||
vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results
|
||||
}
|
||||
yield();
|
||||
u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled
|
||||
} // end of send data cycle
|
||||
else {
|
||||
#ifdef BLECOUNTER
|
||||
@ -331,6 +346,8 @@ uint64_t uptime() {
|
||||
|
||||
// Print a key on display
|
||||
void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) {
|
||||
#ifdef HAS_DISPLAY
|
||||
|
||||
uint8_t start=lsb?len:0;
|
||||
uint8_t end = lsb?0:len;
|
||||
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("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void init_display(const char *Productname, const char *Version) {
|
||||
#ifdef HAS_DISPLAY
|
||||
u8x8.begin();
|
||||
u8x8.setFont(u8x8_font_chroma48medium8_r);
|
||||
#ifdef HAS_DISPLAY
|
||||
uint8_t buf[32];
|
||||
u8x8.clear();
|
||||
u8x8.setFlipMode(0);
|
||||
@ -454,15 +472,44 @@ void setup() {
|
||||
antenna_init();
|
||||
#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
|
||||
salt = random(65536); // get new 16bit random for salting hashes
|
||||
|
||||
// initialize display
|
||||
init_display(PROGNAME, PROGVERSION);
|
||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||
u8x8.setCursor(0,5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
||||
u8x8.drawString(0,6,"Join Wait ");
|
||||
#ifdef HAS_DISPLAY
|
||||
init_display(PROGNAME, PROGVERSION);
|
||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||
u8x8.setCursor(0,5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
||||
u8x8.drawString(0,6,"Join Wait ");
|
||||
#endif
|
||||
|
||||
// output LoRaWAN keys to console
|
||||
#ifdef VERBOSE
|
||||
|
@ -10,7 +10,7 @@
|
||||
#define BLECOUNTER 1 // comment out if you don't want BLE count
|
||||
|
||||
// BLE scan time
|
||||
#define BLESCANTIME 15 // [seconds]
|
||||
#define BLESCANTIME 10 // [seconds]
|
||||
#define BLESCANCYCLE 2 // BLE scan once after each <BLECYCLE> wifi scans
|
||||
|
||||
// WiFi Sniffer cycle interval
|
||||
|
Loading…
Reference in New Issue
Block a user