From 0ed5f73b2cc70e23a0752022f667e16c9a7e53b2 Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Sun, 10 Nov 2019 08:00:28 +0000 Subject: [PATCH 01/21] compile flag for do no payload reset --- src/paxcounter.conf | 3 ++- src/senddata.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 1e39ece9..96d424b0 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -47,6 +47,7 @@ #define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle #define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results #define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit +#define PAYLOAD_COMBINE 0 // 0/1 does combine data on same port into one combined payload message #define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5] #define LORATXPOWDEFAULT 14 // 0 .. 255, LoRaWAN TX power in dBm [default = 14] #define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy @@ -92,7 +93,7 @@ #define RCMDPORT 2 // remote commands #define STATUSPORT 2 // remote command results #define CONFIGPORT 3 // config query results -#define GPSPORT 4 // gps +#define GPSPORT 1 // gps #define BUTTONPORT 5 // button pressed signal #define BEACONPORT 6 // beacon alarms #define BMEPORT 7 // BME680 sensor diff --git a/src/senddata.cpp b/src/senddata.cpp index 11b0d81a..2c04df02 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -84,7 +84,9 @@ void sendData() { #if (HAS_BME) case MEMS_DATA: +#if !(PAYLOAD_COMBINE) payload.reset(); +#endif payload.addBME(bme_status); SendPayload(BMEPORT, prio_normal); break; @@ -96,7 +98,9 @@ void sendData() { if (gps.location.isValid()) { gpsStatus_t gps_status; gps_storelocation(&gps_status); +#if !(PAYLOAD_COMBINE) payload.reset(); +#endif payload.addGPS(gps_status); SendPayload(GPSPORT, prio_high); } else @@ -106,17 +110,23 @@ void sendData() { #if (HAS_SENSORS) case SENSOR1_DATA: +#if !(PAYLOAD_COMBINE) payload.reset(); +#endif payload.addSensor(sensor_read(1)); SendPayload(SENSOR1PORT, prio_normal); break; case SENSOR2_DATA: +#if !(PAYLOAD_COMBINE) payload.reset(); +#endif payload.addSensor(sensor_read(2)); SendPayload(SENSOR2PORT, prio_normal); break; case SENSOR3_DATA: +#if !(PAYLOAD_COMBINE) payload.reset(); +#endif payload.addSensor(sensor_read(3)); SendPayload(SENSOR3PORT, prio_normal); break; @@ -124,7 +134,9 @@ void sendData() { #if (defined BAT_MEASURE_ADC || defined HAS_PMU) case BATT_DATA: +#if !(PAYLOAD_COMBINE) payload.reset(); +#endif payload.addVoltage(read_voltage()); SendPayload(BATTPORT, prio_normal); break; From ab82374bfaf1ccfefbeb072049bde11af68e6eca Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Sun, 17 Nov 2019 09:32:43 +0000 Subject: [PATCH 02/21] less generic, only advanced gps+counter --- src/paxcounter.conf | 3 +-- src/senddata.cpp | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 96d424b0..b7aa5033 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -47,7 +47,6 @@ #define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle #define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results #define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit -#define PAYLOAD_COMBINE 0 // 0/1 does combine data on same port into one combined payload message #define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5] #define LORATXPOWDEFAULT 14 // 0 .. 255, LoRaWAN TX power in dBm [default = 14] #define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy @@ -93,7 +92,7 @@ #define RCMDPORT 2 // remote commands #define STATUSPORT 2 // remote command results #define CONFIGPORT 3 // config query results -#define GPSPORT 1 // gps +#define GPSPORT 4 // gps - set to 1 to send combined GPS+COUNT payload #define BUTTONPORT 5 // button pressed signal #define BEACONPORT 6 // beacon alarms #define BMEPORT 7 // BME680 sensor diff --git a/src/senddata.cpp b/src/senddata.cpp index 2c04df02..d18826fe 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -68,6 +68,15 @@ void sendData() { payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); +#if (HAS_GPS) && (GPSPORT==1) + // send GPS position only if we have a fix + if (gps.location.isValid()) { + gpsStatus_t gps_status; + gps_storelocation(&gps_status); + payload.addGPS(gps_status); + } else + ESP_LOGD(TAG, "No valid GPS position"); +#endif SendPayload(COUNTERPORT, prio_normal); // clear counter if not in cumulative counter mode if (cfg.countermode != 1) { @@ -84,23 +93,19 @@ void sendData() { #if (HAS_BME) case MEMS_DATA: -#if !(PAYLOAD_COMBINE) payload.reset(); -#endif payload.addBME(bme_status); SendPayload(BMEPORT, prio_normal); break; #endif -#if (HAS_GPS) +#if (HAS_GPS) && (GPSPORT!=1) case GPS_DATA: // send GPS position only if we have a fix if (gps.location.isValid()) { gpsStatus_t gps_status; gps_storelocation(&gps_status); -#if !(PAYLOAD_COMBINE) payload.reset(); -#endif payload.addGPS(gps_status); SendPayload(GPSPORT, prio_high); } else @@ -110,23 +115,17 @@ void sendData() { #if (HAS_SENSORS) case SENSOR1_DATA: -#if !(PAYLOAD_COMBINE) payload.reset(); -#endif payload.addSensor(sensor_read(1)); SendPayload(SENSOR1PORT, prio_normal); break; case SENSOR2_DATA: -#if !(PAYLOAD_COMBINE) payload.reset(); -#endif payload.addSensor(sensor_read(2)); SendPayload(SENSOR2PORT, prio_normal); break; case SENSOR3_DATA: -#if !(PAYLOAD_COMBINE) payload.reset(); -#endif payload.addSensor(sensor_read(3)); SendPayload(SENSOR3PORT, prio_normal); break; @@ -134,9 +133,7 @@ void sendData() { #if (defined BAT_MEASURE_ADC || defined HAS_PMU) case BATT_DATA: -#if !(PAYLOAD_COMBINE) payload.reset(); -#endif payload.addVoltage(read_voltage()); SendPayload(BATTPORT, prio_normal); break; From 40248d60c3d23626546dcf92e0c4126c88c9705c Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Sun, 17 Nov 2019 09:44:41 +0000 Subject: [PATCH 03/21] increment version --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 97e33211..d7c1c122 100644 --- a/platformio.ini +++ b/platformio.ini @@ -43,7 +43,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.71 +release_version = 1.9.72 ; 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 = 3 From be448a37a39bdfbe954a2e1c1169a466ad2ff8cf Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Tue, 19 Nov 2019 22:27:12 +0000 Subject: [PATCH 04/21] OpenSenseBox specific payload --- include/globals.h | 2 ++ src/TTN/packed_decoder.js | 8 ++++++++ src/gpsread.cpp | 2 ++ src/paxcounter.conf | 3 ++- src/payload.cpp | 2 ++ src/senddata.cpp | 8 +++++++- 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/globals.h b/include/globals.h index aaecfceb..5b61fa58 100644 --- a/include/globals.h +++ b/include/globals.h @@ -94,9 +94,11 @@ typedef struct { typedef struct { int32_t latitude; int32_t longitude; +#if !(PAYLOAD_OPENSENSEBOX) uint8_t satellites; uint16_t hdop; int16_t altitude; +#endif } gpsStatus_t; typedef struct { diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 9ee6cf4f..bf2c3b39 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -18,6 +18,14 @@ function Decoder(bytes, port) { if (bytes.length === 4) { return decode(bytes, [uint16, uint16], ['wifi', 'ble']); } + // combined wifi counter and gps data, used by https://opensensemap.org + if (bytes.length === 10) { + return decode(bytes, [latLng, latLng, uint16], ['latitude', 'longitude', 'wifi']); + } + // combined wifi + ble counter and gps data, used by https://opensensemap.org + if (bytes.length === 12) { + return decode(bytes, [latLng, latLng, uint16, uint16], ['latitude', 'longitude', 'wifi', 'ble']); + } // combined wifi counter and gps data if (bytes.length === 15) { return decode(bytes, [uint16, latLng, latLng, uint8, hdop, altitude], ['wifi', 'latitude', 'longitude', 'sats', 'hdop', 'altitude']); diff --git a/src/gpsread.cpp b/src/gpsread.cpp index eab3b3b3..e8540a1c 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -76,9 +76,11 @@ void gps_storelocation(gpsStatus_t *gps_store) { (gps.location.age() < 1500)) { gps_store->latitude = (int32_t)(gps.location.lat() * 1e6); gps_store->longitude = (int32_t)(gps.location.lng() * 1e6); +#if !(PAYLOAD_OPENSENSEBOX) gps_store->satellites = (uint8_t)gps.satellites.value(); gps_store->hdop = (uint16_t)gps.hdop.value(); gps_store->altitude = (int16_t)gps.altitude.meters(); +#endif } } diff --git a/src/paxcounter.conf b/src/paxcounter.conf index b7aa5033..a8dee35a 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -47,6 +47,7 @@ #define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle #define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results #define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit +#define PAYLOAD_OPENSENSEBOX 1 // send payload compatible to sensebox.de (swap geo position and pax data) #define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5] #define LORATXPOWDEFAULT 14 // 0 .. 255, LoRaWAN TX power in dBm [default = 14] #define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy @@ -92,7 +93,7 @@ #define RCMDPORT 2 // remote commands #define STATUSPORT 2 // remote command results #define CONFIGPORT 3 // config query results -#define GPSPORT 4 // gps - set to 1 to send combined GPS+COUNT payload +#define GPSPORT 1 // gps - set to 1 to send combined GPS+COUNT payload #define BUTTONPORT 5 // button pressed signal #define BEACONPORT 6 // beacon alarms #define BMEPORT 7 // BME680 sensor diff --git a/src/payload.cpp b/src/payload.cpp index fad4a1bc..1ddf1fbf 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -193,10 +193,12 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, void PayloadConvert::addGPS(gpsStatus_t value) { #if(HAS_GPS) writeLatLng(value.latitude, value.longitude); +#if !(PAYLOAD_OPENSENSEBOX) writeUint8(value.satellites); writeUint16(value.hdop); writeUint16(value.altitude); #endif +#endif } void PayloadConvert::addSensor(uint8_t buf[]) { diff --git a/src/senddata.cpp b/src/senddata.cpp index d18826fe..d741633a 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -65,10 +65,11 @@ void sendData() { #if ((WIFICOUNTER) || (BLECOUNTER)) case COUNT_DATA: payload.reset(); +#if !(PAYLOAD_OPENSENSEBOX) payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); -#if (HAS_GPS) && (GPSPORT==1) +#endif // send GPS position only if we have a fix if (gps.location.isValid()) { gpsStatus_t gps_status; @@ -76,6 +77,11 @@ void sendData() { payload.addGPS(gps_status); } else ESP_LOGD(TAG, "No valid GPS position"); +#endif +#if (PAYLOAD_OPENSENSEBOX) + payload.addCount(macs_wifi, MAC_SNIFF_WIFI); + if (cfg.blescan) + payload.addCount(macs_ble, MAC_SNIFF_BLE); #endif SendPayload(COUNTERPORT, prio_normal); // clear counter if not in cumulative counter mode From 8790c9f3d580b0c5e150c41656b37f2a01b432c0 Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Tue, 19 Nov 2019 22:39:36 +0000 Subject: [PATCH 05/21] defaults --- src/paxcounter.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/paxcounter.conf b/src/paxcounter.conf index a8dee35a..061510d1 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -47,7 +47,7 @@ #define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle #define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results #define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit -#define PAYLOAD_OPENSENSEBOX 1 // send payload compatible to sensebox.de (swap geo position and pax data) +#define PAYLOAD_OPENSENSEBOX 0 // send payload compatible to sensebox.de (swap geo position and pax data) #define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5] #define LORATXPOWDEFAULT 14 // 0 .. 255, LoRaWAN TX power in dBm [default = 14] #define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy @@ -93,7 +93,7 @@ #define RCMDPORT 2 // remote commands #define STATUSPORT 2 // remote command results #define CONFIGPORT 3 // config query results -#define GPSPORT 1 // gps - set to 1 to send combined GPS+COUNT payload +#define GPSPORT 4 // gps - set to 1 to send combined GPS+COUNT payload #define BUTTONPORT 5 // button pressed signal #define BEACONPORT 6 // beacon alarms #define BMEPORT 7 // BME680 sensor From ae8f4ac514a9aa9e62c0ae6e60f79d6b60db96ec Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Tue, 19 Nov 2019 22:41:49 +0000 Subject: [PATCH 06/21] style --- src/senddata.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/senddata.cpp b/src/senddata.cpp index d741633a..6f910d71 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -70,6 +70,7 @@ void sendData() { if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); #endif +#if (HAS_GPS) && (GPSPORT == 1) // send GPS position only if we have a fix if (gps.location.isValid()) { gpsStatus_t gps_status; @@ -105,7 +106,7 @@ void sendData() { break; #endif -#if (HAS_GPS) && (GPSPORT!=1) +#if (HAS_GPS) && (GPSPORT != 1) case GPS_DATA: // send GPS position only if we have a fix if (gps.location.isValid()) { From 42b1435df3f6eb84420b229796d6b9968cb017d5 Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Tue, 19 Nov 2019 22:42:50 +0000 Subject: [PATCH 07/21] quick explanation how to set up mobile paxxounter --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4504b72b..878a8b46 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,12 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. [**packed_decoder.js**](src/TTN/packed_decoder.js) | [**packed_converter.js**](src/TTN/packed_converter.js) +# 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/. +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"}] + **Port #1:** Paxcount data @@ -307,7 +313,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0x03 set GPS data on/off 0 = GPS data off - 1 = GPS data on, sends GPS data on port 4, if GPS is present and has a fix [default] + 1 = GPS data on, sends GPS data on port 4 (default, use port 1 for mobile pax counter), if GPS is present and has a fix [default] 0x04 set display on/off From bb227b525b582c7efb23e7d5977af958252bdd64 Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Thu, 21 Nov 2019 17:04:55 +0000 Subject: [PATCH 08/21] additional decoder for short latLon on port4 --- src/TTN/packed_decoder.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index bf2c3b39..0624d885 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -50,7 +50,11 @@ function Decoder(bytes, port) { if (port === 4) { // gps data - return decode(bytes, [latLng, latLng, uint8, hdop, altitude], ['latitude', 'longitude', 'sats', 'hdop', 'altitude']); + if (bytes.length === 8) { + return decode(bytes, [latLng, latLng], ['latitude', 'longitude']); + } else { + return decode(bytes, [latLng, latLng, uint8, hdop, altitude], ['latitude', 'longitude', 'sats', 'hdop', 'altitude']); + } } if (port === 5) { From 4d12aa7cecfa78b9eef0d0be741b84fc321f2035 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 27 Oct 2019 16:13:33 +0100 Subject: [PATCH 09/21] bugfix reset runmode logic --- src/reset.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/reset.cpp b/src/reset.cpp index 0fa965d3..94f6626d 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -34,8 +34,15 @@ void do_after_reset(int reason) { RTC_runmode = RUNMODE_POWERCYCLE; break; + case SW_CPU_RESET: // 0x0c Software reset CPU + // keep previous runmode (could be RUNMODE_UPDATE) + break; + case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core RTC_runmode = RUNMODE_WAKEUP; +#if (HAS_LORA) + // to be done: restore LoRaWAN channel configuration and datarate here +#endif break; case SW_RESET: // 0x03 Software reset digital core @@ -46,11 +53,11 @@ void do_after_reset(int reason) { case RTCWDT_SYS_RESET: // 0x09 RTC Watch dog Reset digital core case INTRUSION_RESET: // 0x0a Instrusion tested to reset CPU case TGWDT_CPU_RESET: // 0x0b Time Group reset CPU - case SW_CPU_RESET: // 0x0c Software reset CPU case RTCWDT_CPU_RESET: // 0x0d RTC Watch dog Reset CPU case EXT_CPU_RESET: // 0x0e for APP CPU, reseted by PRO CPU case RTCWDT_RTC_RESET: // 0x10 RTC Watch dog reset digital core and rtc mode default: + RTC_runmode = RUNMODE_POWERCYCLE; break; } @@ -66,6 +73,9 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) { #if (HAS_LORA) if (os_queryTimeCriticalJobs(ms2osticks(10000))) return; + + // to be done: save LoRaWAN channel configuration here + #endif // set up power domains From b5c5e3ce47681511c87f177b8a8fffb1c3d4f8af Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 27 Oct 2019 17:33:23 +0100 Subject: [PATCH 10/21] ota.cpp bugfix led define --- src/ota.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ota.cpp b/src/ota.cpp index d78a6453..087b92e7 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -246,7 +246,7 @@ int do_ota_update() { goto retry; } -#ifdef HAS_LED +#if (HAS_LED != NOT_A_PIN) #ifndef LED_ACTIVE_LOW if (!Update.begin(contentLength, U_FLASH, HAS_LED, HIGH)) { #else From 28d9def1d49da6041d340b0370b2eaa5565160eb Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 8 Nov 2019 23:05:28 +0100 Subject: [PATCH 11/21] disable LMIC onEvent() --- src/lmic_config.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lmic_config.h b/src/lmic_config.h index fb3a5816..dc55260a 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -21,7 +21,10 @@ #define LMIC_USE_INTERRUPTS 1 // time sync via LoRaWAN network, note: not supported by TTNv2 -// #define LMIC_ENABLE_DeviceTimeReq 1 +//#define LMIC_ENABLE_DeviceTimeReq 1 + +// use callback event handlers, not onEvent() reference +#define LMIC_ENABLE_onEvent 0 // This tells LMIC to make the receive windows bigger, in case your clock is // faster or slower. This causes the transceiver to be earlier switched on, From 2252d65375e548ff2070d46e96cffc4fcf0a526e Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 8 Nov 2019 23:06:31 +0100 Subject: [PATCH 12/21] TTN settings for join --- src/lorawan.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 8b787580..ff8ecfe7 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -89,9 +89,7 @@ void lora_setupForNetwork(bool preJoin) { // other regions, this will need to be changed. LMIC_selectSubBand(1); #elif CFG_LMIC_EU_like - // setting for TheThingsNetwork - // TTN uses SF9, not SF12, for RX2 window - LMIC.dn2Dr = EU868_DR_SF9; + // settings for TheThingsNetwork // Enable link check validation LMIC_setLinkCheckMode(true); #endif From 032cfa0f8e099132b1b7ab1a14a8181d0ab72b2c Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Thu, 21 Nov 2019 20:18:03 +0000 Subject: [PATCH 13/21] changes opensensebox payload struct --- include/globals.h | 2 -- src/gpsread.cpp | 2 -- src/payload.cpp | 2 ++ 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/globals.h b/include/globals.h index 8f2ef032..43902886 100644 --- a/include/globals.h +++ b/include/globals.h @@ -95,11 +95,9 @@ typedef struct { typedef struct { int32_t latitude; int32_t longitude; -#if !(PAYLOAD_OPENSENSEBOX) uint8_t satellites; uint16_t hdop; int16_t altitude; -#endif } gpsStatus_t; typedef struct { diff --git a/src/gpsread.cpp b/src/gpsread.cpp index e8540a1c..eab3b3b3 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -76,11 +76,9 @@ void gps_storelocation(gpsStatus_t *gps_store) { (gps.location.age() < 1500)) { gps_store->latitude = (int32_t)(gps.location.lat() * 1e6); gps_store->longitude = (int32_t)(gps.location.lng() * 1e6); -#if !(PAYLOAD_OPENSENSEBOX) gps_store->satellites = (uint8_t)gps.satellites.value(); gps_store->hdop = (uint16_t)gps.hdop.value(); gps_store->altitude = (int16_t)gps.altitude.meters(); -#endif } } diff --git a/src/payload.cpp b/src/payload.cpp index 1ddf1fbf..3c3001d0 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -89,12 +89,14 @@ void PayloadConvert::addGPS(gpsStatus_t value) { buffer[cursor++] = (byte)((value.longitude & 0x00FF0000) >> 16); buffer[cursor++] = (byte)((value.longitude & 0x0000FF00) >> 8); buffer[cursor++] = (byte)((value.longitude & 0x000000FF)); +#if (!PAYLOAD_OPENSENSEBOX) buffer[cursor++] = value.satellites; buffer[cursor++] = highByte(value.hdop); buffer[cursor++] = lowByte(value.hdop); buffer[cursor++] = highByte(value.altitude); buffer[cursor++] = lowByte(value.altitude); #endif +#endif } void PayloadConvert::addSensor(uint8_t buf[]) { From 59f6bc6d280364eb118357e0166bd53cf8676c5b Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Thu, 21 Nov 2019 20:34:54 +0000 Subject: [PATCH 14/21] cfg.wifiscan --- src/senddata.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/senddata.cpp b/src/senddata.cpp index 6f910d71..b8e77638 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -66,6 +66,7 @@ void sendData() { case COUNT_DATA: payload.reset(); #if !(PAYLOAD_OPENSENSEBOX) + if (cfg.wifiscan) payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); @@ -80,6 +81,7 @@ void sendData() { ESP_LOGD(TAG, "No valid GPS position"); #endif #if (PAYLOAD_OPENSENSEBOX) + if (cfg.wifiscan) payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); From 6feb1c1f658ad53035a4fd579e32062b79679b00 Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Sun, 24 Nov 2019 17:13:42 +0000 Subject: [PATCH 15/21] gps.fix broken --- README.md | 2 +- src/payload.cpp | 2 -- src/senddata.cpp | 39 +++++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index eab22936..2eed00c1 100644 --- a/README.md +++ b/README.md @@ -314,7 +314,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0x03 set GPS data on/off 0 = GPS data off - 1 = GPS data on, sends GPS data on port 4 (default, use port 1 for mobile pax counter), if GPS is present and has a fix [default] + 1 = GPS data on, sends GPS data on port 4 (default, use port 1 for mobile pax counter), if GPS is present and has a fix 0x04 set display on/off diff --git a/src/payload.cpp b/src/payload.cpp index 3c3001d0..813aed87 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -195,12 +195,10 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, void PayloadConvert::addGPS(gpsStatus_t value) { #if(HAS_GPS) writeLatLng(value.latitude, value.longitude); -#if !(PAYLOAD_OPENSENSEBOX) writeUint8(value.satellites); writeUint16(value.hdop); writeUint16(value.altitude); #endif -#endif } void PayloadConvert::addSensor(uint8_t buf[]) { diff --git a/src/senddata.cpp b/src/senddata.cpp index b8e77638..e4c55198 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -58,6 +58,7 @@ void sendData() { uint8_t bitmask = cfg.payloadmask; uint8_t mask = 1; + gpsStatus_t gps_status; while (bitmask) { switch (bitmask & mask) { @@ -71,14 +72,15 @@ void sendData() { if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); #endif -#if (HAS_GPS) && (GPSPORT == 1) - // send GPS position only if we have a fix - if (gps.location.isValid()) { - gpsStatus_t gps_status; - gps_storelocation(&gps_status); - payload.addGPS(gps_status); - } else - ESP_LOGD(TAG, "No valid GPS position"); +#if (HAS_GPS) + if (GPSPORT == COUNTERPORT) { + // send GPS position only if we have a fix + if (gps.location.isValid()) { + gps_storelocation(&gps_status); + payload.addGPS(gps_status); + } else + ESP_LOGD(TAG, "No valid GPS position"); + } #endif #if (PAYLOAD_OPENSENSEBOX) if (cfg.wifiscan) @@ -108,17 +110,18 @@ void sendData() { break; #endif -#if (HAS_GPS) && (GPSPORT != 1) +#if (HAS_GPS) case GPS_DATA: - // send GPS position only if we have a fix - if (gps.location.isValid()) { - gpsStatus_t gps_status; - gps_storelocation(&gps_status); - payload.reset(); - payload.addGPS(gps_status); - SendPayload(GPSPORT, prio_high); - } else - ESP_LOGD(TAG, "No valid GPS position"); + if (GPSPORT != COUNTERPORT) { + // send GPS position only if we have a fix + if (gps.location.isValid()) { + gps_storelocation(&gps_status); + payload.reset(); + payload.addGPS(gps_status); + SendPayload(GPSPORT, prio_high); + } else + ESP_LOGD(TAG, "No valid GPS position"); + } break; #endif From b7a640e02fe639e1154f2233748967559fd9a43c Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Wed, 27 Nov 2019 20:26:03 +0000 Subject: [PATCH 16/21] enable GPS default,fix SenseBox payload,whitespace --- README.md | 2 +- src/configmanager.cpp | 8 ++++---- src/paxcounter.conf | 2 +- src/payload.cpp | 2 ++ src/senddata.cpp | 8 ++++---- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2eed00c1..7b885de5 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ Output of sensor and peripheral data is internally switched by a bitmask registe | Bit | Sensordata | Default | --- | ------------- | ------- -| 0 | GPS | off* +| 0 | GPS* | on | 1 | Beacon alarm | on | 2 | BME280/680 | on | 3 | Paxcounter | on diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 40d4a0a8..3b32470d 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -8,10 +8,10 @@ static const char TAG[] = "flash"; nvs_handle my_handle; esp_err_t err; -#define PAYLOADMASK \ - ((ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | \ - SENSOR3_DATA) & \ - (~BATT_DATA) & (~GPS_DATA)) +#define PAYLOADMASK \ + ((GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | \ + SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) & \ + (~BATT_DATA) ) // populate cfg vars with factory settings void defaultConfig() { diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 061510d1..0c936ed8 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -93,7 +93,7 @@ #define RCMDPORT 2 // remote commands #define STATUSPORT 2 // remote command results #define CONFIGPORT 3 // config query results -#define GPSPORT 4 // gps - set to 1 to send combined GPS+COUNT payload +#define GPSPORT 4 // gps - set to 1 to send combined GPS+COUNTERPORT payload #define BUTTONPORT 5 // button pressed signal #define BEACONPORT 6 // beacon alarms #define BMEPORT 7 // BME680 sensor diff --git a/src/payload.cpp b/src/payload.cpp index 813aed87..323e402b 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -195,10 +195,12 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, void PayloadConvert::addGPS(gpsStatus_t value) { #if(HAS_GPS) writeLatLng(value.latitude, value.longitude); +#if (!PAYLOAD_OPENSENSEBOX) writeUint8(value.satellites); writeUint16(value.hdop); writeUint16(value.altitude); #endif +#endif } void PayloadConvert::addSensor(uint8_t buf[]) { diff --git a/src/senddata.cpp b/src/senddata.cpp index e4c55198..2dfcbbf3 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -68,7 +68,7 @@ void sendData() { payload.reset(); #if !(PAYLOAD_OPENSENSEBOX) if (cfg.wifiscan) - payload.addCount(macs_wifi, MAC_SNIFF_WIFI); + payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); #endif @@ -76,15 +76,15 @@ void sendData() { if (GPSPORT == COUNTERPORT) { // send GPS position only if we have a fix if (gps.location.isValid()) { - gps_storelocation(&gps_status); - payload.addGPS(gps_status); + gps_storelocation(&gps_status); + payload.addGPS(gps_status); } else ESP_LOGD(TAG, "No valid GPS position"); } #endif #if (PAYLOAD_OPENSENSEBOX) if (cfg.wifiscan) - payload.addCount(macs_wifi, MAC_SNIFF_WIFI); + payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); #endif From a7497624b71168885c02f4b62548aee3488445e8 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 27 Nov 2019 22:13:18 +0100 Subject: [PATCH 17/21] change GPS data default off to on --- README.md | 2 +- src/configmanager.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 68fe86bd..b61757b9 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ Output of sensor and peripheral data is internally switched by a bitmask registe | Bit | Sensordata | Default | --- | ------------- | ------- -| 0 | GPS | off* +| 0 | GPS | on* | 1 | Beacon alarm | on | 2 | BME280/680 | on | 3 | Paxcounter | on diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 40d4a0a8..c51e4dd7 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -9,9 +9,9 @@ nvs_handle my_handle; esp_err_t err; #define PAYLOADMASK \ - ((ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | \ - SENSOR3_DATA) & \ - (~BATT_DATA) & (~GPS_DATA)) + (ALARM_DATA | MEMS_DATA | COUNT_DATA | GPS_DATA | SENSOR1_DATA | \ + SENSOR2_DATA | SENSOR3_DATA) & \ + (~BATT_DATA) // populate cfg vars with factory settings void defaultConfig() { From d9a74bd8be87c403a60e93e655393a8438e5a365 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 27 Nov 2019 22:13:38 +0100 Subject: [PATCH 18/21] main.cpp comments sanitized --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6d96d7b9..774a0b45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,9 +34,9 @@ IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer lmictask 1 2 MCCI LMiC LORAWAN stack clockloop 1 4 generates realtime telegrams for external clock timesync_req 1 3 processes realtime time sync requests -irqhandler 1 1 display, timesync, gps, etc. triggered by timers +irqhandler 1 1 cyclic tasks (i.e. displayrefresh) triggered by timers gpsloop 1 1 reads data from GPS via serial or i2c -lorasendtask 1 1 feed data from lora sendqueue to lmcic +lorasendtask 1 1 feeds data from lora sendqueue to lmcic IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator Low priority numbers denote low priority tasks. From def1dac9be955cb67e78cead5f847b84e4919adf Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 27 Nov 2019 22:14:17 +0100 Subject: [PATCH 19/21] v1.9.82 --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index bc46b135..f3bc4713 100644 --- a/platformio.ini +++ b/platformio.ini @@ -43,10 +43,10 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.81 +release_version = 1.9.82 ; 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 From d8329ff69d2a79b35f1f5030ebf8de248d2e2eab Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 27 Nov 2019 22:23:17 +0100 Subject: [PATCH 20/21] readme.md sanitized --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7b885de5..4ef3bfbb 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,12 @@ 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/. +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"}] + # Payload format You can select different payload formats in [paxcounter.conf](src/paxcounter.conf#L12): @@ -213,13 +219,6 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering. [**packed_decoder.js**](src/TTN/packed_decoder.js) | [**packed_converter.js**](src/TTN/packed_converter.js) -# 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/. -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"}] - - **Port #1:** Paxcount data byte 1-2: Number of unique devices, seen on Wifi From 984fb151d68e543bf276c3ef15f83e830a4231b7 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 27 Nov 2019 22:25:34 +0100 Subject: [PATCH 21/21] readme.md sanitized --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4ef3bfbb..8a82a062 100644 --- a/README.md +++ b/README.md @@ -506,3 +506,4 @@ Thanks to - [robbi5](https://github.com/robbi5) for the payload converter - [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