new led management (part 1)
This commit is contained in:
parent
f6864b1973
commit
758a960371
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
; ---> 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
|
||||||
|
@ -116,13 +116,13 @@ void do_send(osjob_t* j){
|
|||||||
mydata[1] = data & 0xff;
|
mydata[1] = data & 0xff;
|
||||||
|
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
// Sum of unique BLE MACs seen
|
// Sum of unique BLE MACs seen
|
||||||
data = (uint16_t) bles.size();
|
data = (uint16_t) bles.size();
|
||||||
mydata[2] = (data & 0xff00) >> 8;
|
mydata[2] = (data & 0xff00) >> 8;
|
||||||
mydata[3] = data & 0xff;
|
mydata[3] = data & 0xff;
|
||||||
#else
|
#else
|
||||||
mydata[2] = 0;
|
mydata[2] = 0;
|
||||||
mydata[3] = 0;
|
mydata[3] = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Total BLE+WIFI unique MACs seen
|
// Total BLE+WIFI unique MACs seen
|
||||||
@ -164,7 +164,7 @@ void onEvent (ev_t ev) {
|
|||||||
|
|
||||||
case EV_JOINED:
|
case EV_JOINED:
|
||||||
strcpy_P(buff, PSTR("JOINED"));
|
strcpy_P(buff, PSTR("JOINED"));
|
||||||
sprintf(display_lora, " "); // erase "Join Wait" message from display
|
sprintf(display_lora, ""); // erase "Join Wait" message from display
|
||||||
// Disable link check validation (automatically enabled
|
// Disable link check validation (automatically enabled
|
||||||
// during join, but not supported by TTN at this time).
|
// during join, but not supported by TTN at this time).
|
||||||
LMIC_setLinkCheckMode(0);
|
LMIC_setLinkCheckMode(0);
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char *TAG = "macsniff";
|
static const char *TAG = "macsniff";
|
||||||
|
|
||||||
|
// defined in main.cpp
|
||||||
|
void set_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_interval, uint8_t set_count);
|
||||||
|
|
||||||
static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL};
|
static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL};
|
||||||
|
|
||||||
uint16_t salt;
|
uint16_t salt;
|
||||||
@ -49,21 +52,16 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
|
|
||||||
// Insert only if it was not found on global count
|
// Insert only if it was not found on global count
|
||||||
if (added) {
|
if (added) {
|
||||||
|
|
||||||
if (sniff_type == MAC_SNIFF_WIFI ) {
|
if (sniff_type == MAC_SNIFF_WIFI ) {
|
||||||
rgb_set_color(COLOR_GREEN);
|
set_LED(COLOR_GREEN, 20, 0, 1);
|
||||||
wifis.insert(hashedmac); // add hashed MAC to wifi container
|
wifis.insert(hashedmac); // add hashed MAC to wifi container
|
||||||
}
|
}
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
else if (sniff_type == MAC_SNIFF_BLE ) {
|
else if (sniff_type == MAC_SNIFF_BLE ) {
|
||||||
rgb_set_color(COLOR_MAGENTA);
|
set_LED(COLOR_MAGENTA, 20, 0, 1);
|
||||||
bles.insert(hashedmac); // add hashed MAC to BLE container
|
bles.insert(hashedmac); // add hashed MAC to BLE container
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Not sure user will have time to see the LED
|
|
||||||
// TBD do light off further in the code
|
|
||||||
rgb_set_color(COLOR_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s",
|
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s",
|
||||||
|
84
src/main.cpp
84
src/main.cpp
@ -46,9 +46,9 @@ osjob_t sendjob, initjob; // LMIC
|
|||||||
// Initialize global variables
|
// Initialize global variables
|
||||||
char display_lora[16], display_lmic[16]; // display buffers
|
char display_lora[16], display_lmic[16]; // display buffers
|
||||||
uint64_t uptimecounter = 0;
|
uint64_t uptimecounter = 0;
|
||||||
uint32_t currentMillis = 0, previousLEDmillis = 0, previousDisplaymillis = 0;
|
uint32_t currentMillis = 0, previousDisplaymillis = 0;
|
||||||
uint8_t DisplayState, LEDState;
|
uint8_t DisplayState, LEDState = 0, LEDcount = 0;
|
||||||
uint16_t LEDBlinkduration = 500, LEDInterval = 1000, color = COLOR_NONE;
|
uint16_t LEDBlinkduration = 0, LEDInterval = 0, color=COLOR_NONE;
|
||||||
uint8_t channel = 0; // wifi channel counter
|
uint8_t channel = 0; // wifi channel counter
|
||||||
bool joinstate = false;
|
bool joinstate = false;
|
||||||
|
|
||||||
@ -79,6 +79,14 @@ void eraseConfig(void);
|
|||||||
void saveConfig(void);
|
void saveConfig(void);
|
||||||
void loadConfig(void);
|
void loadConfig(void);
|
||||||
|
|
||||||
|
void set_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_interval, uint8_t set_count) {
|
||||||
|
color = set_color; // set color for RGB LED
|
||||||
|
LEDBlinkduration = set_blinkduration; // duration on
|
||||||
|
LEDInterval = set_interval; // duration off - on - off
|
||||||
|
LEDcount = set_count * 2; // number of blinks before LED off
|
||||||
|
LEDState = set_count ? 1 : 0; // sets LED to off if 0 blinks
|
||||||
|
}
|
||||||
|
|
||||||
/* begin LMIC specific parts ------------------------------------------------------------ */
|
/* begin LMIC specific parts ------------------------------------------------------------ */
|
||||||
|
|
||||||
// defined in lorawan.cpp
|
// defined in lorawan.cpp
|
||||||
@ -144,13 +152,6 @@ static void lora_init (osjob_t* j) {
|
|||||||
LMIC_startJoining();
|
LMIC_startJoining();
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_interval, uint8_t set_state) {
|
|
||||||
color = set_color;
|
|
||||||
LEDBlinkduration = set_blinkduration;
|
|
||||||
LEDInterval = set_interval;
|
|
||||||
LEDState = set_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
// LMIC FreeRTos Task
|
// LMIC FreeRTos Task
|
||||||
void lorawan_loop(void * pvParameters) {
|
void lorawan_loop(void * pvParameters) {
|
||||||
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
||||||
@ -161,16 +162,16 @@ 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) ) {
|
||||||
// quick blink 20ms on each 1/5 second
|
// 5 quick blinks 20ms on each 1/5 second while joining
|
||||||
set_LED(COLOR_YELLOW, 20, 200, 1);
|
set_LED(COLOR_YELLOW, 20, 200, 5);
|
||||||
// TX data pending
|
// TX data pending
|
||||||
} else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) {
|
} else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) {
|
||||||
// small blink 10ms on each 1/2sec (not when joining)
|
// 3 small blink 10ms on each 1/2sec (not when joining)
|
||||||
set_LED(COLOR_BLUE, 10, 500, 1);
|
set_LED(COLOR_BLUE, 10, 500, 3);
|
||||||
// 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 ) {
|
||||||
// heartbeat long blink 200ms on each 2 seconds
|
// 5 heartbeat long blink 200ms on each 2 seconds
|
||||||
set_LED(COLOR_RED, 200, 2000, 1);
|
set_LED(COLOR_RED, 200, 2000, 5);
|
||||||
} else {
|
} else {
|
||||||
// led off
|
// led off
|
||||||
set_LED(COLOR_NONE, 0, 0, 0);
|
set_LED(COLOR_NONE, 0, 0, 0);
|
||||||
@ -270,7 +271,7 @@ void sniffer_loop(void * pvParameters) {
|
|||||||
vTaskDelay(1000/portTICK_PERIOD_MS);
|
vTaskDelay(1000/portTICK_PERIOD_MS);
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
sprintf(display_lora, " "); // clear LoRa wait message fromd display
|
sprintf(display_lora, ""); // clear LoRa wait message fromd display
|
||||||
|
|
||||||
} // end of send data cycle
|
} // end of send data cycle
|
||||||
|
|
||||||
@ -412,39 +413,30 @@ uint64_t uptime() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
void updateLEDstatus() {
|
void switchLED() {
|
||||||
|
|
||||||
if (LEDState == 0) {
|
|
||||||
if (currentMillis - previousLEDmillis >= LEDInterval) {
|
|
||||||
LEDState = 1;
|
|
||||||
previousLEDmillis += LEDInterval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (currentMillis - previousLEDmillis >= LEDBlinkduration) {
|
|
||||||
LEDState = 0;
|
|
||||||
previousLEDmillis += LEDBlinkduration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}; // updateLEDstatus()
|
|
||||||
|
|
||||||
void refreshLED() {
|
|
||||||
static bool previousLEDState;
|
static bool previousLEDState;
|
||||||
// led need to change state? avoid digitalWrite() for nothing
|
// led need to change state? avoid digitalWrite() for nothing
|
||||||
if (LEDState != previousLEDState) {
|
if (LEDState != previousLEDState) {
|
||||||
#ifdef LED_ACTIVE_LOW
|
#ifdef LED_ACTIVE_LOW
|
||||||
digitalWrite(HAS_LED, LEDState);
|
|
||||||
#else
|
|
||||||
digitalWrite(HAS_LED, !LEDState);
|
digitalWrite(HAS_LED, !LEDState);
|
||||||
|
#else
|
||||||
|
digitalWrite(HAS_LED, LEDState);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_RGB_LED
|
#ifdef HAS_RGB_LED
|
||||||
rgb_set_color(color);
|
rgb_set_color(color);
|
||||||
#endif
|
#endif
|
||||||
previousLEDState = LEDState;
|
previousLEDState = LEDState;
|
||||||
|
LEDcount--; // decrement blink counter
|
||||||
}
|
}
|
||||||
}; // refreshLED()
|
}; // switchLED()
|
||||||
|
|
||||||
|
void switchLEDstate() {
|
||||||
|
if (!LEDcount) // no more blinks? -> switch off LED
|
||||||
|
LEDState = 0;
|
||||||
|
else if (LEDInterval) // blinks left? -> toggle LED and decrement blinks
|
||||||
|
LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? 1 : 0;
|
||||||
|
} // switchLEDstate()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -469,7 +461,6 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
|
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
|
||||||
rgb_set_color(COLOR_NONE);
|
|
||||||
|
|
||||||
// initialize 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);
|
||||||
@ -492,17 +483,8 @@ void setup() {
|
|||||||
|
|
||||||
// initialize led if needed
|
// initialize led if needed
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
LEDState = 0;
|
|
||||||
color = COLOR_NONE;
|
|
||||||
pinMode(HAS_LED, OUTPUT);
|
pinMode(HAS_LED, OUTPUT);
|
||||||
#ifdef LED_ACTIVE_LOW
|
set_LED(COLOR_NONE, 0, 0, 0); // LED off
|
||||||
digitalWrite(HAS_LED, LEDState);
|
|
||||||
#else
|
|
||||||
digitalWrite(HAS_LED, !LEDState);
|
|
||||||
#endif
|
|
||||||
#ifdef HAS_RBG_LED
|
|
||||||
rgb_set_color (color);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize button handling if needed
|
// initialize button handling if needed
|
||||||
@ -593,8 +575,8 @@ void loop() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
updateLEDstatus();
|
switchLEDstate();
|
||||||
refreshLED();
|
switchLED();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//sendPayload();
|
//sendPayload();
|
||||||
|
Loading…
Reference in New Issue
Block a user