From be448a37a39bdfbe954a2e1c1169a466ad2ff8cf Mon Sep 17 00:00:00 2001 From: nerdyscout Date: Tue, 19 Nov 2019 22:27:12 +0000 Subject: [PATCH] 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