adding Set ENS counter on/off via rcomd 0x18 00|01

This commit is contained in:
Chrisotph Schultz 2020-10-04 22:58:29 +02:00
parent a90f3d07da
commit cae92514bb
11 changed files with 74 additions and 38 deletions

View File

@ -505,6 +505,10 @@ Send for example `8386` as Downlink on Port 2 to get battery status and time/dat
0 = disabled
1 = enabled [default]
0x18 set ENS counter on/off
0 = disabled (default)
1 = enabled
0x80 get device configuration
Device answers with it's current configuration on Port 3.

View File

@ -11,7 +11,7 @@
#include "sds011read.h"
#include "sdcard.h"
extern Ticker cyclicTimer;
extern Ticker housekeeper;
void setCyclicIRQ(void);
void doHousekeeping(void);

View File

@ -80,6 +80,7 @@ typedef struct __attribute__((packed)) {
uint8_t monitormode; // 0=disabled, 1=enabled
uint8_t runmode; // 0=normal, 1=update
uint8_t payloadmask; // bitswitches for payload data
uint8_t enscount; // 0=disabled 1= enabled
char version[10]; // Firmware version
#ifdef HAS_BME680
uint8_t

View File

@ -168,11 +168,12 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event,
mac_add((uint8_t *)p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE);
#if (COUNT_ENS)
if (cfg.enscount){
// check for ens signature
if (NULL != strstr((const char *)p->scan_rst.ble_adv, ensMagicBytes))
cwa_mac_add(hashedmac);
#endif
}
/* to be improved in vendorfilter if:
// you can search for elements in the payload using the

View File

@ -47,6 +47,7 @@ static void defaultConfig(configData_t *myconfig) {
myconfig->rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
myconfig->monitormode = 0; // 0=disabled, 1=enabled
myconfig->payloadmask = PAYLOADMASK; // all payload switched on
myconfig->enscount =0; // 0= disabled, 1 = enabled
memcpy(myconfig->version, version, 10); // Firmware version [exactly 10 chars]
#ifdef HAS_BME680

View File

@ -7,7 +7,7 @@
// Local logging tag
static const char TAG[] = __FILE__;
Ticker cyclicTimer;
Ticker housekeeper;
#if (HAS_SDS011)
extern boolean isSDS011Active;

View File

@ -265,11 +265,10 @@ void dp_drawPage(time_t t, bool nextpage) {
else
dp_printf("WIFI:off");
if (cfg.blescan)
#if (!COUNT_ENS)
if (!cfg.enscount)
dp_printf("BLTH:%-5d", macs_ble);
#else
else
dp_printf(" CWA:%-5d", cwa_report());
#endif
else
dp_printf(" BLTH:off");
#elif ((WIFICOUNTER) && (!BLECOUNTER))
@ -280,10 +279,10 @@ void dp_drawPage(time_t t, bool nextpage) {
#elif ((!WIFICOUNTER) && (BLECOUNTER))
if (cfg.blescan) {
dp_printf("BLTH:%-5d", macs_ble);
#if (COUNT_ENS)
if (cfg.enscount)
dp_printf("(CWA:%d)", cwa_report());
#endif
} else
}
else
dp_printf("BLTH:off");
#else
dp_printf("Sniffer disabled");

View File

@ -1,6 +1,6 @@
// clang-format off
// upload_speed 921600
// board ttgo-lora32-v21new
// board esp32dev
#ifndef _TTGOV21NEW_H
#define _TTGOV21NEW_H

View File

@ -486,7 +486,7 @@ void setup() {
// cyclic function interrupts
sendTimer.attach(cfg.sendcycle * 2, setSendIRQ);
cyclicTimer.attach(HOMECYCLE, setCyclicIRQ);
housekeeper.attach(HOMECYCLE, setCyclicIRQ);
#if (TIME_SYNC_INTERVAL)

View File

@ -339,26 +339,54 @@ void set_flush(uint8_t val[]) {
// used to open receive window on LoRaWAN class a nodes
};
void set_enscount(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set ENS_COUNT to %s",
val[0] ? "on" : "off");
cfg.enscount = val[0] ? 1 : 0;
if (val[0])
cfg.payloadmask |= SENSOR1_DATA;
else
cfg.payloadmask &= ~SENSOR1_DATA;
}
// assign previously defined functions to set of numeric remote commands
// format: opcode, function, #bytes params,
// flag (true = do make settings persistent / false = don't)
//
static const cmd_t table[] = {
{0x01, set_rssi, 1, true}, {0x02, set_countmode, 1, true},
{0x03, set_gps, 1, true}, {0x04, set_display, 1, true},
{0x05, set_loradr, 1, true}, {0x06, set_lorapower, 1, true},
{0x07, set_loraadr, 1, true}, {0x08, set_screensaver, 1, true},
{0x09, set_reset, 1, false}, {0x0a, set_sendcycle, 1, true},
{0x0b, set_wifichancycle, 1, true}, {0x0c, set_blescantime, 1, true},
{0x0d, set_vendorfilter, 1, false}, {0x0e, set_blescan, 1, true},
{0x0f, set_wifiant, 1, true}, {0x10, set_rgblum, 1, true},
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
{0x13, set_sensor, 2, true}, {0x14, set_payloadmask, 1, true},
{0x15, set_bme, 1, true}, {0x16, set_batt, 1, true},
{0x17, set_wifiscan, 1, true}, {0x80, get_config, 0, false},
{0x81, get_status, 0, false}, {0x83, get_batt, 0, false},
{0x84, get_gps, 0, false}, {0x85, get_bme, 0, false},
{0x86, get_time, 0, false}, {0x87, set_time, 0, false},
{0x01, set_rssi, 1, true},
{0x02, set_countmode, 1, true},
{0x03, set_gps, 1, true},
{0x04, set_display, 1, true},
{0x05, set_loradr, 1, true},
{0x06, set_lorapower, 1, true},
{0x07, set_loraadr, 1, true},
{0x08, set_screensaver, 1, true},
{0x09, set_reset, 1, false},
{0x0a, set_sendcycle, 1, true},
{0x0b, set_wifichancycle, 1, true},
{0x0c, set_blescantime, 1, true},
{0x0d, set_vendorfilter, 1, false},
{0x0e, set_blescan, 1, true},
{0x0f, set_wifiant, 1, true},
{0x10, set_rgblum, 1, true},
{0x11, set_monitor, 1, true},
{0x12, set_beacon, 7, false},
{0x13, set_sensor, 2, true},
{0x14, set_payloadmask, 1, true},
{0x15, set_bme, 1, true},
{0x16, set_batt, 1, true},
{0x17, set_wifiscan, 1, true},
{0x18, set_enscount, 1, true},
{0x80, get_config, 0, false},
{0x81, get_status, 0, false},
{0x83, get_batt, 0, false},
{0x84, get_gps, 0, false},
{0x85, get_bme, 0, false},
{0x86, get_time, 0, false},
{0x87, set_time, 0, false},
{0x99, set_flush, 0, false}};
static const uint8_t cmdtablesize =

View File

@ -56,16 +56,18 @@ uint8_t *sensor_read(uint8_t sensor) {
// insert user specific sensor data frames here
// note: Sensor1 fields are used for ENS count, if ENS detection enabled
#if (COUNT_ENS)
#if COUNT_ENS
if (cfg.enscount)
payload.addCount(cwa_report(), MAC_SNIFF_BLE_CWA);
#else
if(!cfg.enscount)
buf[0] = length;
buf[1] = 0x01;
buf[2] = 0x02;
buf[3] = 0x03;
#endif
break;
case 2:
buf[0] = length;