Merge branch 'SDS011' into SDS011

This commit is contained in:
Verkehrsrot 2020-03-14 07:38:22 +01:00 committed by GitHub
commit 8392b8c308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 89 additions and 77 deletions

View File

@ -58,7 +58,7 @@ Depending on board hardware following features are supported:
- Silicon unique ID - Silicon unique ID
- Battery voltage monitoring - Battery voltage monitoring
- GPS (Generic serial NMEA, or Quectel L76 I2C) - GPS (Generic serial NMEA, or Quectel L76 I2C)
- Environmental sensor (Bosch BMP180/BME280/BME680 I2C) - Environmental sensors (Bosch BMP180/BME280/BME680 I2C; SDS011 serial)
- Real Time Clock (Maxim DS3231 I2C) - Real Time Clock (Maxim DS3231 I2C)
- IF482 (serial) and DCF77 (gpio) time telegram generator - IF482 (serial) and DCF77 (gpio) time telegram generator
- Switch external power / battery - Switch external power / battery
@ -167,7 +167,7 @@ by pressing the button of the device.
# Sensors and Peripherals # Sensors and Peripherals
You can add up to 3 user defined sensors. Insert sensor's payload scheme in [*sensor.cpp*](src/sensor.cpp). Bosch BMP180 / BME280 / BME680 environment sensors are supported. Enable flag *lib_deps_sensors* for your board in [*platformio.ini*](src/platformio.ini) and configure BME in board's hal file before build. If you need Bosch's proprietary BSEC libraray (e.g. to get indoor air quality value from BME680) further enable *build_flags_sensors*, which comes on the price of reduced RAM and increased build size. RTC DS3231, generic serial NMEA GPS, I2C LoPy GPS are supported, and to be configured in board's hal file. See [*generic.h*](src/hal/generic.h) for all options and for proper configuration of BME280/BME680. You can add up to 3 user defined sensors. Insert sensor's payload scheme in [*sensor.cpp*](src/sensor.cpp). Bosch BMP180 / BME280 / BME680 environment sensors are supported. Enable flag *lib_deps_sensors* for your board in [*platformio.ini*](src/platformio.ini) and configure BME in board's hal file before build. If you need Bosch's proprietary BSEC libraray (e.g. to get indoor air quality value from BME680) further enable *build_flags_sensors*, which comes on the price of reduced RAM and increased build size. Furthermore, SDS011, RTC DS3231, generic serial NMEA GPS, I2C LoPy GPS are supported, and to be configured in board's hal file. See [*generic.h*](src/hal/generic.h) for all options and for proper configuration of BME280/BME680.
Output of user sensor data can be switched by user remote control command 0x14 sent to Port 2. Output of user sensor data can be switched by user remote control command 0x14 sent to Port 2.
@ -548,4 +548,4 @@ Thanks to
- [terrillmoore](https://github.com/mcci-catena) for maintaining the LMIC for arduino LoRaWAN stack - [terrillmoore](https://github.com/mcci-catena) for maintaining the LMIC for arduino LoRaWAN stack
- [sbamueller](https://github.com/sbamueller) for writing the tutorial in Make Magazine - [sbamueller](https://github.com/sbamueller) for writing the tutorial in Make Magazine
- [Stefan](https://github.com/nerdyscout) for paxcounter opensensebox integration - [Stefan](https://github.com/nerdyscout) for paxcounter opensensebox integration
- [August Quint](https://github.com/AugustQu) for adding SD card data logger support - [August Quint](https://github.com/AugustQu) for adding SD card data logger and SDS011 support

View File

@ -111,6 +111,11 @@ typedef struct {
float gas; // raw gas sensor signal float gas; // raw gas sensor signal
} bmeStatus_t; } bmeStatus_t;
typedef struct {
float pm10;
float pm25;
} sdsStatus_t;
extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs; extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
extern std::array<uint64_t, 0xff>::iterator it; extern std::array<uint64_t, 0xff>::iterator it;
extern std::array<uint64_t, 0xff> beacons; extern std::array<uint64_t, 0xff> beacons;

View File

@ -49,7 +49,7 @@ void IRAM_ATTR myRxCallback(void *pUserData, uint8_t port,
void IRAM_ATTR myTxCallback(void *pUserData, int fSuccess); void IRAM_ATTR myTxCallback(void *pUserData, int fSuccess);
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[], void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
const uint8_t tablesize); const uint8_t tablesize);
uint8_t getBattLevel(void); //u1_t os_getBattLevel(void);
const char *getSfName(rps_t rps); const char *getSfName(rps_t rps);
const char *getBwName(rps_t rps); const char *getBwName(rps_t rps);
const char *getCrName(rps_t rps); const char *getCrName(rps_t rps);

View File

@ -1,6 +1,7 @@
#ifndef _SDS011READ_H #ifndef _SDS011READ_H
#define _SDS011READ_H #define _SDS011READ_H
#include "globals.h"
#include <SDS011.h> #include <SDS011.h>
#define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25" #define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25"
@ -9,5 +10,6 @@ bool sds011_init();
void sds011_loop(); void sds011_loop();
void sds011_sleep(void); void sds011_sleep(void);
void sds011_wakeup(void); void sds011_wakeup(void);
void sds011_store(sdsStatus_t *sds_store);
#endif // _SDS011READ_H #endif // _SDS011READ_H

View File

@ -45,15 +45,15 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
[common] [common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c" ; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.9.90 release_version = 1.9.91
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 2 debug_level = 3
extra_scripts = pre:build.py extra_scripts = pre:build.py
otakeyfile = ota.conf otakeyfile = ota.conf
lorakeyfile = loraconf.h lorakeyfile = loraconf.h
lmicconfigfile = lmic_config.h lmicconfigfile = lmic_config.h
platform_espressif32 = espressif32@1.11.1 platform_espressif32 = espressif32@1.11.2
monitor_speed = 115200 monitor_speed = 115200
upload_speed = 115200 upload_speed = 115200
lib_deps_lora = lib_deps_lora =
@ -73,12 +73,11 @@ lib_deps_sensors =
Adafruit BME280 Library@>=2.0.0 Adafruit BME280 Library@>=2.0.0
Adafruit BMP085 Library@>=1.0.1 Adafruit BMP085 Library@>=1.0.1
BSEC Software Library@1.5.1474 BSEC Software Library@1.5.1474
;SDS011 sensor Library https://github.com/ricki-z/SDS011.git
https://github.com/ricki-z/SDS011.git#33fd8b6
lib_deps_basic = lib_deps_basic =
ArduinoJson@^5.13.1 ArduinoJson@^5.13.1
76@>=1.2.4 ; #76 Timezone by Jack Christensen 76@>=1.2.4 ; #76 Timezone by Jack Christensen
274@>=2.3.3 ; #274 RTC by Michael Miller 274@>=2.3.4 ; #274 RTC by Michael Miller
SimpleButton SimpleButton
AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He
esp32-micro-sdcard esp32-micro-sdcard

View File

@ -10,8 +10,7 @@ static const char TAG[] = __FILE__;
TinyGPSPlus gps; TinyGPSPlus gps;
TinyGPSCustom gpstime(gps, "GPZDA", 1); // field 1 = UTC time TinyGPSCustom gpstime(gps, "GPZDA", 1); // field 1 = UTC time
static const String ZDA_Request = "$EIGPQ,ZDA*39\r\n"; static const String ZDA_Request = "$EIGPQ,ZDA*39\r\n";
static gpsStatus_t gps_status = {0};
gpsStatus_t gps_status = {0};
TaskHandle_t GpsTask; TaskHandle_t GpsTask;
#ifdef GPS_SERIAL #ifdef GPS_SERIAL

View File

@ -48,8 +48,14 @@
//#define HAS_BMP180 //#define HAS_BMP180
//#define BMP180_ADDR 0x77 //#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 // 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_sx1276_radio 1 // select LoRa chip
//#define CFG_sx1272_radio 1 // select LoRa chip //#define CFG_sx1272_radio 1 // select LoRa chip

View File

@ -15,8 +15,8 @@
// SDS011 dust sensor settings // SDS011 dust sensor settings
#define HAS_SDS011 1 // use SDS011 #define HAS_SDS011 1 // use SDS011
// used pins on the ESP-side: // used pins on the ESP-side:
#define ESP_PIN_TX 19 // connect to RX on the SDS011 #define SDS_TX 19 // connect to RX on the SDS011
#define ESP_PIN_RX 23 // connect to TX 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 HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define CFG_sx1276_radio 1 // HPD13A LoRa SoC

View File

@ -1,13 +1,10 @@
// Basic Config // Basic Config
#if (HAS_LORA) #if (HAS_LORA)
#include "lorawan.h" #include "lorawan.h"
#endif
// Local logging Tag // Local logging Tag
static const char TAG[] = "lora"; static const char TAG[] = "lora";
#if (HAS_LORA)
#if CLOCK_ERROR_PROCENTAGE > 7 #if CLOCK_ERROR_PROCENTAGE > 7
#warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects #warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects
#endif #endif
@ -101,8 +98,10 @@ void lora_setupForNetwork(bool preJoin) {
if (!cfg.adrmode) if (!cfg.adrmode)
LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower); LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower);
// show current devaddr // show current devaddr
ESP_LOGI(TAG, "DEVaddr: %08X", LMIC.devaddr); ESP_LOGI(TAG, "DEVaddr: 0x%08X | Network ID: 0x%03X | Network Type: %d",
ESP_LOGI(TAG, "Radio parameters: %s / %s / %s", 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)), getSfName(updr2rps(LMIC.datarate)),
getBwName(updr2rps(LMIC.datarate)), getBwName(updr2rps(LMIC.datarate)),
getCrName(updr2rps(LMIC.datarate))); getCrName(updr2rps(LMIC.datarate)));
@ -601,32 +600,6 @@ void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
} // mac_decode() } // 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 *getSfName(rps_t rps) {
const char *const t[] = {"FSK", "SF7", "SF8", "SF9", const char *const t[] = {"FSK", "SF7", "SF8", "SF9",
"SF10", "SF11", "SF12", "SF?"}; "SF10", "SF11", "SF12", "SF?"};
@ -643,4 +616,30 @@ const char *getCrName(rps_t rps) {
return t[getCr(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 #endif // HAS_LORA

View File

@ -346,7 +346,6 @@ void PayloadConvert::addSDS(sdsStatus_t sds) {
buffer[cursor++] = highByte((uint16_t)(sds.pm25 * 10)); buffer[cursor++] = highByte((uint16_t)(sds.pm25 * 10));
buffer[cursor++] = lowByte((uint16_t)(sds.pm25 * 10)); buffer[cursor++] = lowByte((uint16_t)(sds.pm25 * 10));
#endif // HAS_SDS011 #endif // HAS_SDS011
}
void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) { void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) {
switch (snifftype) { switch (snifftype) {

View File

@ -6,12 +6,6 @@
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
#include "sdcard.h" #include "sdcard.h"
#if (HAS_SDS011)
#include <sds011read.h>
// the results of the sensor:
extern float pm25;
extern float pm10;
#endif
static bool useSDCard; static bool useSDCard;
@ -33,6 +27,9 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle) {
static int counterWrites = 0; static int counterWrites = 0;
char tempBuffer[12 + 1]; char tempBuffer[12 + 1];
time_t t = now(); time_t t = now();
#if (HAS_SDS011)
sdsStatus_t sds;
#endif
if (!useSDCard) if (!useSDCard)
return; return;
@ -45,7 +42,8 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle) {
sprintf(tempBuffer, "%d,%d", noWifi, noBle); sprintf(tempBuffer, "%d,%d", noWifi, noBle);
fileSDCard.print(tempBuffer); fileSDCard.print(tempBuffer);
#if (HAS_SDS011) #if (HAS_SDS011)
sprintf(tempBuffer, ",%5.1f,%4.1f", pm10, pm25); sds011_store(&sds);
sprintf(tempBuffer, ",%5.1f,%4.1f", sds.pm10, sds.pm25);
fileSDCard.print(tempBuffer); fileSDCard.print(tempBuffer);
#endif #endif
fileSDCard.println(); fileSDCard.println();

View File

@ -1,5 +1,7 @@
// routines for fetching data from the SDS011-sensor // routines for fetching data from the SDS011-sensor
#if (HAS_SDS011)
// Local logging tag // Local logging tag
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
@ -13,16 +15,13 @@ static HardwareSerial sdsSerial(2); // so we use it here
static SDS011 sdsSensor; // fine dust sensor static SDS011 sdsSensor; // fine dust sensor
// the results of the sensor: // the results of the sensor:
float pm25; static float pm10, pm25;
float pm10;
boolean isSDS011Active; boolean isSDS011Active;
// init // init
bool sds011_init() { bool sds011_init() {
pm25 = pm10 = 0.0; pm25 = pm10 = 0.0;
#if (HAS_SDS011) sdsSensor.begin(&sdsSerial, SDS_RX, SDS_TX);
sdsSensor.begin (&sdsSerial, ESP_PIN_RX, ESP_PIN_TX);
#endif
sds011_sleep(); // we do sleep/wakup by ourselves sds011_sleep(); // we do sleep/wakup by ourselves
return true; return true;
} }
@ -42,6 +41,12 @@ void sds011_loop() {
return; 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 // putting the SDS-sensor to sleep
void sds011_sleep(void) { void sds011_sleep(void) {
sdsSensor.sleep(); sdsSensor.sleep();
@ -56,3 +61,5 @@ void sds011_wakeup() {
isSDS011Active = true; isSDS011Active = true;
} }
} }
#endif // HAS_SDS011

View File

@ -3,11 +3,6 @@
Ticker sendcycler; Ticker sendcycler;
#if (HAS_SDS011)
extern float pm10;
extern float pm25;
#endif
void sendcycle() { void sendcycle() {
xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL); xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL);
} }
@ -71,6 +66,9 @@ void sendData() {
#if (HAS_GPS) #if (HAS_GPS)
gpsStatus_t gps_status; gpsStatus_t gps_status;
#endif #endif
#if (HAS_SDS011)
sdsStatus_t sds_status;
#endif
while (bitmask) { while (bitmask) {
switch (bitmask & mask) { switch (bitmask & mask) {
@ -101,8 +99,8 @@ void sendData() {
payload.addCount(macs_ble, MAC_SNIFF_BLE); payload.addCount(macs_ble, MAC_SNIFF_BLE);
#endif #endif
#if (HAS_SDS011) #if (HAS_SDS011)
payload.addPM10(pm10); sds011_store(&sds_status);
payload.addPM25(pm25); payload.addSDS(sds_status);
#endif #endif
SendPayload(COUNTERPORT, prio_normal); SendPayload(COUNTERPORT, prio_normal);
// clear counter if not in cumulative counter mode // clear counter if not in cumulative counter mode