Merge pull request #849 from cyberman54/development

Development
This commit is contained in:
Verkehrsrot 2022-01-29 13:50:50 +01:00 committed by GitHub
commit 793c407f34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 32 additions and 175 deletions

View File

@ -216,15 +216,6 @@ Paxcounter can be used to sync a wall clock which has a DCF77 or IF482 time tele
This describes how to set up a mobile PaxCounter:<br> Follow all steps so far for preparing the device, selecting the packed payload format. In `paxcounter.conf` set PAYLOAD_OPENSENSEBOX to 1. Register a new sensebox on https://opensensemap.org/. In the sensor configuration select "TheThingsNetwork" and set decoding profile to "LoRa serialization". Enter your TTN Application and Device ID. Setup decoding option using `[{"decoder":"latLng"},{"decoder":"uint16",sensor_id":"yoursensorid"}]`
# Covid-19 Exposure Notification System beacon detection (currently NOT working with v3.0.x, use v2.4.x for this feature)
Bluetooth low energy service UUID 0xFD6F, used by Google/Apple COVID-19 Exposure Notification System, can be monitored and counted. By comparing with the total number of observed devices this <A HREF="https://linux-fuer-wi.blogspot.com/2020/10/suche-die-zahl-64879.html">gives an indication</A> how many people staying in proximity are using Apps for tracing COVID-19 exposures, e.g. in Germany the "Corona Warn App". To achive best results with this funcion, use following settings in `paxcounter.conf`:
#define COUNT_ENS 1 // enable ENS monitoring function
#define BLECOUNTER 1 // enable bluetooth sniffing
#define WIFICOUNTER 0 // disable wifi sniffing (improves BLE scan speed)
#define HAS_SENSOR_1 1 // optional, in board's hal file: transmit ENS counter data to server
# SD-card
Data can be stored on an SD-card if one is availabe. Simply choose the file in src/hal and add the following lines to your hal-file:
@ -384,7 +375,7 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
**Ports #10, #11, #12:** User sensor data
Format is specified by user in function `sensor_read(uint8_t sensor)`, see `src/sensor.cpp`. Port #10 is also used for ENS counter (2 bytes = 16 bit), if ENS is compiled AND ENS data transfer is enabled
Format is specified by user in function `sensor_read(uint8_t sensor)`, see `src/sensor.cpp`.
# Remote control
@ -504,7 +495,7 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/
0x02 = RESERVED_DATA
0x04 = MEMS_DATA
0x08 = GPS_DATA
0x10 = SENSOR_1_DATA (also ENS counter)
0x10 = SENSOR_1_DATA
0x20 = SENSOR_2_DATA
0x40 = SENSOR_3_DATA
0x80 = BATT_DATA
@ -525,10 +516,9 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/
0 = disabled
1 = enabled [default]
0x18 set ENS counter on/off
0x18 reserved
0 = disabled [default]
1 = enabled
unused, does nothing
0x19 set sleep cycle
@ -622,4 +612,4 @@ Thanks to
- [terrillmoore](https://github.com/mcci-catena) for maintaining the LMIC for arduino LoRaWAN stack
- [sbamueller](https://github.com/sbamueller) for writing the tutorial in Make Magazine
- [Stefan](https://github.com/nerdyscout) for paxcounter opensensebox integration
- [August Quint](https://github.com/AugustQu) for adding SD card data logger, SDS011 and ENS support
- [August Quint](https://github.com/AugustQu) for adding SD card data logger and SDS011 support

View File

@ -1,16 +0,0 @@
#ifndef _CORONA_h
#define _CORONA_H
// inspired by https://github.com/kmetz/BLEExposureNotificationBeeper
// (c) by Kaspar Metz
// modified for use in the Paxcounter by AQ
#include "globals.h"
#include <map>
bool cwa_init(void);
void cwa_mac_add(uint16_t hashedmac);
void cwa_clear(void);
uint16_t cwa_report(void);
#endif

View File

@ -6,10 +6,6 @@
#include "qrcode.h"
#include "power.h"
#if (COUNT_ENS)
#include "corona.h"
#endif
#if (HAS_DISPLAY) == 1
#include <OneBitDisplay.h>
#elif (HAS_DISPLAY) == 2

View File

@ -71,7 +71,6 @@ typedef struct __attribute__((packed)) {
uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
uint8_t rgblum; // RGB Led luminosity (0..100%)
uint8_t payloadmask; // bitswitches for payload data
uint8_t enscount; // 0=disabled 1= enabled
#ifdef HAS_BME680
uint8_t

View File

@ -18,7 +18,6 @@
#include "sensor.h"
#include "lorawan.h"
#include "timekeeper.h"
#include "corona.h"
#include "boot.h"
#include "libpax_helpers.h"
#include "power.h"

View File

@ -8,6 +8,8 @@
#include "lorawan.h"
#include "display.h"
#include "power.h"
#include "sdcard.h"
#include "sds011read.h"
void reset_rtc_vars(void);
void do_reset(bool warmstart);

View File

@ -61,7 +61,8 @@
#define SDCARD_FILE_HEADER_VOLTAGE ",voltage"
#endif
bool sdcard_init(void);
bool sdcard_init(bool create = true);
bool sdcard_close(void);
void sdcardWriteData(uint16_t, uint16_t, uint16_t = 0);
#endif // _SDCARD_H

View File

@ -10,10 +10,6 @@
#include "display.h"
#include "sdcard.h"
#if (COUNT_ENS)
#include "corona.h"
#endif
extern struct count_payload_t count_from_libpax;
void SendPayload(uint8_t port);

View File

@ -84,11 +84,6 @@ function Decoder(bytes, port) {
}
}
if (port === 10) {
// ENS count
return decode(bytes, [uint16], ['ens']);
}
}

View File

@ -91,11 +91,6 @@ function decodeUplink(input) {
}
}
if (input.fPort === 10) {
// ENS count
data = decode(input.bytes, [uint16], ['ens']);
}
data.bytes = input.bytes; // comment out if you do not want to include the original payload
data.port = input.fPort; // comment out if you do not want to inlude the port

View File

@ -84,13 +84,6 @@ function decodeUplink(input) {
}
}
if (input.fPort === 10) {
var i = 0;
if (input.bytes.length >= 2) {
data.ens = (input.bytes[i++] << 8) | input.bytes[i++];
}
}
if (data.hdop) {
data.hdop /= 100;
data.latitude /= 1000000;

View File

@ -57,7 +57,6 @@ static void defaultConfig(configData_t *myconfig) {
myconfig->wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
myconfig->rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
myconfig->payloadmask = PAYLOADMASK; // payloads as defined in default
myconfig->enscount = COUNT_ENS; // 0=disabled, 1=enabled
#ifdef HAS_BME680
// initial BSEC state for BME680 sensor

View File

@ -1,54 +0,0 @@
// routines for counting the number of devices which advertise Exposure
// Notification Service e.g. "Corona Warn App" in Germany
// copied from https://github.com/kmetz/BLEExposureNotificationBeeper
// (c) by Kaspar Metz
// modified for use in the Paxcounter by AQ
#if (COUNT_ENS) && !(BLECOUNTER)
#warning ENS-Counter needs Bluetooth, but Bluetooth compile option is disabled
#endif
#if (COUNT_ENS)
// Local logging tag
static const char TAG[] = __FILE__;
#define BT_BD_ADDR_HEX(addr) \
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
#include "corona.h"
// When to forget old senders ** currently not used **
#define FORGET_AFTER_MINUTES 2
// array of timestamps for seen notifiers: hash -> timestamp[ms]
static std::map<uint16_t, unsigned long> cwaSeenNotifiers;
// Remove notifiers last seen over FORGET_AFTER_MINUTES ago.
void cwa_clear() {
#ifdef VERBOSE
ESP_LOGV(TAG, "CWA: forget old notifier: %d", cwaSeenNotifiers.size());
for (auto const &notifier : cwaSeenNotifiers) {
ESP_LOGD(TAG, "CWA forget <%04X>", notifier.first);
// }
}
#endif
// clear everything, otherwise we would count the same device again, as in the
// next cycle it likely will advertise with a different hash-value
cwaSeenNotifiers.clear();
}
// return the total number of devices seen advertising ENS
uint16_t cwa_report(void) { return cwaSeenNotifiers.size(); }
bool cwa_init(void) {
ESP_LOGD(TAG, "init BLE-scanner for ENS");
return true;
}
void cwa_mac_add(uint16_t hashedmac) {
cwaSeenNotifiers[hashedmac] = millis(); // hash last seen at ....
}
#endif

View File

@ -268,12 +268,7 @@ void dp_drawPage(bool nextpage) {
else
dp_printf("WIFI:off");
if (cfg.blescan)
#if (COUNT_ENS)
if (cfg.enscount)
dp_printf(" CWA:%-5d", cwa_report());
else
#endif
dp_printf("BLTH:%-5d", count_from_libpax.ble_count);
dp_printf("BLTH:%-5d", count_from_libpax.ble_count);
else
dp_printf(" BLTH:off");
#elif ((WIFICOUNTER) && (!BLECOUNTER))
@ -284,12 +279,7 @@ void dp_drawPage(bool nextpage) {
#elif ((!WIFICOUNTER) && (BLECOUNTER))
if (cfg.blescan)
dp_printf("BLTH:%-5d", count_from_libpax.ble_count);
#if (COUNT_ENS)
if (cfg.enscount)
dp_printf("(CWA:%d)", cwa_report());
else
#endif
dp_printf("BLTH:off");
dp_printf("BLTH:off");
#else
dp_printf("Sniffer disabled");
#endif

View File

@ -18,7 +18,7 @@
#define CFG_sx1276_radio 1
#define HAS_DISPLAY 1 // OLED-Display on board
#define HAS_LED LED_BUILTIN // white LED on board
#define HAS_LED LED_BUILTIN // white LED on board (set to NOT_A_PIN to disable)
#define HAS_BUTTON KEY_BUILTIN // button "PROG" on board
// Pins for I2C interface of OLED Display

View File

@ -20,7 +20,7 @@
#define CFG_sx1276_radio 1
#define HAS_DISPLAY 1 // OLED-Display on board
#define HAS_LED LED_BUILTIN // white LED on board
#define HAS_LED LED_BUILTIN // white LED on board (set to NOT_A_PIN to disable)
#define HAS_BUTTON KEY_BUILTIN // button "PROG" on board
#define BAT_MEASURE_ADC ADC2_GPIO13_CHANNEL // battery probe GPIO pin

View File

@ -20,7 +20,7 @@
#define CFG_sx1276_radio 1
#define HAS_DISPLAY 1 // OLED-Display on board
#define HAS_LED LED_BUILTIN // white LED on board
#define HAS_LED LED_BUILTIN // white LED on board (set to NOT_A_PIN to disable)
#define HAS_BUTTON KEY_BUILTIN // button "PROG" on board
#define BAT_MEASURE_ADC ADC1_GPIO37_CHANNEL // battery probe GPIO pin

View File

@ -10,7 +10,7 @@
// Hardware related definitions for lolin32lite (without LoRa shield)
#define HAS_LED LED_BUILTIN // on board LED on GPIO5
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW (set to NOT_A_PIN to disable)
#define MY_SDA SDA
#define MY_SCL SCL

View File

@ -15,7 +15,7 @@
#define HAS_DISPLAY 1 // OLED-Display on board
//#define MY_DISPLAY_FLIP 1 // uncomment this for rotated display
#define HAS_LED 22 // ESP32 GPIO12 (pin22) On Board LED
#define HAS_LED 22 // ESP32 GPIO12 (pin22) On Board LED (set to NOT_A_PIN to disable)
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_13) // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
#define HAS_BUTTON 15 // ESP32 GPIO15 (pin15) Button is on the LoraNode32 shield

View File

@ -14,7 +14,7 @@
#define HAS_DISPLAY 1 // OLED-Display on board
//#define MY_DISPLAY_FLIP 1 // uncomment this for rotated display
#define HAS_LED LED_BUILTIN
#define HAS_LED LED_BUILTIN // set to NOT_A_PIN to disable
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
#define HAS_BUTTON KEY_BUILTIN

View File

@ -21,6 +21,7 @@
//#define HAS_DISPLAY 1
//#define HAS_LED (25) // green on board LED
#define HAS_LED NOT_A_PIN
#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board

View File

@ -91,11 +91,6 @@ function decodeUplink(input) {
}
}
if (input.fPort === 10) {
// ENS count
data = decode(input.bytes, [uint16], ['ens']);
}
data.bytes = input.bytes; // comment out if you do not want to include the original payload
data.port = input.fPort; // comment out if you do not want to inlude the port

View File

@ -337,15 +337,9 @@ void setup() {
// initialize sensors
#if (HAS_SENSORS)
#if (HAS_SENSOR_1)
#if (COUNT_ENS)
ESP_LOGI(TAG, "init CWA-counter");
if (cwa_init())
strcat_P(features, " CWA");
#else
strcat_P(features, " SENS(1)");
sensor_init();
#endif
#endif
#if (HAS_SENSOR_2)
strcat_P(features, " SENS(2)");
sensor_init();

View File

@ -27,10 +27,6 @@
#define BLESCANWINDOW 80 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms
#define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle
// Corona Exposure Notification Service(ENS) counter
#define COUNT_ENS 0 // count found number of devices which advertise Exposure Notification Service
// set to 1 if you want to enable this function [default=0]
/* Note: guide for setting bluetooth parameters
*
* |< Scan Window > |< Scan Window > | ... |< Scan Window > |

View File

@ -397,15 +397,6 @@ 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 |= (uint8_t)SENSOR1_DATA;
else
cfg.payloadmask &= (uint8_t)~SENSOR1_DATA;
}
void set_loadconfig(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: load config from NVRAM");
loadConfig();
@ -430,7 +421,7 @@ static const cmd_t table[] = {
{0x10, set_rgblum, 1}, {0x13, set_sensor, 2},
{0x14, set_payloadmask, 1}, {0x15, set_bme, 1},
{0x16, set_batt, 1}, {0x17, set_wifiscan, 1},
{0x18, set_enscount, 1}, {0x19, set_sleepcycle, 2},
{0x18, set_flush, 0}, {0x19, set_sleepcycle, 2},
{0x20, set_loadconfig, 0}, {0x21, set_saveconfig, 0},
{0x80, get_config, 0}, {0x81, get_status, 0},
{0x83, get_batt, 0}, {0x84, get_gps, 0},

View File

@ -126,6 +126,11 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {
sds011_sleep();
#endif
// flush & close sd card, if we have
#if (HAS_SDCARD)
sdcard_close();
#endif
// wait a while (max 100 sec) to clear send queues
ESP_LOGI(TAG, "Waiting until send queues are empty...");
for (i = 100; i > 0; i--) {

View File

@ -13,7 +13,13 @@ static void createFile(void);
File fileSDCard;
bool sdcard_init() {
bool sdcard_close(void) {
ESP_LOGD(TAG, "unmounting SD-card");
fileSDCard.flush();
fileSDCard.end();
}
bool sdcard_init(bool create) {
ESP_LOGI(TAG, "looking for SD-card...");
// for usage of SD drivers on ESP32 platform see

View File

@ -159,10 +159,6 @@ void sendData() {
payload.reset();
payload.addSensor(sensor_read(1));
SendPayload(SENSOR1PORT);
#if (COUNT_ENS)
if (cfg.countermode != 1)
cwa_clear();
#endif
break;
#endif
#if (HAS_SENSOR_2)

View File

@ -2,12 +2,6 @@
#include "globals.h"
#include "sensor.h"
#if (COUNT_ENS)
#include "payload.h"
#include "corona.h"
extern PayloadConvert payload;
#endif
// Local logging tag
static const char TAG[] = __FILE__;
@ -53,16 +47,10 @@ uint8_t *sensor_read(uint8_t sensor) {
case 1:
// insert user specific sensor data frames here
// note: Sensor1 fields are used for ENS count, if ENS detection enabled
#if (COUNT_ENS)
if (cfg.enscount)
payload.addCount(cwa_report(), MAC_SNIFF_BLE_ENS);
#else
buf[0] = length;
buf[1] = 0x01;
buf[2] = 0x02;
buf[3] = 0x03;
#endif
break;
case 2: