change default to bluetooth disabled

This commit is contained in:
Klaus K Wilting 2018-12-02 14:08:50 +01:00
parent 8d22695114
commit decb8b7181
18 changed files with 163 additions and 49 deletions

View File

@ -55,7 +55,8 @@ Hardware dependent settings (pinout etc.) are stored in board files in /hal dire
<b>3D printable cases</b> can be found (and, if wanted so, ordered) on Thingiverse, see <b>3D printable cases</b> can be found (and, if wanted so, ordered) on Thingiverse, see
<A HREF="https://www.thingiverse.com/thing:2670713">Heltec</A>, <A HREF="https://www.thingiverse.com/thing:2811127">TTGOv2</A>, <A HREF="https://www.thingiverse.com/thing:3005574">TTGOv2.1</A>, <A HREF="https://www.thingiverse.com/thing:3041339">T-BEAM</A> for example.<br> <A HREF="https://www.thingiverse.com/thing:2670713">Heltec</A>, <A HREF="https://www.thingiverse.com/thing:2811127">TTGOv2</A>, <A HREF="https://www.thingiverse.com/thing:3005574">TTGOv2.1</A>, <A HREF="https://www.thingiverse.com/thing:3041339">T-BEAM</A> for example.<br>
<b>Power consumption</b> was metered at around 450 - 1000mW, depending on board and user settings in paxcounter.conf. If you are limited on battery, you may want to save around 30% power by disabling bluetooth (commenting out line *#define BLECOUNTER* in paxcounter.conf). <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 (line *#define BLECOUNTER* in paxcounter.conf is commented out). Enabling bluetooth costs 30% more power + 30% flash storage for the software stack. Proof of concept showed that for passenger flow metering purpose 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 stack gets less access to RF ressources of ESP32.
# Preparing # Preparing

View File

@ -0,0 +1,77 @@
// Copyright 2018-2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __COEXIST_INTERNAL_H__
#define __COEXIST_INTERNAL_H__
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
COEX_PREFER_WIFI = 0,
COEX_PREFER_BT,
COEX_PREFER_BALANCE,
COEX_PREFER_NUM,
} coex_prefer_t;
/**
* @brief Init software coexist
* extern function for internal use.
*
* @return Init ok or failed.
*/
esp_err_t coex_init(void);
/**
* @brief De-init software coexist
* extern function for internal use.
*/
void coex_deinit(void);
/**
* @brief Pause software coexist
* extern function for internal use.
*/
void coex_pause(void);
/**
* @brief Resume software coexist
* extern function for internal use.
*/
void coex_resume(void);
/**
* @brief Get software coexist version string
* extern function for internal use.
* @return : version string
*/
const char *coex_version_get(void);
/**
* @brief Coexist performance preference set from libbt.a
* extern function for internal use.
*
* @param prefer : the prefer enumeration value
* @return : ESP_OK - success, other - failed
*/
esp_err_t coex_preference_set(coex_prefer_t prefer);
#ifdef __cplusplus
}
#endif
#endif /* __COEXIST_INTERNAL_H__ */

View File

@ -9,6 +9,10 @@
#include <array> #include <array>
#include <algorithm> #include <algorithm>
// sniffing types
#define MAC_SNIFF_WIFI 0
#define MAC_SNIFF_BLE 1
// bits in payloadmask for filtering payload data // bits in payloadmask for filtering payload data
#define GPS_DATA (0x01) #define GPS_DATA (0x01)
#define ALARM_DATA (0x02) #define ALARM_DATA (0x02)
@ -93,6 +97,7 @@ extern TaskHandle_t irqHandlerTask, wifiSwitchTask;
#include "led.h" #include "led.h"
#include "payload.h" #include "payload.h"
#include "blescan.h"
#ifdef HAS_GPS #ifdef HAS_GPS
#include "gpsread.h" #include "gpsread.h"
@ -114,10 +119,6 @@ extern TaskHandle_t irqHandlerTask, wifiSwitchTask;
#include "button.h" #include "button.h"
#endif #endif
#ifdef BLECOUNTER
#include "blescan.h"
#endif
#ifdef HAS_BATTERY_PROBE #ifdef HAS_BATTERY_PROBE
#include "battery.h" #include "battery.h"
#endif #endif

View File

@ -16,4 +16,7 @@
#include "spislave.h" #include "spislave.h"
#include "lorawan.h" #include "lorawan.h"
#include <esp_coexist.h>
#include "coexist_internal.h"
#endif #endif

View File

@ -39,7 +39,7 @@ public:
void reset(void); void reset(void);
uint8_t getSize(void); uint8_t getSize(void);
uint8_t *getBuffer(void); uint8_t *getBuffer(void);
void addCount(uint16_t value1, uint16_t value2); void addCount(uint16_t value, uint8_t sniffytpe);
void addConfig(configData_t value); void addConfig(configData_t value);
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem, void addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem,
uint8_t reset1, uint8_t reset2); uint8_t reset1, uint8_t reset2);

View File

@ -7,9 +7,6 @@
// Hash function for scrambling MAC addresses // Hash function for scrambling MAC addresses
#include "hash.h" #include "hash.h"
#define MAC_SNIFF_WIFI 0
#define MAC_SNIFF_BLE 1
void wifi_sniffer_init(void); void wifi_sniffer_init(void);
void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
void switchWifiChannel(void * parameter); void switchWifiChannel(void * parameter);

View File

@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
[common] [common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c" ; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.6.971 release_version = 1.6.98
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 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 ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 0 debug_level = 0
@ -38,12 +38,12 @@ upload_protocol = esptool
;upload_protocol = custom ;upload_protocol = custom
extra_scripts = pre:build.py extra_scripts = pre:build.py
keyfile = ota.conf keyfile = ota.conf
platform_espressif32 = espressif32@1.5.0 ;platform_espressif32 = espressif32@1.5.0
;platform_espressif32 = https://github.com/platformio/platform-espressif32.git#a7b1fe6 platform_espressif32 = https://github.com/platformio/platform-espressif32.git#feature/stage
board_build.partitions = min_spiffs.csv board_build.partitions = min_spiffs.csv
monitor_speed = 115200 monitor_speed = 115200
lib_deps_lora = lib_deps_lora =
MCCI LoRaWAN LMIC library@2.3.0 MCCI LoRaWAN LMIC library@2.3.1
lib_deps_display = lib_deps_display =
U8g2@>=2.25.0 U8g2@>=2.25.0
lib_deps_rgbled = lib_deps_rgbled =

View File

@ -4,9 +4,16 @@
function Converter(decoded, port) { function Converter(decoded, port) {
var converted = decoded; var converted = decoded;
var pax = 0;
if (port === 1) { if (port === 1) {
converted.pax = converted.ble + converted.wifi;
for (var x in converted) {
pax += converted[x];
}
converted.pax = pax;
} }
if (port === 2) { if (port === 2) {

View File

@ -6,7 +6,11 @@ function Decoder(bytes, port) {
var decoded = {}; var decoded = {};
if (port === 1) { if (port === 1) {
// only counter data, no gps // only wifi counter data, no gps
if (bytes.length === 2) {
return decode(bytes, [uint16], ['wifi']);
}
// wifi + ble counter data, no gps
if (bytes.length === 4) { if (bytes.length === 4) {
return decode(bytes, [uint16, uint16], ['wifi', 'ble']); return decode(bytes, [uint16, uint16], ['wifi', 'ble']);
} }

View File

@ -7,8 +7,11 @@ function Decoder(bytes, port) {
if (port === 1) { if (port === 1) {
var i = 0; var i = 0;
decoded.wifi = (bytes[i++] << 8) | bytes[i++]; if (bytes.length >= 2) {
decoded.ble = (bytes[i++] << 8) | bytes[i++]; decoded.wifi = (bytes[i++] << 8) | bytes[i++];}
if (bytes.length >= 4) {
decoded.ble = (bytes[i++] << 8) | bytes[i++];}
if (bytes.length > 4) { if (bytes.length > 4) {
decoded.latitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); decoded.latitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);

View File

@ -243,7 +243,10 @@ esp_err_t register_ble_callback(void) {
} // register_ble_callback } // register_ble_callback
#endif // BLECOUNTER
void start_BLEscan(void) { void start_BLEscan(void) {
#ifdef BLECOUNTER
ESP_LOGI(TAG, "Initializing bluetooth scanner ..."); ESP_LOGI(TAG, "Initializing bluetooth scanner ...");
// Initialize BT controller to allocate task and other resource. // Initialize BT controller to allocate task and other resource.
@ -255,15 +258,16 @@ void start_BLEscan(void) {
ESP_ERROR_CHECK(register_ble_callback()); ESP_ERROR_CHECK(register_ble_callback());
ESP_LOGI(TAG, "Bluetooth scanner started"); ESP_LOGI(TAG, "Bluetooth scanner started");
#endif // BLECOUNTER
} // start_BLEscan } // start_BLEscan
void stop_BLEscan(void) { void stop_BLEscan(void) {
#ifdef BLECOUNTER
ESP_LOGI(TAG, "Shutting down bluetooth scanner ..."); ESP_LOGI(TAG, "Shutting down bluetooth scanner ...");
ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL)); ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL));
ESP_ERROR_CHECK(esp_bluedroid_disable()); ESP_ERROR_CHECK(esp_bluedroid_disable());
ESP_ERROR_CHECK(esp_bluedroid_deinit()); ESP_ERROR_CHECK(esp_bluedroid_deinit());
btStop(); // disable & deinit bt_controller btStop(); // disable & deinit bt_controller
ESP_LOGI(TAG, "Bluetooth scanner stopped"); ESP_LOGI(TAG, "Bluetooth scanner stopped");
} // stop_BLEscan
#endif // BLECOUNTER #endif // BLECOUNTER
} // stop_BLEscan

View File

@ -25,7 +25,7 @@ void defaultConfig() {
cfg.blescantime = cfg.blescantime =
BLESCANINTERVAL / BLESCANINTERVAL /
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms) 10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
cfg.blescan = 1; // 0=disabled, 1=enabled cfg.blescan = 0; // 0=disabled, 1=enabled
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
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%)

View File

@ -106,6 +106,7 @@ void setup() {
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded"
: "external"); : "external");
ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion()); ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion());
ESP_LOGI(TAG, "Wifi/BT software coexist version: %s", esp_coex_version_get());
ESP_LOGI(TAG, "Free RAM: %d bytes", ESP.getFreeHeap()); ESP_LOGI(TAG, "Free RAM: %d bytes", ESP.getFreeHeap());
#ifdef HAS_GPS #ifdef HAS_GPS

View File

@ -15,7 +15,7 @@
// Set this to include BLE counting and vendor filter functions // Set this to include BLE counting and vendor filter functions
#define VENDORFILTER 1 // comment out if you want to count things, not people #define VENDORFILTER 1 // comment out if you want to count things, not people
#define BLECOUNTER 1 // comment out if you don't want BLE count, saves power & memory //#define BLECOUNTER 1 // activate if you want BLE count, at expense of power & memory
// BLE scan parameters // BLE scan parameters
#define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below #define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below
@ -74,7 +74,7 @@
#define BME_TEMP_OFFSET 5.0f // Offset sensor on chip temp <-> ambient temp [default = 5°C] #define BME_TEMP_OFFSET 5.0f // Offset sensor on chip temp <-> ambient temp [default = 5°C]
// OTA settings // OTA settings
//#define USE_OTA 1 // Comment out to disable OTA update #define USE_OTA 1 // Comment out to disable OTA update
#define WIFI_MAX_TRY 5 // maximum number of wifi connect attempts for OTA update [default = 20] #define WIFI_MAX_TRY 5 // maximum number of wifi connect attempts for OTA update [default = 20]
#define OTA_MAX_TRY 5 // maximum number of attempts for OTA download and write to flash [default = 3] #define OTA_MAX_TRY 5 // maximum number of attempts for OTA download and write to flash [default = 3]
#define OTA_MIN_BATT 3600 // minimum battery level for OTA [millivolt] #define OTA_MIN_BATT 3600 // minimum battery level for OTA [millivolt]

View File

@ -18,11 +18,9 @@ uint8_t *PayloadConvert::getBuffer(void) { return buffer; }
#if PAYLOAD_ENCODER == 1 #if PAYLOAD_ENCODER == 1
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) {
buffer[cursor++] = highByte(value1); buffer[cursor++] = highByte(value);
buffer[cursor++] = lowByte(value1); buffer[cursor++] = lowByte(value);
buffer[cursor++] = highByte(value2);
buffer[cursor++] = lowByte(value2);
} }
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) { void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
@ -135,10 +133,7 @@ void PayloadConvert::addButton(uint8_t value) {
#elif PAYLOAD_ENCODER == 2 #elif PAYLOAD_ENCODER == 2
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) { writeUint16(value); }
writeUint16(value1);
writeUint16(value2);
}
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) { void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
writeUint8(rssi); writeUint8(rssi);
@ -286,21 +281,27 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f,
#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4) #elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4)
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) {
select(snifftype) {
case MAC_SNIFF_WIFI:
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL; buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
#endif #endif
buffer[cursor++] = buffer[cursor++] =
LPP_LUMINOSITY; // workaround since cayenne has no data type meter LPP_LUMINOSITY; // workaround since cayenne has no data type meter
buffer[cursor++] = highByte(value1); buffer[cursor++] = highByte(value);
buffer[cursor++] = lowByte(value1); buffer[cursor++] = lowByte(value);
break;
case MAC_SNIFF_BLE:
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL; buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
#endif #endif
buffer[cursor++] = buffer[cursor++] =
LPP_LUMINOSITY; // workaround since cayenne has no data type meter LPP_LUMINOSITY; // workaround since cayenne has no data type meter
buffer[cursor++] = highByte(value2); buffer[cursor++] = highByte(value);
buffer[cursor++] = lowByte(value2); buffer[cursor++] = lowByte(value);
break;
}
} }
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) { void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {

View File

@ -79,13 +79,11 @@ void set_blescantime(uint8_t val[]) {
cfg.blescantime = val[0]; cfg.blescantime = val[0];
ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds", ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds",
cfg.blescantime / float(100)); cfg.blescantime / float(100));
#ifdef BLECOUNTER
// stop & restart BLE scan task to apply new parameter // stop & restart BLE scan task to apply new parameter
if (cfg.blescan) { if (cfg.blescan) {
stop_BLEscan(); stop_BLEscan();
start_BLEscan(); start_BLEscan();
} }
#endif
} }
void set_countmode(uint8_t val[]) { void set_countmode(uint8_t val[]) {
@ -193,14 +191,12 @@ void set_loraadr(uint8_t val[]) {
void set_blescan(uint8_t val[]) { void set_blescan(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
cfg.blescan = val[0] ? 1 : 0; cfg.blescan = val[0] ? 1 : 0;
#ifdef BLECOUNTER
if (cfg.blescan) if (cfg.blescan)
start_BLEscan(); start_BLEscan();
else { else {
macs_ble = 0; // clear BLE counter macs_ble = 0; // clear BLE counter
stop_BLEscan(); stop_BLEscan();
} }
#endif
} }
void set_wifiant(uint8_t val[]) { void set_wifiant(uint8_t val[]) {

View File

@ -40,7 +40,9 @@ void sendCounter() {
case COUNT_DATA: case COUNT_DATA:
payload.reset(); payload.reset();
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0); payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
if (cfg.blescan)
payload.addCount(macs_ble, MAC_SNIFF_BLE);
SendPayload(COUNTERPORT); SendPayload(COUNTERPORT);
// clear counter if not in cumulative counter mode // clear counter if not in cumulative counter mode
if (cfg.countermode != 1) { if (cfg.countermode != 1) {

View File

@ -1,6 +1,8 @@
// Basic Config // Basic Config
#include "globals.h" #include "globals.h"
#include "wifiscan.h" #include "wifiscan.h"
#include <esp_coexist.h>
#include "coexist_internal.h"
// Local logging tag // Local logging tag
static const char TAG[] = "wifi"; static const char TAG[] = "wifi";
@ -9,6 +11,8 @@ static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN,
WIFI_CHANNEL_MAX, 100, WIFI_CHANNEL_MAX, 100,
WIFI_COUNTRY_POLICY_MANUAL}; WIFI_COUNTRY_POLICY_MANUAL};
esp_coex_prefer_t coexist_config = ESP_COEX_PREFER_BALANCE;
typedef struct { typedef struct {
unsigned frame_ctrl : 16; unsigned frame_ctrl : 16;
unsigned duration_id : 16; unsigned duration_id : 16;
@ -41,6 +45,12 @@ IRAM_ATTR void wifi_sniffer_packet_handler(void *buff,
mac_add((uint8_t *)hdr->addr2, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI); mac_add((uint8_t *)hdr->addr2, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI);
} }
const char *esp_coex_version_get(void) { return coex_version_get(); }
esp_err_t esp_coex_preference_set(esp_coex_prefer_t prefer) {
return coex_preference_set((coex_prefer_t)prefer);
}
void wifi_sniffer_init(void) { void wifi_sniffer_init(void) {
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM cfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM
@ -49,6 +59,13 @@ void wifi_sniffer_init(void) {
// .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames // .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames
.filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames
coex_pause();
ESP_ERROR_CHECK(
esp_coex_preference_set(coexist_config)); // configure Wifi/BT coexist lib
coex_resume();
//coex_deinit();
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); // configure Wifi with cfg ESP_ERROR_CHECK(esp_wifi_init(&cfg)); // configure Wifi with cfg
ESP_ERROR_CHECK( ESP_ERROR_CHECK(
esp_wifi_set_country(&wifi_country)); // set locales for RF and channels esp_wifi_set_country(&wifi_country)); // set locales for RF and channels