From 18c0c06598905f435f12cd1de052a7fd5a3d9a05 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 21 Jul 2018 17:14:27 +0200 Subject: [PATCH] cayenne payload encoding modified --- platformio.ini | 4 ++-- src/paxcounter.conf | 12 +++++++----- src/payload.cpp | 30 ++++++++++++++++++++++-------- src/payload.h | 8 +++++--- src/senddata.cpp | 2 +- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/platformio.ini b/platformio.ini index 93b0a529..297df023 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,8 +16,8 @@ ;env_default = heltec ;env_default = ttgov1 ;env_default = ttgov2 -;env_default = ttgov21 -env_default = ttgobeam +env_default = ttgov21 +;env_default = ttgobeam ;env_default = lopy ;env_default = lopy4 ;env_default = fipy diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 3cdc90ea..8994ce1c 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -7,7 +7,11 @@ // Verbose enables serial output #define VERBOSE 1 // comment out to silence the device, for mute use build option -// set this to include BLE counting and vendor filter functions +// Payload send cycle and encoding +#define SEND_SECS 30 // payload send cycle [seconds/2] -> 240 sec. +#define PAYLOAD_ENCODER 3 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed + +// Set this to include BLE counting and vendor filter functions #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 @@ -35,9 +39,7 @@ #define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings #define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. -// LoRa payload default parameters -#define PAYLOAD_ENCODER 3 // select payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP -#define SEND_SECS 120 // payload send cycle [seconds/2] -> 240 sec. +// LoRa parameters #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 @@ -50,7 +52,7 @@ #define STATUSPORT 2 // Port on which device sends remote command results #define CONFIGPORT 3 // Port on which device sends gps query results #define GPSPORT 4 // Port on which device sends gps query results -#define CAYENNEPORT 1 // Port used for Cayenne encoding +#define CAYENNEPORT 2 // Port for Cayenne LPP 2.0 packet sensor encoding // Default RGB LED luminosity (in %) #define RGBLUMINOSITY 30 // 30% diff --git a/src/payload.cpp b/src/payload.cpp index ef6780ce..a6b1c5e5 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -65,7 +65,8 @@ void PayloadConvert::addConfig(configData_t value) { cursor += 10; } -void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) { +void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, + float cputemp) { buffer[cursor++] = voltage >> 8; buffer[cursor++] = voltage; buffer[cursor++] = uptime >> 56; @@ -82,7 +83,6 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) buffer[cursor++] = (uint32_t)cputemp; } - /* ---------------- packed format with LoRa serialization Encoder ---------- */ // derived from // https://github.com/thesolarnomad/lora-serialization/blob/master/src/LoraEncoder.cpp @@ -117,7 +117,8 @@ void PayloadConvert::addConfig(configData_t value) { value.vendorfilter ? true : false, value.gpsmode ? true : false); } -void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) { +void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, + float cputemp) { writeUint16(voltage); writeUptime(uptime); writeTemperature(cputemp); @@ -163,7 +164,7 @@ void PayloadConvert::writeTemperature(float temperature) { } void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, - bool g, bool h) { + bool g, bool h) { uint8_t bitmap = 0; // LSB first bitmap |= (a & 1) << 7; @@ -178,18 +179,22 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, } /* ---------------- Cayenne LPP format ---------- */ -//http://community.mydevices.com/t/cayenne-lpp-2-0/7510 +// http://community.mydevices.com/t/cayenne-lpp-2-0/7510 -#elif PAYLOAD_ENCODER == 3 +#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4) void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { uint16_t val1 = value1 * 100; uint16_t val2 = value2 * 100; +#if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL; +#endif buffer[cursor++] = LPP_ANALOG_INPUT; // workaround, type meter not found? buffer[cursor++] = val1 >> 8; buffer[cursor++] = val1; +#if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_COUNT_BLE_CHANNEL; +#endif buffer[cursor++] = LPP_ANALOG_INPUT; // workaround, type meter not found? buffer[cursor++] = val2 >> 8; buffer[cursor++] = val2; @@ -200,7 +205,9 @@ void PayloadConvert::addGPS(gpsStatus_t value) { int32_t lat = value.latitude / 100; int32_t lon = value.longitude / 100; int32_t alt = value.altitude * 100; +#if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_GPS_CHANNEL; +#endif buffer[cursor++] = LPP_GPS; buffer[cursor++] = lat >> 16; buffer[cursor++] = lat >> 8; @@ -215,18 +222,25 @@ void PayloadConvert::addGPS(gpsStatus_t value) { #endif void PayloadConvert::addConfig(configData_t value) { +#if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_ADR_CHANNEL; +#endif buffer[cursor++] = LPP_DIGITAL_INPUT; buffer[cursor++] = value.adrmode; } -void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius) { +void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, + float celsius) { int16_t val = celsius * 10; +#if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_BATT_CHANNEL; +#endif buffer[cursor++] = LPP_ANALOG_INPUT; buffer[cursor++] = voltage >> 8; buffer[cursor++] = voltage; +#if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_TEMP_CHANNEL; +#endif buffer[cursor++] = LPP_TEMPERATURE; buffer[cursor++] = (uint16_t)val >> 8; buffer[cursor++] = (uint16_t)val; @@ -234,4 +248,4 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius) #else #error "No valid payload converter defined" -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/payload.h b/src/payload.h index ddb459d5..ebdc9c06 100644 --- a/src/payload.h +++ b/src/payload.h @@ -1,13 +1,15 @@ #ifndef _PAYLOAD_H_ #define _PAYLOAD_H_ -// MyDevices CayenneLPP channels +// MyDevices CayenneLPP channels for dynamic sensor payload format +#if (PAYLOAD_ENCODER == 3) #define LPP_GPS_CHANNEL 20 #define LPP_COUNT_WIFI_CHANNEL 21 #define LPP_COUNT_BLE_CHANNEL 22 #define LPP_BATT_CHANNEL 23 #define LPP_ADR_CHANNEL 25 #define LPP_TEMP_CHANNEL 26 +#endif // MyDevices CayenneLPP types #define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m @@ -56,7 +58,7 @@ private: bool h); }; -#elif PAYLOAD_ENCODER == 3 // format cayenne lpp +#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4) // format cayenne lpp private: uint8_t *buffer; @@ -66,7 +68,7 @@ private: #else #error "No valid payload converter defined" -#endif +#endif extern PayloadConvert payload; diff --git a/src/senddata.cpp b/src/senddata.cpp index 09421580..fd346697 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -9,7 +9,7 @@ void senddata(uint8_t port) { ESP_LOGI(TAG, "LoRa busy, data not sent"); sprintf(display_line7, "LORA BUSY"); } else { - LMIC_setTxData2(PAYLOAD_ENCODER == 3 ? CAYENNEPORT : port, + LMIC_setTxData2(PAYLOAD_ENCODER == 4 ? CAYENNEPORT : port, payload.getBuffer(), payload.getSize(), (cfg.countermode & 0x02));