bugfixing LED blink routine (not fixed)

This commit is contained in:
Klaus K Wilting 2018-04-25 11:46:58 +02:00
parent bedd90bede
commit e0dc8cd4d0
2 changed files with 21 additions and 16 deletions

View File

@ -27,7 +27,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
bool added = false; bool added = false;
uint32_t addr2int, vendor2int; // temporary buffer for MAC and Vendor OUI uint32_t addr2int, vendor2int; // temporary buffer for MAC and Vendor OUI
uint16_t hashedmac; // temporary buffer for generated hash value uint16_t hashedmac; // temporary buffer for generated hash value
uint16_t memlevel; // % of used heap mem float memlevel; // % of used heap mem
// only last 3 MAC Address bytes are used for MAC address anonymization // only last 3 MAC Address bytes are used for MAC address anonymization
// but since it's uint32 we take 4 bytes to avoid 1st value to be 0 // but since it's uint32 we take 4 bytes to avoid 1st value to be 0
@ -51,6 +51,10 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
// Count only if MAC was not yet seen // Count only if MAC was not yet seen
if (added) { if (added) {
// Display heap memory left
memlevel = ESP.getFreeHeap() / heapmem * 100;
sprintf(display_mem, "%d%%", memlevel);
// increment counter and one blink led
if (sniff_type == MAC_SNIFF_WIFI ) { if (sniff_type == MAC_SNIFF_WIFI ) {
macs_wifi++; // increment Wifi MACs counter macs_wifi++; // increment Wifi MACs counter
if (joinstate) if (joinstate)
@ -65,10 +69,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
#endif #endif
} }
// Display heap memory left
memlevel = 1 - (ESP.getFreeHeap() / heapmem);
sprintf(display_mem, "%d.1%%", memlevel);
// Log scan result // Log scan result
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s -> %d Bytes left", ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s -> %d Bytes left",
sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH", sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH",

View File

@ -50,6 +50,7 @@ uint8_t channel = 0; // wifi channel rotation counter global for
char display_lora[16], display_lmic[16], display_mem[16]; // display buffers char display_lora[16], display_lmic[16], display_mem[16]; // display buffers
enum states LEDState = LED_OFF, previousLEDState = LED_OFF; // LED state global for state machine enum states LEDState = LED_OFF, previousLEDState = LED_OFF; // LED state global for state machine
bool joinstate = false; // LoRa network joined? global flag bool joinstate = false; // LoRa network joined? global flag
bool oneblink = false, blinkdone = false; // flags for state machine for blinking LED once
const uint32_t heapmem = ESP.getFreeHeap(); // free heap memory after start (:= 100%) const uint32_t heapmem = ESP.getFreeHeap(); // free heap memory after start (:= 100%)
std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE) std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
@ -70,10 +71,11 @@ int redirect_log(const char * fmt, va_list args) {
#endif #endif
void blink_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_interval) { void blink_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_interval) {
ESP_LOGI(TAG, "blink_LED color: %d, duration: %d, interval: %d", set_color, set_blinkduration, set_interval);
color = set_color; // set color for RGB LED color = set_color; // set color for RGB LED
LEDBlinkduration = set_blinkduration; // duration on LEDBlinkduration = set_blinkduration; // duration on
LEDInterval = set_interval; // duration off - on - off LEDInterval = set_interval; // duration off - on - off
LEDState = LED_ON; // start blink oneblink = set_interval ? false : true; // set blinking mode: continuous or single blink
} }
void reset_counters() { void reset_counters() {
@ -151,15 +153,15 @@ void lorawan_loop(void * pvParameters) {
// LED indicators for viusalizing LoRaWAN state // LED indicators for viusalizing LoRaWAN state
if ( LMIC.opmode & (OP_JOINING | OP_REJOIN) ) { if ( LMIC.opmode & (OP_JOINING | OP_REJOIN) ) {
// 5 quick blinks 20ms on each 1/5 second while joining // quick blink 20ms on each 1/5 second while joining
blink_LED(COLOR_YELLOW, 20, 200); blink_LED(COLOR_YELLOW, 20, 200);
// TX data pending // TX data pending
} else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) { } else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) {
// 3 small blink 10ms on each 1/2sec (not when joining) // small blink 10ms on each 1/2sec (not when joining)
blink_LED(COLOR_BLUE, 10, 500); blink_LED(COLOR_BLUE, 10, 500);
// This should not happen so indicate a problem // This should not happen so indicate a problem
} else if ( LMIC.opmode & (OP_TXDATA | OP_TXRXPEND | OP_JOINING | OP_REJOIN) == 0 ) { } else if ( LMIC.opmode & (OP_TXDATA | OP_TXRXPEND | OP_JOINING | OP_REJOIN) == 0 ) {
// 5 heartbeat long blink 200ms on each 2 seconds // heartbeat long blink 200ms on each 2 seconds
blink_LED(COLOR_RED, 200, 2000); blink_LED(COLOR_RED, 200, 2000);
} else { } else {
// led off // led off
@ -414,14 +416,17 @@ uint64_t uptime() {
void switchLEDstate() { void switchLEDstate() {
// LEDInterval != 0 -> LED is currently blinking -> toggle if interval cycle time elapsed if (oneblink && !blinkdone) { // keep LED on until one blink is done
// LEDInterval = 0 -> do one blink then turn off LED LEDState = (currentMillis % LEDBlinkduration) > 0 ? LED_ON : LED_OFF;
blinkdone = LEDState ? false : true;
if (LEDInterval) // LED is blinking, wait until time elapsed, then toggle }
else
if (LEDInterval) // LED is blinking, wait until time elapsed, then toggle LED
LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? LED_ON : LED_OFF; LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? LED_ON : LED_OFF;
else // only one blink
LEDState = (currentMillis < LEDBlinkduration) ? LED_ON : LED_OFF;
} // switchLEDstate() } // switchLEDstate()
#endif #endif