Skip to content

Commit

Permalink
Merge pull request #641 from cyberman54/master
Browse files Browse the repository at this point in the history
sync dev to master
  • Loading branch information
cyberman54 authored Sep 27, 2020
2 parents 8f054ea + 3e01029 commit 4d2bde6
Show file tree
Hide file tree
Showing 25 changed files with 283 additions and 184 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Some <b>3D printable cases</b> can be found (and, if wanted so, ordered) on Thin
for example.<br>

<b>Power consumption</b> was metered at around 450 - 1000mW, depending on board and user settings in paxcounter.conf.
By default bluetooth sniffing is disabled (#define *BLECOUNTER* 0 in paxcounter.conf). Enabling bluetooth costs 30% more power + 30% flash storage for the software stack. Proof of concept showed that for passenger flow metering wifi sniffing shows better results than bluetooth sniffing. If you enable bluetooth be aware that this goes on expense of wifi sniffing results, because then wifi and bt stack must share the 2,4 GHz RF ressources of ESP32. If you need to sniff wifi and bt in parallel and need best possible results, use two boards - one for wifi only and one for bt only - and add counted results.
By default bluetooth sniffing not installed (#define *BLECOUNTER* 0 in paxcounter.conf). Installing and enabling bluetooth costs 30% more power + 30% flash storage for the software stack. If you enable bluetooth be aware that this goes on expense of wifi sniffing results, because then wifi and bt stack must share the 2,4 GHz RF ressources of ESP32. If you need to sniff wifi and bt in parallel and need best possible results, use two boards - one for wifi only and one for bt only - and add counted results.

# Preparing

Expand Down Expand Up @@ -200,12 +200,24 @@ Paxcounter can keep it's time-of-day synced with an external time source. Set *#
Paxcounter can be used to sync a wall clock which has a DCF77 or IF482 time telegram input. Set *#define HAS_IF482* or *#define HAS_DCF77* in board's hal file to setup clock controller. Use case of this function is to integrate paxcounter and clock. Accurary of the synthetic DCF77 signal depends on accuracy of on board's time base, see above.

# mobile PaxCounter via https://opensensemap.org/

This describes how to set up a mobile PaxCounter:
Follow all steps so far for preparing the device, use the packed payload format. In paxcounter.conf set PAYLOAD_OPENSENSEBOX to 1. Register a new sensbox on https://opensensemap.org/.
Follow all steps so far for preparing the device, use the packed payload format. In [paxcounter.conf](src/paxcounter.conf) set PAYLOAD_OPENSENSEBOX to 1. Register a new sensbox on https://opensensemap.org/.
There in the sensor configuration select "TheThingsNetwork" and set Decoding Profil to "LoRa serialization", enter your TTN Application and Device Id. Decoding option has to be
[{"decoder":"latLng"},{"decoder":"uint16","sensor_id":"yoursensorid"}]

# Covid-19 Exposure Notification System beacon detection (Germany: "Corona Warn App counter")

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 gives an indication 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 resulta withs this funcion, use following settings in [paxcounter.conf](src/paxcounter.conf):

#define COUNT_ENS 1 // enable ENS monitoring function
#define VENDORFILTER 0 // disable OUI filter (scans ALL device MACs)
#define BLECOUNTER 1 // enable bluetooth sniffing
#define WIFICOUNTER 0 // disable wifi sniffing (improves BLE scan speed)
#define HAS_SENSOR_1 1 // optional: 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:

#define HAS_SDCARD 1 // SD-card-reader/writer, using SPI interface
Expand Down Expand Up @@ -348,6 +360,9 @@ The device listenes for remote control commands on LoRaWAN Port 2. Multiple comm

Note: all settings are stored in NVRAM and will be reloaded when device starts.

Send for example `8386` as Downlink on Port 2 to get battery status and time/date from the device.
<img src="img/paxcounter_downlink_example.png">

0x01 set scan RSSI limit

1 ... 255 used for wifi and bluetooth scan radius (greater values increase scan radius, values 50...110 make sense)
Expand Down Expand Up @@ -527,9 +542,9 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.

# License

Copyright 2018 Oliver Brandmueller <ob@sysadm.in>
Copyright 2018-2020 Oliver Brandmueller <ob@sysadm.in>

Copyright 2018 Klaus Wilting <verkehrsrot@arcor.de>
Copyright 2018-2020 Klaus Wilting <verkehrsrot@arcor.de>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -556,4 +571,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 and SDS011 support
- [August Quint](https://github.com/AugustQu) for adding SD card data logger, SDS011 and ENS support
Binary file added img/paxcounter_downlink_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 0 additions & 77 deletions include/coexist_internal.h

This file was deleted.

16 changes: 16 additions & 0 deletions include/corona.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#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
5 changes: 3 additions & 2 deletions include/macsniff.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

#define MAC_SNIFF_WIFI 0
#define MAC_SNIFF_BLE 1
#define MAC_SNIFF_BLE_CWA 2

uint16_t get_salt(void);
uint64_t macConvert(uint8_t *paddr);
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
uint16_t mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
void printKey(const char *name, const uint8_t *key, uint8_t len, bool lsb);

#endif
#endif
4 changes: 2 additions & 2 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <esp_spi_flash.h> // needed for reading ESP32 chip attributes
#include <esp_event_loop.h> // needed for Wifi event handler
#include <esp32-hal-timer.h> // needed for timers
#include <esp_coexist.h> // needed for showing coex sw version

#include "globals.h"
#include "reset.h"
Expand All @@ -20,5 +19,6 @@
#include "sensor.h"
#include "lorawan.h"
#include "timekeeper.h"
#include "corona.h"

#endif
#endif
12 changes: 7 additions & 5 deletions include/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#include <stdio.h>
#include <SPI.h>

#ifdef HAS_SDCARD
#if (HAS_SDCARD)
#if HAS_SDCARD == 1
#include <mySD.h>
//#include <SD.h>
#elif HAS_SDCARD == 2
#include <SD_MMC.h>
#else
Expand Down Expand Up @@ -39,8 +38,11 @@
#define SDCARD_FILE_NAME "/paxcount.%02d"
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"

#if (COUNT_ENS)
#define SDCARD_FILE_HEADER_CWA ",cwa"
#endif

bool sdcard_init(void);
void sdcardWriteData(uint16_t, uint16_t);
static void createFile(void);
void sdcardWriteData(uint16_t, uint16_t, uint16_t = 0);

#endif
#endif // _SDCARD_H
1 change: 1 addition & 0 deletions include/senddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "lorawan.h"
#include "display.h"
#include "sdcard.h"
#include "corona.h"

extern Ticker sendcycler;

Expand Down
2 changes: 0 additions & 2 deletions include/wifiscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// ESP32 Functions
#include <esp_wifi.h>
#include <esp_coexist.h>
#include "coexist_internal.h"

#include "hash.h" // Hash function for scrambling MAC addresses
#include "antenna.h" // code for switching wifi antennas
Expand Down
51 changes: 26 additions & 25 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,53 @@ halfile = generic.h

[platformio]
; upload firmware to board with usb cable
;default_envs = usb
default_envs = usb
; upload firmware to a jfrog bintray repository
;default_envs = ota
; use latest versions of libraries
default_envs = dev
;default_envs = dev
description = Paxcounter is a device for metering passenger flows in realtime. It counts how many mobile devices are around.

[common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.9.996
release_version = 2.0.12
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 4
debug_level = 3
extra_scripts = pre:build.py
otakeyfile = ota.conf
lorakeyfile = loraconf.h
lmicconfigfile = lmic_config.h
platform_espressif32 = espressif32@1.12.4
platform_espressif32 = espressif32@2.0.0
monitor_speed = 115200
upload_speed = 115200 ; set by build.py and taken from hal file
display_library = ; set by build.py and taken from hal file
lib_deps_lora =
MCCI LoRaWAN LMIC library@3.2.0 ; MCCI LMIC by Terrill Moore
mcci-catena/MCCI LoRaWAN LMIC library @ ^3.2.0
lib_deps_display =
OneBitDisplay@1.5.0
QRCode@0.0.1
BitBang_I2C@2.1.1
TFT_eSPI@>=2.2.8
bitbank2/OneBitDisplay @ 1.5.0
ricmoo/QRCode @ ^0.0.1
bodmer/TFT_eSPI @ ^2.2.20
lib_deps_ledmatrix =
Ultrathin_LED_Matrix@>=1.0.0
seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0
lib_deps_rgbled =
SmartLeds@>=1.2.0
roboticsbrno/SmartLeds @ ^1.2.1
lib_deps_gps =
1655@>=1.0.2 ; #1655 TinyGPSPlus by Mikal Hart
mikalhart/TinyGPSPlus @ ^1.0.2
lib_deps_sensors =
Adafruit Unified Sensor@>=1.1.4
Adafruit BME280 Library@>=2.0.2
Adafruit BMP085 Library@>=1.1.0
BSEC Software Library@1.5.1474
adafruit/Adafruit Unified Sensor @ ^1.1.4
adafruit/Adafruit BME280 Library @ ^2.1.0
adafruit/Adafruit BMP085 Library @ ^1.1.0
boschsensortec/BSEC Software Library @ 1.5.1474
https://github.com/ricki-z/SDS011.git
lib_deps_basic =
ArduinoJson@<6
76@>=1.2.4 ; #76 Timezone by Jack Christensen
274@>=2.3.5 ; #274 RTC by Michael Miller
SimpleButton
AXP202X_Library@>=1.1.2 ; AXP202 PMU lib by Lewis He
esp32-micro-sdcard
MQTT@>=2.4.7 ; MQTT client maintained by Joel Gaehwiler
bblanchon/ArduinoJson @ <6
jchristensen/Timezone @ ^1.2.4
makuna/RTC @ ^2.3.5
spacehuhn/SimpleButton
lewisxhe/AXP202X_Library @ ^1.1.2
geeksville/esp32-micro-sdcard @ ^0.1.1
256dpi/MQTT @ ^2.4.7
lib_deps_all =
${common.lib_deps_basic}
${common.lib_deps_lora}
Expand All @@ -109,17 +108,19 @@ build_flags_all =
-mfix-esp32-psram-cache-issue

[env]
lib_ldf_mode = deep ; #632 Fixes compiler error with OneBitDisplay library
framework = arduino
board = esp32dev
board_build.partitions = min_spiffs.csv
upload_speed = ${common.upload_speed}
;upload_port = COM7
;upload_port = COM8
platform = ${common.platform_espressif32}
lib_deps = ${common.lib_deps_all}
build_flags = ${common.build_flags_all}
upload_protocol = ${common.upload_protocol}
extra_scripts = ${common.extra_scripts}
monitor_speed = ${common.monitor_speed}
monitor_filters = time, esp32_exception_decoder, default

[env:ota]
upload_protocol = custom
Expand Down
Loading

0 comments on commit 4d2bde6

Please sign in to comment.