beacon monitor mode implemented (EXPERIMENTAL, untested yet)

This commit is contained in:
Klaus K Wilting 2018-07-24 18:44:13 +02:00
parent cc141bcb67
commit a030918f91
9 changed files with 89 additions and 9 deletions

5
src/beacon_array.h Normal file
View File

@ -0,0 +1,5 @@
std::array<uint32_t, 5>::iterator it;
std::array<uint32_t, 5> beacons = {0x000000000000, 0x000000000000,
0x000000000000, 0x000000000000,
0x000000000000};

View File

@ -30,6 +30,7 @@ void defaultConfig() {
cfg.vendorfilter = 1; // 0=disabled, 1=enabled cfg.vendorfilter = 1; // 0=disabled, 1=enabled
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
cfg.gpsmode = 1; // 0=disabled, 1=enabled cfg.gpsmode = 1; // 0=disabled, 1=enabled
cfg.monitormode = 0; // 0=disabled, 1=enabled
strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1); strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1);
} }
@ -138,6 +139,10 @@ void saveConfig() {
flash8 != cfg.gpsmode) flash8 != cfg.gpsmode)
nvs_set_i8(my_handle, "gpsmode", cfg.gpsmode); nvs_set_i8(my_handle, "gpsmode", cfg.gpsmode);
if (nvs_get_i8(my_handle, "monitormode", &flash8) != ESP_OK ||
flash8 != cfg.monitormode)
nvs_set_i8(my_handle, "monitormode", cfg.monitormode);
if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK || if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK ||
flash16 != cfg.rssilimit) flash16 != cfg.rssilimit)
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit); nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
@ -307,14 +312,21 @@ void loadConfig() {
if (nvs_get_i8(my_handle, "gpsmode", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "gpsmode", &flash8) == ESP_OK) {
cfg.gpsmode = flash8; cfg.gpsmode = flash8;
ESP_LOGI(TAG, "GPSmode = %d", flash8); ESP_LOGI(TAG, "GPS mode = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "GPSmode set to default %d", cfg.gpsmode); ESP_LOGI(TAG, "GPS mode set to default %d", cfg.gpsmode);
saveConfig();
}
if (nvs_get_i8(my_handle, "monitormode", &flash8) == ESP_OK) {
cfg.monitormode = flash8;
ESP_LOGI(TAG, "Monitor mode = %d", flash8);
} else {
ESP_LOGI(TAG, "Monitor mode set to default %d", cfg.monitormode);
saveConfig(); saveConfig();
} }
nvs_close(my_handle); nvs_close(my_handle);
ESP_LOGI(TAG, "Done"); ESP_LOGI(TAG, "Done");
} }
} // loadConfig() } // loadConfig()

View File

@ -8,7 +8,7 @@
#include <esp32-hal-log.h> #include <esp32-hal-log.h>
// attn: increment version after modifications to configData_t truct! // attn: increment version after modifications to configData_t truct!
#define PROGVERSION "1.3.94" // use max 10 chars here! #define PROGVERSION "1.3.95" // use max 10 chars here!
#define PROGNAME "PAXCNT" #define PROGNAME "PAXCNT"
// std::set for unified array functions // std::set for unified array functions
@ -33,6 +33,7 @@ typedef struct {
uint8_t vendorfilter; // 0=disabled, 1=enabled uint8_t vendorfilter; // 0=disabled, 1=enabled
uint8_t rgblum; // RGB Led luminosity (0..100%) uint8_t rgblum; // RGB Led luminosity (0..100%)
uint8_t gpsmode; // 0=disabled, 1=enabled uint8_t gpsmode; // 0=disabled, 1=enabled
uint8_t monitormode; // 0=disabled, 1=enabled
char version[10]; // Firmware version char version[10]; // Firmware version
} configData_t; } configData_t;

View File

