This commit is contained in:
Klaus K Wilting committed 2020-02-25 21:16:23 +01:00
commit 417c3c7e69
14 files changed
+196 -15

No files matched your search

+16 -2
View File
@@ -9,6 +9,10 @@ static const char TAG[] = __FILE__;
Ticker housekeeper;
#if (HAS_SDS011)
extern boolean isSDS011Active;
#endif
void housekeeping() {
xTaskNotifyFromISR(irqHandlerTask, CYCLIC_IRQ, eSetBits, NULL);
}
@@ -18,7 +22,6 @@ void doHousekeeping() {
// update uptime counter
uptime();
// check if update mode trigger switch was set
if (RTC_runmode == RUNMODE_UPDATE) {
// check battery status if we can before doing ota
@@ -112,6 +115,17 @@ void doHousekeeping() {
}
#endif
#if (HAS_SDS011)
if ( isSDS011Active ) {
ESP_LOGD(TAG, "SDS011: go to sleep");
sds011_loop();
}
else {
ESP_LOGD(TAG, "SDS011: wakeup");
sds011_wakeup();
}
#endif
} // doHousekeeping()
// uptime counter 64bit to prevent millis() rollover after 49 days
@@ -143,4 +157,4 @@ void reset_counters() {
#endif
#endif
}
}
+1 -1
View File
@@ -100,4 +100,4 @@
#define MCP_24AA02E64_I2C_ADDRESS 0x50 // I2C address for the 24AA02E64
#define MCP_24AA02E64_MAC_ADDRESS 0xF8 // Memory adress of unique deveui 64 bits
#endif
#endif
+7 -1
View File
@@ -12,6 +12,12 @@
// This settings are for boards labeled v1.6 on pcb, NOT for v1.5 or older
*/
// SDS011 dust sensor settings
#define HAS_SDS011 1 // use SDS011
// used pins on the ESP-side:
#define ESP_PIN_TX 19 // connect to RX on the SDS011
#define ESP_PIN_RX 23 // connect to TX on the SDS011
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
@@ -48,4 +54,4 @@
#define LORA_IO1 (33)
#define LORA_IO2 (32)
#endif
#endif
+7 -1
View File
@@ -324,10 +324,16 @@ void setup() {
#endif
#ifdef HAS_SDCARD
if (sdcardInit())
if (sdcard_init())
strcat_P(features, " SD");
#endif
#if (HAS_SDS011)
ESP_LOGI(TAG, "init fine-dust-sensor");
if ( sds011_init() )
strcat_P(features, " SDS");
#endif
#if (VENDORFILTER)
strcat_P(features, " FILTER");
#endif
+37 -1
View File
@@ -489,5 +489,41 @@ void PayloadConvert::addTime(time_t value) {
buffer[cursor++] = (byte)((tx_period & 0x000000FF));
#endif
}
#endif // PAYLOAD_ENCODER
#endif
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]);
}
+22 -5
View File
@@ -6,6 +6,12 @@
static const char TAG[] = __FILE__;
#include "sdcard.h"
#if (HAS_SDS011)
#include <sds011read.h>
// the results of the sensor:
extern float pm25;
extern float pm10;
#endif
static bool useSDCard;
@@ -13,11 +19,13 @@ static void createFile(void);
File fileSDCard;
bool sdcardInit() {
bool sdcard_init() {
ESP_LOGD(TAG, "looking for SD-card...");
useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
if (useSDCard)
createFile();
else
ESP_LOGD(TAG,"SD-card not found");
return useSDCard;
}
@@ -35,7 +43,12 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle) {
sprintf(tempBuffer, "%02d:%02d:%02d,", hour(t), minute(t), second(t));
fileSDCard.print(tempBuffer);
sprintf(tempBuffer, "%d,%d", noWifi, noBle);
fileSDCard.println(tempBuffer);
fileSDCard.print( tempBuffer);
#if (HAS_SDS011)
sprintf(tempBuffer, ",%5.1f,%4.1f", pm10, pm25);
fileSDCard.print( tempBuffer);
#endif
fileSDCard.println( );
if (++counterWrites > 2) {
// force writing to SD-card
@@ -58,8 +71,12 @@ void createFile(void) {
ESP_LOGD(TAG, "SD: file does not exist: opening");
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
if (fileSDCard) {
ESP_LOGD(TAG, "SD: name opended: <%s>", bufferFilename);
fileSDCard.println(SDCARD_FILE_HEADER);
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
fileSDCard.print( SDCARD_FILE_HEADER );
#if (HAS_SDS011)
fileSDCard.print( SDCARD_FILE_HEADER_SDS011 );
#endif
fileSDCard.println();
useSDCard = true;
break;
}
@@ -68,4 +85,4 @@ void createFile(void) {
return;
}
#endif // (HAS_SDCARD)
#endif // (HAS_SDCARD)
+58
View File
@@ -0,0 +1,58 @@
// routines for fetching data from the SDS011-sensor
// Local logging tag
static const char TAG[] = __FILE__;
#include "sds011read.h"
#if (HAS_IF482)
#error cannot use IF482 together with SDS011 (both use UART#2)
#endif
// UART(2) is unused in this project
static HardwareSerial sdsSerial(2); // so we use it here
static SDS011 sdsSensor; // fine dust sensor
// the results of the sensor:
float pm25;
float pm10;
boolean isSDS011Active;
// init
bool sds011_init() {
pm25 = pm10 = 0.0;
#if (HAS_SDS011)
sdsSensor.begin (&sdsSerial, ESP_PIN_RX, ESP_PIN_TX);
#endif
sds011_sleep(); // we do sleep/wakup by ourselves
return true;
}
// reading data:
void sds011_loop() {
if (isSDS011Active) {
int sdsErrorCode = sdsSensor.read(&pm25, &pm10);
if (sdsErrorCode) {
pm25 = pm10 = 0.0;
ESP_LOGI(TAG, "SDS011 error: %d", sdsErrorCode);
} else {
ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
}
sds011_sleep();
}
return;
}
// putting the SDS-sensor to sleep
void sds011_sleep(void) {
sdsSensor.sleep();
isSDS011Active = false;
}
// start the SDS-sensor
// needs 30 seconds for warming up
void sds011_wakeup() {
if (!isSDS011Active) {
sdsSensor.wakeup();
isSDS011Active = true;
}
}
+10 -1
View File
@@ -3,6 +3,11 @@
Ticker sendcycler;
#if (HAS_SDS011)
extern float pm10;
extern float pm25;
#endif
void sendcycle() {
xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL);
}
@@ -94,6 +99,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 +181,4 @@ void flushQueues() {
#ifdef HAS_SPI
spi_queuereset();
#endif
}
}
+3
View File
@@ -16,6 +16,9 @@ static const char TAG[] = __FILE__;
const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
#ifdef HAS_IF482
#if (HAS_SDS011)
#error cannot use IF482 together with SDS011 (both use UART#2)
#endif
HardwareSerial IF482(2); // use UART #2 (#1 may be in use for serial GPS)
#endif