diff --git a/include/payload.h b/include/payload.h index b41bb113..b2d5683f 100644 --- a/include/payload.h +++ b/include/payload.h @@ -3,6 +3,10 @@ #include "paxcounter.conf" +#if (HAS_SDS011) +#include "sds011read.h" +#endif + // MyDevices CayenneLPP 1.0 channels for Synamic sensor payload format // all payload goes out on LoRa FPort 1 #if (PAYLOAD_ENCODER == 3) @@ -55,6 +59,9 @@ public: void addButton(uint8_t value); void addSensor(uint8_t[]); void addTime(time_t value); + void addPM10(float value); + void addPM25(float value); + void addChars( char* string, int len); #if (PAYLOAD_ENCODER == 1) // format plain @@ -95,4 +102,4 @@ private: extern PayloadConvert payload; -#endif // _PAYLOAD_H_ \ No newline at end of file +#endif // _PAYLOAD_H_ diff --git a/include/senddata.h b/include/senddata.h index 5022800c..324f2e1f 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -16,6 +16,10 @@ #include "sdcard.h" #endif +#if (HAS_SDS011) +#include "sds011read.h" +#endif + extern Ticker sendcycler; void SendPayload(uint8_t port, sendprio_t prio); diff --git a/src/payload.cpp b/src/payload.cpp index 323e402b..2624c138 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -489,5 +489,41 @@ void PayloadConvert::addTime(time_t value) { buffer[cursor++] = (byte)((tx_period & 0x000000FF)); #endif } +#endif // PAYLOAD_ENCODER -#endif \ No newline at end of file +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 + // TODO +#elif (PAYLOAD_ENCODER == 4 ) // Cayenne LPP packed + // TODO +#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 + // TODO +#elif (PAYLOAD_ENCODER == 4 ) // Cayenne LPP packed + // TODO +#endif +#endif // HAS_SDS011 +} + +void PayloadConvert::addChars( char * string, int len) { + for (int i=0; i < len; i++) + addByte(string[i]); +} diff --git a/src/senddata.cpp b/src/senddata.cpp index db0a4e20..367a5c68 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -3,6 +3,11 @@ Ticker sendcycler; +#if (HAS_SDS011) +extern float pm10; +extern float pm25; +#endif + void sendcycle() { xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL); } @@ -98,6 +103,10 @@ void sendData() { payload.addCount(macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); +#endif +#if (HAS_SDS011) + payload.addPM10(pm10); + payload.addPM25(pm25); #endif SendPayload(COUNTERPORT, prio_normal); // clear counter if not in cumulative counter mode