@ -6,6 +6,9 @@
#include "vendor_array.h" #include "vendor_array.h"
#endif #endif
#include "beacon_array.h"
#include "senddata.h"
// Local logging tag // Local logging tag
static const char TAG[] = "wifi"; static const char TAG[] = "wifi";
@ -27,12 +30,21 @@ uint16_t reset_salt(void) {
return salt; return salt;
} }
uint8_t isBeacon(uint32_t mac) {
it = std::find(beacons.begin(), beacons.end(), mac);
if (it != beacons.end())
return std::distance(beacons.begin(), it);
else
return 0;
}
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
char buff[16]; // temporary buffer for printf char buff[16]; // temporary buffer for printf
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
uint8_t beacon = 0; // beacon number in test monitor mode
// 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 +63,16 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
// and increment counter on display // and increment counter on display
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization // https://en.wikipedia.org/wiki/MAC_Address_Anonymization
// in test monitor mode check if MAC is a known beacon
if (cfg.monitormode) {
beacon = isBeacon(addr2int);
if (beacon) {
payload.reset();
payload.addAlarm(rssi, beacon);
senddata(BEACONPORT);
}
};
addr2int += (uint32_t)salt; // add 16-bit salt to pseudo MAC addr2int += (uint32_t)salt; // add 16-bit salt to pseudo MAC
snprintf( snprintf(
buff, sizeof(buff), "%08X", buff, sizeof(buff), "%08X",

View File

@ -45,10 +45,10 @@ portMUX_TYPE timerMux =
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
// handler shared variables // handler shared variables
std::set<uint16_t> macs; // associative container holds total of unique MAC std::set<uint16_t> macs; // associative container holding unique MAC
// adress hashes (Wifi + BLE) // adress hashes (Wifi + BLE)
// initialize payload ncoder // initialize payload encoder
PayloadConvert payload(PAYLOAD_BUFFER_SIZE); PayloadConvert payload(PAYLOAD_BUFFER_SIZE);
// local Tag for logging // local Tag for logging

View File

@ -55,6 +55,7 @@
#define BUTTONPORT 5 // Port on which device sends button pressed signal #define BUTTONPORT 5 // Port on which device sends button pressed signal
#define LPP1PORT 1 // Port for Cayenne LPP 1.0 dynamic sensor encoding #define LPP1PORT 1 // Port for Cayenne LPP 1.0 dynamic sensor encoding
#define LPP2PORT 2 // Port for Cayenne LPP 2.0 packed sensor encoding #define LPP2PORT 2 // Port for Cayenne LPP 2.0 packed sensor encoding
#define BEACONPORT 6 // Port on which device sends beacon alarms
// Some hardware settings // Some hardware settings
#define RGBLUMINOSITY 30 // RGB LED luminosity [default = 30%] #define RGBLUMINOSITY 30 // RGB LED luminosity [default = 30%]

View File

@ -26,6 +26,11 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = lowByte(value2); buffer[cursor++] = lowByte(value2);
} }
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
buffer[cursor++] = rssi;
buffer[cursor++] = msg;
}
void PayloadConvert::addConfig(configData_t value) { void PayloadConvert::addConfig(configData_t value) {
buffer[cursor++] = value.lorasf; buffer[cursor++] = value.lorasf;
buffer[cursor++] = value.txpower; buffer[cursor++] = value.txpower;
@ -99,6 +104,11 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
writeUint16(value2); writeUint16(value2);
} }
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
writeUint8(rssi);
writeUint8(msg);
}
void PayloadConvert::addConfig(configData_t value) { void PayloadConvert::addConfig(configData_t value) {
writeUint8(value.lorasf); writeUint8(value.lorasf);
writeUint8(value.txpower); writeUint8(value.txpower);
@ -207,6 +217,19 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = lowByte(value2); buffer[cursor++] = lowByte(value2);
} }
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_ALARM_CHANNEL;
#endif
buffer[cursor++] = LPP_PRESENCE;
buffer[cursor++] = msg;
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_MSG_CHANNEL;
#endif
buffer[cursor++] = LPP_ANALOG_INPUT;
buffer[cursor++] = rssi;
}
void PayloadConvert::addConfig(configData_t value) { void PayloadConvert::addConfig(configData_t value) {
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_ADR_CHANNEL; buffer[cursor++] = LPP_ADR_CHANNEL;

View File

@ -11,6 +11,8 @@
#define LPP_BUTTON_CHANNEL 24 #define LPP_BUTTON_CHANNEL 24
#define LPP_ADR_CHANNEL 25 #define LPP_ADR_CHANNEL 25
#define LPP_TEMP_CHANNEL 26 #define LPP_TEMP_CHANNEL 26
#define LPP_ALARM_CHANNEL 27
#define LPP_MSG_CHANNEL 28
#endif #endif
// MyDevices CayenneLPP types // MyDevices CayenneLPP types
@ -20,6 +22,7 @@
#define LPP_DIGITAL_OUTPUT 1 // 1 byte #define LPP_DIGITAL_OUTPUT 1 // 1 byte
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed #define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
#define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned #define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned
#define LPP_Presence 102 // 1 byte
class PayloadConvert { class PayloadConvert {
@ -33,6 +36,7 @@ public:
void addCount(uint16_t value1, uint16_t value2); void addCount(uint16_t value1, uint16_t value2);
void addConfig(configData_t value); void addConfig(configData_t value);
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp); void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
void addAlarm(int8_t rssi, uint8_t message);
#ifdef HAS_GPS #ifdef HAS_GPS
void addGPS(gpsStatus_t value); void addGPS(gpsStatus_t value);
#endif #endif

View File

@ -170,7 +170,7 @@ void set_display(uint8_t val) {
}; };
void set_gps(uint8_t val) { void set_gps(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set GPS to %s", val ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set GPS mode to %s", val ? "on" : "off");
switch (val) { switch (val) {
case 1: case 1:
cfg.gpsmode = val; cfg.gpsmode = val;
@ -181,6 +181,18 @@ void set_gps(uint8_t val) {
} }
}; };
void set_monitor(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set Monitor mode to %s", val ? "on" : "off");
switch (val) {
case 1:
cfg.monitormode = val;
break;
default:
cfg.monitormode = 0;
break;
}
};
void set_lorasf(uint8_t val) { void set_lorasf(uint8_t val) {
#ifdef HAS_LORA #ifdef HAS_LORA
ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val); ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val);
@ -312,8 +324,8 @@ cmd_t table[] = {{0x01, set_rssi, true}, {0x02, set_countmode, true},
{0x0b, set_wifichancycle, true}, {0x0c, set_blescantime, true}, {0x0b, set_wifichancycle, true}, {0x0c, set_blescantime, true},
{0x0d, set_vendorfilter, false}, {0x0e, set_blescan, true}, {0x0d, set_vendorfilter, false}, {0x0e, set_blescan, true},
{0x0f, set_wifiant, true}, {0x10, set_rgblum, true}, {0x0f, set_wifiant, true}, {0x10, set_rgblum, true},
{0x80, get_config, false}, {0x81, get_status, false}, {0x11, set_monitor, true}, {0x80, get_config, false},
{0x84, get_gps, false}}; {0x81, get_status, false}, {0x84, get_gps, false}};
// check and execute remote command // check and execute remote command
void rcommand(uint8_t cmd, uint8_t arg) { void rcommand(uint8_t cmd, uint8_t arg) {