Merge branch 'SDS011' into SDS011

This commit is contained in:
Verkehrsrot authored and GitHub committed 2020-03-14 07:38:22 +01:00
commit 8392b8c308
13 files changed
+89 -77

No files matched your search

+1 -2
View File
@@ -10,8 +10,7 @@ static const char TAG[] = __FILE__;
TinyGPSPlus gps;
TinyGPSCustom gpstime(gps, "GPZDA", 1); // field 1 = UTC time
static const String ZDA_Request = "$EIGPQ,ZDA*39\r\n";
gpsStatus_t gps_status = {0};
static gpsStatus_t gps_status = {0};
TaskHandle_t GpsTask;
#ifdef GPS_SERIAL
+7 -1
View File
@@ -48,8 +48,14 @@
//#define HAS_BMP180
//#define BMP180_ADDR 0x77
// SDS011 dust sensor settings
#define HAS_SDS011 1 // use SDS011
// used pins on the ESP-side:
#define SDS_TX 19 // connect to RX on the SDS011
#define SDS_RX 23 // connect to TX on the SDS011
// user defined sensors
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
#define HAS_SENSORS 1 // comment out if device has user defined sensors
#define CFG_sx1276_radio 1 // select LoRa chip
//#define CFG_sx1272_radio 1 // select LoRa chip
+2 -2
View File
@@ -15,8 +15,8 @@
// 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 SDS_TX 19 // connect to RX on the SDS011
#define SDS_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
+32 -33
View File
@@ -1,13 +1,10 @@
// Basic Config
#if (HAS_LORA)
#include "lorawan.h"
#endif
// Local logging Tag
static const char TAG[] = "lora";
#if (HAS_LORA)
#if CLOCK_ERROR_PROCENTAGE > 7
#warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects
#endif
@@ -101,8 +98,10 @@ void lora_setupForNetwork(bool preJoin) {
if (!cfg.adrmode)
LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower);
// show current devaddr
ESP_LOGI(TAG, "DEVaddr: %08X", LMIC.devaddr);
ESP_LOGI(TAG, "Radio parameters: %s / %s / %s",
ESP_LOGI(TAG, "DEVaddr: 0x%08X | Network ID: 0x%03X | Network Type: %d",
LMIC.devaddr, LMIC.netid & 0x001FFFFF, LMIC.netid & 0x00E00000);
ESP_LOGI(TAG, "RSSI: %d | SNR: %d", LMIC.rssi, LMIC.snr / 4);
ESP_LOGI(TAG, "Radio parameters: %s | %s | %s",
getSfName(updr2rps(LMIC.datarate)),
getBwName(updr2rps(LMIC.datarate)),
getCrName(updr2rps(LMIC.datarate)));
@@ -372,7 +371,7 @@ void lora_queuereset(void) { xQueueReset(LoraSendQueue); }
#if (TIME_SYNC_LORAWAN)
void IRAM_ATTR user_request_network_time_callback(void *pVoidUserUTCTime,
int flagSuccess) {
int flagSuccess) {
// Explicit conversion from void* to uint32_t* to avoid compiler errors
time_t *pUserUTCTime = (time_t *)pVoidUserUTCTime;
@@ -503,7 +502,7 @@ void myEventCallback(void *pUserData, ev_t ev) {
// receive message handler
void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
size_t nMsg) {
size_t nMsg) {
// display type of received data
if (nMsg)
@@ -601,32 +600,6 @@ void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
} // mac_decode()
uint8_t getBattLevel() {
/*
return values:
MCMD_DEVS_EXT_POWER = 0x00, // external power supply
MCMD_DEVS_BATT_MIN = 0x01, // min battery value
MCMD_DEVS_BATT_MAX = 0xFE, // max battery value
MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level
*/
#if (defined HAS_PMU || defined BAT_MEASURE_ADC)
uint16_t voltage = read_voltage();
switch (voltage) {
case 0:
return MCMD_DEVS_BATT_NOINFO;
case 0xffff:
return MCMD_DEVS_EXT_POWER;
default:
return (voltage > OTA_MIN_BATT ? MCMD_DEVS_BATT_MAX : MCMD_DEVS_BATT_MIN);
}
#else // we don't have any info on battery level
return MCMD_DEVS_BATT_NOINFO;
#endif
} // getBattLevel()
// u1_t os_getBattLevel(void) { return getBattLevel(); };
const char *getSfName(rps_t rps) {
const char *const t[] = {"FSK", "SF7", "SF8", "SF9",
"SF10", "SF11", "SF12", "SF?"};
@@ -643,4 +616,30 @@ const char *getCrName(rps_t rps) {
return t[getCr(rps)];
}
/*
u1_t os_getBattLevel() {
//return values:
//MCMD_DEVS_EXT_POWER = 0x00, // external power supply
//MCMD_DEVS_BATT_MIN = 0x01, // min battery value
//MCMD_DEVS_BATT_MAX = 0xFE, // max battery value
//MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level
#if (defined HAS_PMU || defined BAT_MEASURE_ADC)
uint16_t voltage = read_voltage();
switch (voltage) {
case 0:
return MCMD_DEVS_BATT_NOINFO;
case 0xffff:
return MCMD_DEVS_EXT_POWER;
default:
return (voltage > OTA_MIN_BATT ? MCMD_DEVS_BATT_MAX : MCMD_DEVS_BATT_MIN);
}
#else // we don't have any info on battery level
return MCMD_DEVS_BATT_NOINFO;
#endif
} // getBattLevel()
*/
#endif // HAS_LORA
-1
View File
@@ -346,7 +346,6 @@ void PayloadConvert::addSDS(sdsStatus_t sds) {
buffer[cursor++] = highByte((uint16_t)(sds.pm25 * 10));
buffer[cursor++] = lowByte((uint16_t)(sds.pm25 * 10));
#endif // HAS_SDS011
}
void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) {
switch (snifftype) {
+11 -13
View File
@@ -6,12 +6,6 @@
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;
@@ -25,7 +19,7 @@ bool sdcard_init() {
if (useSDCard)
createFile();
else
ESP_LOGD(TAG,"SD-card not found");
ESP_LOGD(TAG, "SD-card not found");
return useSDCard;
}
@@ -33,6 +27,9 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle) {
static int counterWrites = 0;
char tempBuffer[12 + 1];
time_t t = now();
#if (HAS_SDS011)
sdsStatus_t sds;
#endif
if (!useSDCard)
return;
@@ -43,12 +40,13 @@ 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.print( tempBuffer);
fileSDCard.print(tempBuffer);
#if (HAS_SDS011)
sprintf(tempBuffer, ",%5.1f,%4.1f", pm10, pm25);
fileSDCard.print( tempBuffer);
sds011_store(&sds);
sprintf(tempBuffer, ",%5.1f,%4.1f", sds.pm10, sds.pm25);
fileSDCard.print(tempBuffer);
#endif
fileSDCard.println( );
fileSDCard.println();
if (++counterWrites > 2) {
// force writing to SD-card
@@ -72,9 +70,9 @@ void createFile(void) {
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
if (fileSDCard) {
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
fileSDCard.print( SDCARD_FILE_HEADER );
fileSDCard.print(SDCARD_FILE_HEADER);
#if (HAS_SDS011)
fileSDCard.print( SDCARD_FILE_HEADER_SDS011 );
fileSDCard.print(SDCARD_FILE_HEADER_SDS011);
#endif
fileSDCard.println();
useSDCard = true;
+13 -6
View File
@@ -1,5 +1,7 @@
// routines for fetching data from the SDS011-sensor
#if (HAS_SDS011)
// Local logging tag
static const char TAG[] = __FILE__;
@@ -13,17 +15,14 @@ static HardwareSerial sdsSerial(2); // so we use it here
static SDS011 sdsSensor; // fine dust sensor
// the results of the sensor:
float pm25;
float pm10;
static float pm10, pm25;
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
sdsSensor.begin(&sdsSerial, SDS_RX, SDS_TX);
sds011_sleep(); // we do sleep/wakup by ourselves
return true;
}
@@ -42,6 +41,12 @@ void sds011_loop() {
return;
}
// retrieving stored data:
void sds011_store(sdsStatus_t *sds_store) {
sds_store->pm10 = pm10;
sds_store->pm25 = pm25;
}
// putting the SDS-sensor to sleep
void sds011_sleep(void) {
sdsSensor.sleep();
@@ -56,3 +61,5 @@ void sds011_wakeup() {
isSDS011Active = true;
}
}
#endif // HAS_SDS011
+7 -9
View File
@@ -3,11 +3,6 @@
Ticker sendcycler;
#if (HAS_SDS011)
extern float pm10;
extern float pm25;
#endif
void sendcycle() {
xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL);
}
@@ -68,9 +63,12 @@ void sendData() {
uint8_t bitmask = cfg.payloadmask;
uint8_t mask = 1;
#if (HAS_GPS)
#if (HAS_GPS)
gpsStatus_t gps_status;
#endif
#endif
#if (HAS_SDS011)
sdsStatus_t sds_status;
#endif
while (bitmask) {
switch (bitmask & mask) {
@@ -101,8 +99,8 @@ void sendData() {
payload.addCount(macs_ble, MAC_SNIFF_BLE);
#endif
#if (HAS_SDS011)
payload.addPM10(pm10);
payload.addPM25(pm25);
sds011_store(&sds_status);
payload.addSDS(sds_status);
#endif
SendPayload(COUNTERPORT, prio_normal);
// clear counter if not in cumulative counter mode