From 804cbfb879ee7b44ebf995883eac98b756c8a0e5 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:43:13 +0100 Subject: [PATCH 1/4] added support for SDS011 --- include/senddata.h | 4 ++++ 1 file changed, 4 insertions(+) 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); From 7a465f7c752b0a8b8fbc7ab6bcc8bda3e6f22090 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:44:54 +0100 Subject: [PATCH 2/4] added support for SDS011 --- include/payload.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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_ From c1411e5c1b475213fe0e5066e65a9791bd93fd58 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:49:07 +0100 Subject: [PATCH 3/4] added support for SDS011 --- src/senddata.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/senddata.cpp b/src/senddata.cpp index f4f6b085..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); } @@ -13,6 +18,10 @@ void SendPayload(uint8_t port, sendprio_t prio) { MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, MessagePrio, Message[] +#if (HAS_SDS011) + sds011_loop(); +#endif + SendBuffer.MessageSize = payload.getSize(); SendBuffer.MessagePrio = prio; @@ -94,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 @@ -172,4 +185,4 @@ void flushQueues() { #ifdef HAS_SPI spi_queuereset(); #endif -} \ No newline at end of file +} From b5250a21edf33f1bf86361804ba367ab1969e73e Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:51:49 +0100 Subject: [PATCH 4/4] added support for SDS011 --- src/payload.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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]); +}