From 3382f5507a0782fa20ea3dc2530b79f1a43016e7 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 28 Feb 2020 16:04:22 +0100 Subject: [PATCH 1/9] Cayenne: added constant for PM-values --- include/payload.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/payload.h b/include/payload.h index 719d59ec..0f968df7 100644 --- a/include/payload.h +++ b/include/payload.h @@ -23,6 +23,7 @@ #define LPP_HUMIDITY_CHANNEL 29 #define LPP_BAROMETER_CHANNEL 30 #define LPP_AIR_CHANNEL 31 +#define LPP_PARTMATTER_CHANNEL 32 // particular matter // MyDevices CayenneLPP 2.0 types for Packed Sensor Payload, not using channels, // but different FPorts From d18403a84a30b8c2b604cca755ea05aa8f330ece Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 28 Feb 2020 16:12:16 +0100 Subject: [PATCH 2/9] Cayenne: added code for PM-values --- src/payload.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/payload.cpp b/src/payload.cpp index 57428234..06bbf5bd 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -317,6 +317,19 @@ void PayloadConvert::addByte(uint8_t value) { not implemented */ } +void PayloadConvert::addSDS(sdsStatus_t sds) { +#if (HAS_SDS011) +#if (PAYLOAD_ENCODER == 3) // Cayenne LPP dynamic + buffer[cursor++] = LPP_PARTMATTER_CHANNEL; // for PM10 and PM25 +#endif + buffer[cursor++] = LPP_LUMINOSITY; // workaround since cayenne has no data type meter + buffer[cursor++] = highByte(sds.pm10); + buffer[cursor++] = lowByte(sds.pm10); + buffer[cursor++] = highByte(sds.pm25); + buffer[cursor++] = lowByte(sds.pm25); +#endif // HAS_SDS011 +} + void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) { switch (snifftype) { case MAC_SNIFF_WIFI: From a2a53f761738ae990d3baedaa3022d6a4048d6c5 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 28 Feb 2020 16:13:20 +0100 Subject: [PATCH 3/9] Update payload.h --- include/payload.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/payload.h b/include/payload.h index 0f968df7..29d1f88e 100644 --- a/include/payload.h +++ b/include/payload.h @@ -60,8 +60,7 @@ public: void addButton(uint8_t value); void addSensor(uint8_t[]); void addTime(time_t value); - void addPM10(float value); - void addPM25(float value); + void addSDS(sdsStatus_t value); private: void addChars( char* string, int len); From 406f71eea567108a6be15ce425b0560215418776 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:23:22 +0100 Subject: [PATCH 4/9] Update payload.h --- include/payload.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/payload.h b/include/payload.h index 29d1f88e..889c164d 100644 --- a/include/payload.h +++ b/include/payload.h @@ -23,7 +23,8 @@ #define LPP_HUMIDITY_CHANNEL 29 #define LPP_BAROMETER_CHANNEL 30 #define LPP_AIR_CHANNEL 31 -#define LPP_PARTMATTER_CHANNEL 32 // particular matter +#define LPP_PARTMATTER10_CHANNEL 32 // particular matter for PM 10 +#define LPP_PARTMATTER25_CHANNEL 33 // particular matter for PM 2.5 // MyDevices CayenneLPP 2.0 types for Packed Sensor Payload, not using channels, // but different FPorts From 8520afcf8d2502c786b053e950ce148e75e78464 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:25:18 +0100 Subject: [PATCH 5/9] Update payload.cpp --- src/payload.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/payload.cpp b/src/payload.cpp index 06bbf5bd..b565c3b4 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -319,14 +319,20 @@ void PayloadConvert::addByte(uint8_t value) { void PayloadConvert::addSDS(sdsStatus_t sds) { #if (HAS_SDS011) +// value of PM10 #if (PAYLOAD_ENCODER == 3) // Cayenne LPP dynamic - buffer[cursor++] = LPP_PARTMATTER_CHANNEL; // for PM10 and PM25 + buffer[cursor++] = LPP_PARTMATTER10_CHANNEL; // for PM10 #endif buffer[cursor++] = LPP_LUMINOSITY; // workaround since cayenne has no data type meter - buffer[cursor++] = highByte(sds.pm10); - buffer[cursor++] = lowByte(sds.pm10); - buffer[cursor++] = highByte(sds.pm25); - buffer[cursor++] = lowByte(sds.pm25); + buffer[cursor++] = highByte((uint16_t)(sds.pm10 * 10)); + buffer[cursor++] = lowByte((uint16_t)(sds.pm10 * 10)); +// value of PM2.5 +#if (PAYLOAD_ENCODER == 3) // Cayenne LPP dynamic + buffer[cursor++] = LPP_PARTMATTER25_CHANNEL; // for PM2.5 +#endif + buffer[cursor++] = LPP_LUMINOSITY; // workaround since cayenne has no data type meter + buffer[cursor++] = highByte((uint16_t)(sds.pm25 * 10)); + buffer[cursor++] = lowByte((uint16_t)(sds.pm25 * 10)); #endif // HAS_SDS011 } From 0c91c55cd4f98f3b3bfc563c7d37112488bab9ef Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:29:20 +0100 Subject: [PATCH 6/9] Update payload.cpp --- src/payload.cpp | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/payload.cpp b/src/payload.cpp index b565c3b4..ceb971fa 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -510,38 +510,6 @@ void PayloadConvert::addTime(time_t value) { } #endif // PAYLOAD_ENCODER -void PayloadConvert::addPM10( float value) { -#if (HAS_SDS011) -#if (PAYLOAD_ENCODER == 1) // plain - char tempBuffer[10+1]; - sprintf( tempBuffer, ",%5.1f", value); - addChars(tempBuffer, strlen(tempBuffer)); -#elif (PAYLOAD_ENCODER == 2 ) // packed - writeUint16( (uint16_t) (value*10) ); -#elif (PAYLOAD_ENCODER == 3 ) // Cayenne LPP dynamic -#error not implemented yet -#elif (PAYLOAD_ENCODER == 4 ) // Cayenne LPP packed -#error not implemented yet -#endif -#endif // HAS_SDS011 -} - -void PayloadConvert::addPM25( float value) { -#if (HAS_SDS011) -#if (PAYLOAD_ENCODER == 1) // plain - char tempBuffer[10+1]; - sprintf( tempBuffer, ",%5.1f", value); - addChars(tempBuffer, strlen(tempBuffer)); -#elif (PAYLOAD_ENCODER == 2 ) // packed - writeUint16( (uint16_t) (value*10) ); -#elif (PAYLOAD_ENCODER == 3 ) // Cayenne LPP dynamic -#error not implemented yet -#elif (PAYLOAD_ENCODER == 4 ) // Cayenne LPP packed -#error not implemented yet -#endif -#endif // HAS_SDS011 -} - void PayloadConvert::addChars( char * string, int len) { for (int i=0; i < len; i++) addByte(string[i]); From 8f7ba2943fff99371a699dd12992f6746f31c346 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:33:47 +0100 Subject: [PATCH 7/9] Update payload.h --- include/payload.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/payload.h b/include/payload.h index 889c164d..79b8c341 100644 --- a/include/payload.h +++ b/include/payload.h @@ -84,7 +84,8 @@ private: void writeUint16(uint16_t i); void writeUint8(uint8_t i); void writeFloat(float value); - void writeUFloat(float value); + void wri +teUFloat(float value); void writePressure(float value); void writeVersion(char *version); void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g, From f33494b84f5fe44069f906c1f6a5e26db8c5f7b7 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:35:42 +0100 Subject: [PATCH 8/9] Update payload.h --- include/payload.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/payload.h b/include/payload.h index 79b8c341..889c164d 100644 --- a/include/payload.h +++ b/include/payload.h @@ -84,8 +84,7 @@ private: void writeUint16(uint16_t i); void writeUint8(uint8_t i); void writeFloat(float value); - void wri -teUFloat(float value); + void writeUFloat(float value); void writePressure(float value); void writeVersion(char *version); void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g, From d818b6ecf4781f161b4282f3d1f06dfeedeb1a65 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:41:07 +0100 Subject: [PATCH 9/9] Update payload.cpp --- src/payload.cpp | 72 ++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/payload.cpp b/src/payload.cpp index ceb971fa..8ab9f91c 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -80,7 +80,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, } void PayloadConvert::addGPS(gpsStatus_t value) { -#if(HAS_GPS) +#if (HAS_GPS) buffer[cursor++] = (byte)((value.latitude & 0xFF000000) >> 24); buffer[cursor++] = (byte)((value.latitude & 0x00FF0000) >> 16); buffer[cursor++] = (byte)((value.latitude & 0x0000FF00) >> 8); @@ -100,7 +100,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#if(HAS_SENSORS) +#if (HAS_SENSORS) uint8_t length = buf[0]; memcpy(buffer, buf + 1, length); cursor += length; // length of buffer @@ -108,7 +108,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#if(HAS_BME) +#if (HAS_BME) int16_t temperature = (int16_t)(value.temperature); // float -> int uint16_t humidity = (uint16_t)(value.humidity); // float -> int uint16_t pressure = (uint16_t)(value.pressure); // float -> int @@ -124,6 +124,16 @@ void PayloadConvert::addBME(bmeStatus_t value) { #endif } +void PayloadConvert::addSDS(sdsStatus_t sds) { +#if (HAS_SDS011) + char tempBuffer[10 + 1]; + sprintf(tempBuffer, ",%5.1f", sds.pm10); + addChars(tempBuffer, strlen(tempBuffer)); + sprintf(tempBuffer, ",%5.1f", sds.pm25); + addChars(tempBuffer, strlen(tempBuffer)); +#endif // HAS_SDS011 +} + void PayloadConvert::addButton(uint8_t value) { #ifdef HAS_BUTTON buffer[cursor++] = value; @@ -193,7 +203,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, } void PayloadConvert::addGPS(gpsStatus_t value) { -#if(HAS_GPS) +#if (HAS_GPS) writeLatLng(value.latitude, value.longitude); #if (!PAYLOAD_OPENSENSEBOX) writeUint8(value.satellites); @@ -204,7 +214,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#if(HAS_SENSORS) +#if (HAS_SENSORS) uint8_t length = buf[0]; memcpy(buffer, buf + 1, length); cursor += length; // length of buffer @@ -212,7 +222,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#if(HAS_BME) +#if (HAS_BME) writeFloat(value.temperature); writePressure(value.pressure); writeUFloat(value.humidity); @@ -220,6 +230,13 @@ void PayloadConvert::addBME(bmeStatus_t value) { #endif } +void PayloadConvert::addSDS(sdsStatus_t sds) { +#if (HAS_SDS011) + writeUint16((uint16_t)(sds.pm10 * 10)); + writeUint16((uint16_t)(sds.pm25 * 10)); +#endif // HAS_SDS011 +} + void PayloadConvert::addButton(uint8_t value) { #ifdef HAS_BUTTON writeUint8(value); @@ -242,9 +259,7 @@ void PayloadConvert::uintToBytes(uint64_t value, uint8_t byteSize) { } } -void PayloadConvert::writeUptime(uint64_t uptime) { - writeUint64(uptime); -} +void PayloadConvert::writeUptime(uint64_t uptime) { writeUint64(uptime); } void PayloadConvert::writeVersion(char *version) { memcpy(buffer + cursor, version, 10); @@ -265,13 +280,9 @@ void PayloadConvert::writeUint16(uint16_t i) { uintToBytes(i, 2); } void PayloadConvert::writeUint8(uint8_t i) { uintToBytes(i, 1); } -void PayloadConvert::writeUFloat(float value) { - writeUint16(value * 100); -} +void PayloadConvert::writeUFloat(float value) { writeUint16(value * 100); } -void PayloadConvert::writePressure(float value) { - writeUint16(value * 10); -} +void PayloadConvert::writePressure(float value) { writeUint16(value * 10); } /** * Uses a 16bit two's complement with two decimals, so the range is @@ -312,10 +323,11 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, #elif ((PAYLOAD_ENCODER == 3) || (PAYLOAD_ENCODER == 4)) -void PayloadConvert::addByte(uint8_t value) { - /* +void PayloadConvert::addByte(uint8_t value) { + /* not implemented - */ } + */ +} void PayloadConvert::addSDS(sdsStatus_t sds) { #if (HAS_SDS011) @@ -412,7 +424,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius, } void PayloadConvert::addGPS(gpsStatus_t value) { -#if(HAS_GPS) +#if (HAS_GPS) int32_t lat = value.latitude / 100; int32_t lon = value.longitude / 100; int32_t alt = value.altitude * 100; @@ -433,18 +445,18 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#if(HAS_SENSORS) -// to come -/* - uint8_t length = buf[0]; - memcpy(buffer, buf+1, length); - cursor += length; // length of buffer -*/ +#if (HAS_SENSORS) + // to come + /* + uint8_t length = buf[0]; + memcpy(buffer, buf+1, length); + cursor += length; // length of buffer + */ #endif // HAS_SENSORS } void PayloadConvert::addBME(bmeStatus_t value) { -#if(HAS_BME) +#if (HAS_BME) // data value conversions to meet cayenne data type definition // 0.1°C per bit => -3276,7 .. +3276,7 °C @@ -510,7 +522,7 @@ void PayloadConvert::addTime(time_t value) { } #endif // PAYLOAD_ENCODER -void PayloadConvert::addChars( char * string, int len) { - for (int i=0; i < len; i++) - addByte(string[i]); +void PayloadConvert::addChars(char *string, int len) { + for (int i = 0; i < len; i++) + addByte(string[i]); }