From 72193b0b3a9ed1363429784f4b3cb24574a49032 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:10:46 +0200 Subject: [PATCH 01/10] 10s BLE scan time looks enough --- project.cson | 8 ++++++++ src/macsniff.cpp | 10 ++++++---- src/main.h | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 project.cson diff --git a/project.cson b/project.cson new file mode 100644 index 00000000..23b8f81a --- /dev/null +++ b/project.cson @@ -0,0 +1,8 @@ +[ + { + title: 'ESP32-Paxcounter' + settings: + 'editor.tabLength': 4 + 'editor.showInvisibles': true + } +] diff --git a/src/macsniff.cpp b/src/macsniff.cpp index d8b330a8..7d00fba9 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -33,6 +33,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { uint16_t hashedmac; std::pair::iterator, bool> newmac; + rgb_set_color(COLOR_MAGENTA); addr2int = ( (uint64_t)paddr[0] ) | ( (uint64_t)paddr[1] << 8 ) | ( (uint64_t)paddr[2] << 16 ) | \ ( (uint64_t)paddr[3] << 24 ) | ( (uint64_t)paddr[4] << 32 ) | ( (uint64_t)paddr[5] << 40 ); @@ -44,7 +45,7 @@ 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 // https://en.wikipedia.org/wiki/MAC_Address_Anonymization - + addr2int |= (uint64_t) salt << 48; // prepend 16-bit salt to 48-bit MAC snprintf(macbuf, 21, "%llx", addr2int); // convert unsigned 64-bit salted MAC to 16 digit hex string hashedmac = rokkit(macbuf, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container @@ -57,7 +58,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { newmac = bles.insert(hashedmac); // add hashed MAC to BLE container if new unique strcpy(typebuff, "BLE "); } - + if (newmac.second) { // first time seen this WIFI or BLE MAC snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, counter); @@ -73,6 +74,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { } #endif + rgb_set_color(COLOR_NONE); + // True if MAC WiFi/BLE was new return newmac.second; } @@ -129,7 +132,7 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff; const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload; const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr; - + if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value uint8_t *p = (uint8_t *) hdr->addr2; mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI) ; @@ -138,4 +141,3 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { } yield(); } - diff --git a/src/main.h b/src/main.h index 57a190b6..f9af4cc6 100644 --- a/src/main.h +++ b/src/main.h @@ -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 wifi scans // WiFi Sniffer cycle interval From 9f2a2919c55be1b5846e714b2e626f4f43f02cf0 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:11:04 +0200 Subject: [PATCH 02/10] Revert "10s BLE scan time looks enough" This reverts commit 72193b0b3a9ed1363429784f4b3cb24574a49032. --- project.cson | 8 -------- src/macsniff.cpp | 10 ++++------ src/main.h | 2 +- 3 files changed, 5 insertions(+), 15 deletions(-) delete mode 100644 project.cson diff --git a/project.cson b/project.cson deleted file mode 100644 index 23b8f81a..00000000 --- a/project.cson +++ /dev/null @@ -1,8 +0,0 @@ -[ - { - title: 'ESP32-Paxcounter' - settings: - 'editor.tabLength': 4 - 'editor.showInvisibles': true - } -] diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 7d00fba9..d8b330a8 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -33,7 +33,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { uint16_t hashedmac; std::pair::iterator, bool> newmac; - rgb_set_color(COLOR_MAGENTA); addr2int = ( (uint64_t)paddr[0] ) | ( (uint64_t)paddr[1] << 8 ) | ( (uint64_t)paddr[2] << 16 ) | \ ( (uint64_t)paddr[3] << 24 ) | ( (uint64_t)paddr[4] << 32 ) | ( (uint64_t)paddr[5] << 40 ); @@ -45,7 +44,7 @@ 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 // https://en.wikipedia.org/wiki/MAC_Address_Anonymization - + addr2int |= (uint64_t) salt << 48; // prepend 16-bit salt to 48-bit MAC snprintf(macbuf, 21, "%llx", addr2int); // convert unsigned 64-bit salted MAC to 16 digit hex string hashedmac = rokkit(macbuf, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container @@ -58,7 +57,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { newmac = bles.insert(hashedmac); // add hashed MAC to BLE container if new unique strcpy(typebuff, "BLE "); } - + if (newmac.second) { // first time seen this WIFI or BLE MAC snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, counter); @@ -74,8 +73,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { } #endif - rgb_set_color(COLOR_NONE); - // True if MAC WiFi/BLE was new return newmac.second; } @@ -132,7 +129,7 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff; const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload; const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr; - + if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value uint8_t *p = (uint8_t *) hdr->addr2; mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI) ; @@ -141,3 +138,4 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { } yield(); } + diff --git a/src/main.h b/src/main.h index f9af4cc6..57a190b6 100644 --- a/src/main.h +++ b/src/main.h @@ -10,7 +10,7 @@ #define BLECOUNTER 1 // comment out if you don't want BLE count // BLE scan time -#define BLESCANTIME 10 // [seconds] +#define BLESCANTIME 15 // [seconds] #define BLESCANCYCLE 2 // BLE scan once after each wifi scans // WiFi Sniffer cycle interval From c066a62ede9ba1adea5948654b16de6f9bf4db18 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:20:06 +0200 Subject: [PATCH 03/10] Added RGB Led doc --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0d62858..491eeedb 100644 --- a/README.md +++ b/README.md @@ -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) 0 = Wifi rssi limiter disabled [default] - + 0x02 set counter mode 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 - 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#L22-L37) with the following definition: byte 1: Lora SF (7..12) 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 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 From 3c590a2c3d74699b1a7a523470593a1e29fbd273 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:23:22 +0200 Subject: [PATCH 04/10] Link fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 491eeedb..49e701bf 100644 --- a/README.md +++ b/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. The configuration is a C structure declared in file [globals.h](src/globals.h#L22-L37) with the following definition: +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) From 6739a226c3b73b04899e90cea3cf514a918ca9b6 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:23:39 +0200 Subject: [PATCH 05/10] Blink RGB Led on BLE device seen --- src/macsniff.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index d8b330a8..fe5b80a4 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -83,11 +83,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); + } }; From 3b1baf1fc4c407ae61735365d34edca1aef66a54 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:24:06 +0200 Subject: [PATCH 06/10] BLE Scan time set to 10s --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index cb303028..80d1bb0e 100644 --- a/src/main.h +++ b/src/main.h @@ -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 wifi scans // WiFi Sniffer cycle interval From 8b4c5c1d87ae6e2ef81ab0c4211c45f1855ef70d Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 11:27:34 +0200 Subject: [PATCH 07/10] Added values for Microchip 24AA02E64 unique DEVEUI Address --- src/hal/lolin32_lora.h | 4 ++++ src/hal/lolin32lite_lora.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/hal/lolin32_lora.h b/src/hal/lolin32_lora.h index c6c44337..797c18a4 100644 --- a/src/hal/lolin32_lora.h +++ b/src/hal/lolin32_lora.h @@ -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 diff --git a/src/hal/lolin32lite_lora.h b/src/hal/lolin32lite_lora.h index c9ce785b..d631ccc0 100644 --- a/src/hal/lolin32lite_lora.h +++ b/src/hal/lolin32lite_lora.h @@ -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 From 3640a62b93b93ae9836f44b0bd564d7bb6ecce78 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 12:38:15 +0200 Subject: [PATCH 08/10] Removed all display code if not HAS_DISPLAY --- src/configmanager.cpp | 4 +- src/globals.h | 2 - src/lorawan.cpp | 136 +++++++++++++++++++++++++++--------------- src/macsniff.cpp | 24 +++++--- src/rcommand.cpp | 46 +++++++++----- 5 files changed, 137 insertions(+), 75 deletions(-) diff --git a/src/configmanager.cpp b/src/configmanager.cpp index ba39b8af..3978f55b 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -289,7 +289,9 @@ void loadConfig() { ESP_LOGI(TAG, "Done"); // put actions to be triggered on loaded config here - u8x8.setPowerSave(!cfg.screenon); // set display on/off + #ifdef HAS_DISPLAY + u8x8.setPowerSave(!cfg.screenon); // set display on/off + #endif #ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one antenna_select(cfg.wifiant); #endif diff --git a/src/globals.h b/src/globals.h index 1ef61705..9a65a3b8 100644 --- a/src/globals.h +++ b/src/globals.h @@ -49,8 +49,6 @@ extern std::set macs; #ifdef HAS_DISPLAY extern HAS_DISPLAY u8x8; -#else - extern U8X8_NULL u8x8; #endif #ifdef BLECOUNTER diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 0f0f86eb..65812d40 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -99,14 +99,18 @@ void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LORA BUSY"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LORA BUSY"); + #endif } else { // Prepare upstream data transmission at the next possible time. LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02)); ESP_LOGI(TAG, "Packet queued"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "PACKET QUEUED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "PACKET QUEUED"); + #endif } // Next TX is scheduled after TX_COMPLETE event. } @@ -115,34 +119,46 @@ void onEvent (ev_t ev) { switch(ev) { case EV_SCAN_TIMEOUT: ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "SCAN TIMEOUT"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "SCAN TIMEOUT"); + #endif break; case EV_BEACON_FOUND: ESP_LOGI(TAG, "EV_BEACON_FOUND"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON FOUND"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON FOUND"); + #endif break; case EV_BEACON_MISSED: ESP_LOGI(TAG, "EV_BEACON_MISSED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON MISSED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON MISSED"); + #endif break; case EV_BEACON_TRACKED: ESP_LOGI(TAG, "EV_BEACON_TRACKED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON TRACKED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON TRACKED"); + #endif break; case EV_JOINING: ESP_LOGI(TAG, "EV_JOINING"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINING"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOINING"); + #endif break; case EV_JOINED: ESP_LOGI(TAG, "EV_JOINED"); - u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOINED"); + #endif // Disable link check validation (automatically enabled // during join, but not supported by TTN at this time). LMIC_setLinkCheckMode(0); @@ -156,38 +172,50 @@ void onEvent (ev_t ev) { break; case EV_RFU1: ESP_LOGI(TAG, "EV_RFU1"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RFUI"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RFUI"); + #endif break; case EV_JOIN_FAILED: ESP_LOGI(TAG, "EV_JOIN_FAILED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOIN FAILED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOIN FAILED"); + #endif break; case EV_REJOIN_FAILED: ESP_LOGI(TAG, "EV_REJOIN_FAILED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "REJOIN FAILED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "REJOIN FAILED"); + #endif break; case EV_TXCOMPLETE: ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "TX COMPLETE"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "TX COMPLETE"); + #endif if (LMIC.txrxFlags & TXRX_ACK) { ESP_LOGI(TAG, "Received ack"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RECEIVED ACK"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RECEIVED ACK"); + #endif } if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); - u8x8.clearLine(6); - u8x8.setCursor(0, 6); - u8x8.printf("Rcvd %i bytes", LMIC.dataLen); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - // LMIC.snr = SNR twos compliment [dB] * 4 - // LMIC.rssi = RSSI [dBm] (-196...+63) - u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); + #ifdef HAS_DISPLAY + u8x8.clearLine(6); + u8x8.setCursor(0, 6); + u8x8.printf("Rcvd %i bytes", LMIC.dataLen); + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + // LMIC.snr = SNR twos compliment [dB] * 4 + // LMIC.rssi = RSSI [dBm] (-196...+63) + u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); + #endif // check if payload received on command port, then call remote command interpreter if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) { // caution: buffering LMIC values here because rcommand() can modify LMIC.frame @@ -202,35 +230,47 @@ void onEvent (ev_t ev) { break; case EV_LOST_TSYNC: ESP_LOGI(TAG, "EV_LOST_TSYNC"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LOST TSYNC"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LOST TSYNC"); + #endif break; case EV_RESET: ESP_LOGI(TAG, "EV_RESET"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RESET"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RESET"); + #endif break; case EV_RXCOMPLETE: // data received in ping slot ESP_LOGI(TAG, "EV_RXCOMPLETE"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RX COMPLETE"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RX COMPLETE"); + #endif break; case EV_LINK_DEAD: ESP_LOGI(TAG, "EV_LINK_DEAD"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK DEAD"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK DEAD"); + #endif break; case EV_LINK_ALIVE: ESP_LOGI(TAG, "EV_LINK_ALIVE"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK ALIVE"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK ALIVE"); + #endif break; default: ESP_LOGI(TAG, "Unknown event"); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - u8x8.printf("UNKNOWN EVENT %d", ev); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + u8x8.printf("UNKNOWN EVENT %d", ev); + #endif break; } } diff --git a/src/macsniff.cpp b/src/macsniff.cpp index fe5b80a4..e0907317 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -60,7 +60,9 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { if (newmac.second) { // first time seen this WIFI or BLE MAC snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value - u8x8.draw2x2String(0, 0, counter); + #ifdef HAS_DISPLAY + u8x8.draw2x2String(0, 0, counter); + #endif ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> #%05i", typebuff, rssi, hashedmac, macs.size()); } else { // already seen WIFI or BLE MAC ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi); @@ -87,8 +89,10 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { // Current devices seen on this scan session currentScanDevice++; mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); - u8x8.setCursor(12,3); - u8x8.printf("%d", currentScanDevice); + #ifdef HAS_DISPLAY + u8x8.setCursor(12,3); + u8x8.printf("%d", currentScanDevice); + #endif rgb_set_color(COLOR_NONE); } @@ -97,17 +101,21 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void BLECount() { int blenum = 0; // Total device seen on this scan session currentScanDevice = 0; // Set 0 seen device on this scan session - u8x8.clearLine(3); - u8x8.drawString(0,3,"BLE Scan..."); + #ifdef HAS_DISPLAY + u8x8.clearLine(3); + u8x8.drawString(0,3,"BLE Scan..."); + #endif BLEDevice::init(PROGNAME); BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime); blenum=foundDevices.getCount(); - u8x8.clearLine(3); - u8x8.setCursor(0,3); - u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); + #ifdef HAS_DISPLAY + u8x8.clearLine(3); + u8x8.setCursor(0,3); + u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); + #endif } #endif diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 09d813fc..505c41cc 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -59,9 +59,11 @@ void set_reset(int val) { switch (val) { case 0: // restart device ESP_LOGI(TAG, "Remote command: restart device"); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset pending "); + #ifdef HAS_DISPLAY + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset pending "); + #endif vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server esp_restart(); break; @@ -71,16 +73,20 @@ void set_reset(int val) { wifis.clear(); // clear Wifi macs container bles.clear(); // clear BLE macs container salt = random(65536); // get new 16bit random for salting hashes - u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset counter "); + #ifdef HAS_DISPLAY + u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset counter "); + #endif break; case 2: // reset device to factory settings ESP_LOGI(TAG, "Remote command: reset device to factory settings"); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Factory reset "); + #ifdef HAS_DISPLAY + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Factory reset "); + #endif eraseConfig(); break; } @@ -89,9 +95,11 @@ void set_reset(int val) { void set_rssi(int val) { cfg.rssilimit = val * -1; ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); + #ifdef HAS_DISPLAY + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); + #endif }; void set_wifiscancycle(int val) { @@ -137,7 +145,9 @@ void set_screensaver(int val) { case 1: cfg.screensaver = val; break; default: cfg.screensaver = 0; break; } - u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off + #ifdef HAS_DISPLAY + u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off + #endif }; void set_display(int val) { @@ -146,7 +156,9 @@ void set_display(int val) { case 1: cfg.screenon = val; break; default: cfg.screenon = 0; break; } - u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off + #ifdef HAS_DISPLAY + u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off + #endif }; void set_lorasf(int val) { @@ -170,7 +182,9 @@ void set_blescan(int val) { default: cfg.blescan = 0; btStop(); - u8x8.clearLine(3); // clear BLE results from display + #ifdef HAS_DISPLAY + u8x8.clearLine(3); // clear BLE results from display + #endif break; } }; From f4ecc3924b1422fc02e8be1ead77b04ddf313088 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 12:39:11 +0200 Subject: [PATCH 09/10] Added 24AA02E64 deveui reading Not working yet (I2C bug in ESP32 framework) --- src/main.cpp | 93 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8e7d9fad..4f062de7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,8 @@ Refer to LICENSE.txt file in repository for more details. // std::set for unified array functions #include +#include + // OLED driver #include @@ -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 + 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 + } // 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 From 47f0f90cf3b4c37454193679797953638728bbb8 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Apr 2018 16:14:57 +0200 Subject: [PATCH 10/10] Revert "Removed all display code if not HAS_DISPLAY" This reverts commit 3640a62b93b93ae9836f44b0bd564d7bb6ecce78. --- src/configmanager.cpp | 4 +- src/globals.h | 2 + src/lorawan.cpp | 136 +++++++++++++++--------------------------- src/macsniff.cpp | 24 +++----- src/rcommand.cpp | 46 +++++--------- 5 files changed, 75 insertions(+), 137 deletions(-) diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 3978f55b..ba39b8af 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -289,9 +289,7 @@ void loadConfig() { ESP_LOGI(TAG, "Done"); // put actions to be triggered on loaded config here - #ifdef HAS_DISPLAY - u8x8.setPowerSave(!cfg.screenon); // set display on/off - #endif + u8x8.setPowerSave(!cfg.screenon); // set display on/off #ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one antenna_select(cfg.wifiant); #endif diff --git a/src/globals.h b/src/globals.h index 9a65a3b8..1ef61705 100644 --- a/src/globals.h +++ b/src/globals.h @@ -49,6 +49,8 @@ extern std::set macs; #ifdef HAS_DISPLAY extern HAS_DISPLAY u8x8; +#else + extern U8X8_NULL u8x8; #endif #ifdef BLECOUNTER diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 65812d40..0f0f86eb 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -99,18 +99,14 @@ void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LORA BUSY"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LORA BUSY"); } else { // Prepare upstream data transmission at the next possible time. LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02)); ESP_LOGI(TAG, "Packet queued"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "PACKET QUEUED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "PACKET QUEUED"); } // Next TX is scheduled after TX_COMPLETE event. } @@ -119,46 +115,34 @@ void onEvent (ev_t ev) { switch(ev) { case EV_SCAN_TIMEOUT: ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "SCAN TIMEOUT"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "SCAN TIMEOUT"); break; case EV_BEACON_FOUND: ESP_LOGI(TAG, "EV_BEACON_FOUND"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON FOUND"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON FOUND"); break; case EV_BEACON_MISSED: ESP_LOGI(TAG, "EV_BEACON_MISSED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON MISSED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON MISSED"); break; case EV_BEACON_TRACKED: ESP_LOGI(TAG, "EV_BEACON_TRACKED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON TRACKED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON TRACKED"); break; case EV_JOINING: ESP_LOGI(TAG, "EV_JOINING"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINING"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOINING"); break; case EV_JOINED: ESP_LOGI(TAG, "EV_JOINED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINED"); - #endif + 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 // during join, but not supported by TTN at this time). LMIC_setLinkCheckMode(0); @@ -172,50 +156,38 @@ void onEvent (ev_t ev) { break; case EV_RFU1: ESP_LOGI(TAG, "EV_RFU1"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RFUI"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RFUI"); break; case EV_JOIN_FAILED: ESP_LOGI(TAG, "EV_JOIN_FAILED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOIN FAILED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOIN FAILED"); break; case EV_REJOIN_FAILED: ESP_LOGI(TAG, "EV_REJOIN_FAILED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "REJOIN FAILED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "REJOIN FAILED"); break; case EV_TXCOMPLETE: ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "TX COMPLETE"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "TX COMPLETE"); if (LMIC.txrxFlags & TXRX_ACK) { ESP_LOGI(TAG, "Received ack"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RECEIVED ACK"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RECEIVED ACK"); } if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); - #ifdef HAS_DISPLAY - u8x8.clearLine(6); - u8x8.setCursor(0, 6); - u8x8.printf("Rcvd %i bytes", LMIC.dataLen); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - // LMIC.snr = SNR twos compliment [dB] * 4 - // LMIC.rssi = RSSI [dBm] (-196...+63) - u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); - #endif + u8x8.clearLine(6); + u8x8.setCursor(0, 6); + u8x8.printf("Rcvd %i bytes", LMIC.dataLen); + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + // LMIC.snr = SNR twos compliment [dB] * 4 + // LMIC.rssi = RSSI [dBm] (-196...+63) + u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); // check if payload received on command port, then call remote command interpreter if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) { // caution: buffering LMIC values here because rcommand() can modify LMIC.frame @@ -230,47 +202,35 @@ void onEvent (ev_t ev) { break; case EV_LOST_TSYNC: ESP_LOGI(TAG, "EV_LOST_TSYNC"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LOST TSYNC"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LOST TSYNC"); break; case EV_RESET: ESP_LOGI(TAG, "EV_RESET"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RESET"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RESET"); break; case EV_RXCOMPLETE: // data received in ping slot ESP_LOGI(TAG, "EV_RXCOMPLETE"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RX COMPLETE"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RX COMPLETE"); break; case EV_LINK_DEAD: ESP_LOGI(TAG, "EV_LINK_DEAD"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK DEAD"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK DEAD"); break; case EV_LINK_ALIVE: ESP_LOGI(TAG, "EV_LINK_ALIVE"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK ALIVE"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK ALIVE"); break; default: ESP_LOGI(TAG, "Unknown event"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - u8x8.printf("UNKNOWN EVENT %d", ev); - #endif + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + u8x8.printf("UNKNOWN EVENT %d", ev); break; } } diff --git a/src/macsniff.cpp b/src/macsniff.cpp index e0907317..fe5b80a4 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -60,9 +60,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { if (newmac.second) { // first time seen this WIFI or BLE MAC snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value - #ifdef HAS_DISPLAY - u8x8.draw2x2String(0, 0, counter); - #endif + u8x8.draw2x2String(0, 0, counter); ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> #%05i", typebuff, rssi, hashedmac, macs.size()); } else { // already seen WIFI or BLE MAC ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi); @@ -89,10 +87,8 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { // Current devices seen on this scan session currentScanDevice++; mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); - #ifdef HAS_DISPLAY - u8x8.setCursor(12,3); - u8x8.printf("%d", currentScanDevice); - #endif + u8x8.setCursor(12,3); + u8x8.printf("%d", currentScanDevice); rgb_set_color(COLOR_NONE); } @@ -101,21 +97,17 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void BLECount() { int blenum = 0; // Total device seen on this scan session currentScanDevice = 0; // Set 0 seen device on this scan session - #ifdef HAS_DISPLAY - u8x8.clearLine(3); - u8x8.drawString(0,3,"BLE Scan..."); - #endif + u8x8.clearLine(3); + u8x8.drawString(0,3,"BLE Scan..."); BLEDevice::init(PROGNAME); BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime); blenum=foundDevices.getCount(); - #ifdef HAS_DISPLAY - u8x8.clearLine(3); - u8x8.setCursor(0,3); - u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); - #endif + u8x8.clearLine(3); + u8x8.setCursor(0,3); + u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); } #endif diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 505c41cc..09d813fc 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -59,11 +59,9 @@ void set_reset(int val) { switch (val) { case 0: // restart device ESP_LOGI(TAG, "Remote command: restart device"); - #ifdef HAS_DISPLAY - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset pending "); - #endif + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset pending "); vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server esp_restart(); break; @@ -73,20 +71,16 @@ void set_reset(int val) { wifis.clear(); // clear Wifi macs container bles.clear(); // clear BLE macs container salt = random(65536); // get new 16bit random for salting hashes - #ifdef HAS_DISPLAY - u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset counter "); - #endif + u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset counter "); break; case 2: // reset device to factory settings ESP_LOGI(TAG, "Remote command: reset device to factory settings"); - #ifdef HAS_DISPLAY - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Factory reset "); - #endif + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Factory reset "); eraseConfig(); break; } @@ -95,11 +89,9 @@ void set_reset(int val) { void set_rssi(int val) { cfg.rssilimit = val * -1; ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit); - #ifdef HAS_DISPLAY - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); - #endif + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); }; void set_wifiscancycle(int val) { @@ -145,9 +137,7 @@ void set_screensaver(int val) { case 1: cfg.screensaver = val; break; default: cfg.screensaver = 0; break; } - #ifdef HAS_DISPLAY - u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off - #endif + u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off }; void set_display(int val) { @@ -156,9 +146,7 @@ void set_display(int val) { case 1: cfg.screenon = val; break; default: cfg.screenon = 0; break; } - #ifdef HAS_DISPLAY - u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off - #endif + u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off }; void set_lorasf(int val) { @@ -182,9 +170,7 @@ void set_blescan(int val) { default: cfg.blescan = 0; btStop(); - #ifdef HAS_DISPLAY - u8x8.clearLine(3); // clear BLE results from display - #endif + u8x8.clearLine(3); // clear BLE results from display break; } };