Merge branch 'SDS011' into SDS011
This commit is contained in:
commit
8392b8c308
@ -58,7 +58,7 @@ Depending on board hardware following features are supported:
|
||||
- Silicon unique ID
|
||||
- Battery voltage monitoring
|
||||
- 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)
|
||||
- IF482 (serial) and DCF77 (gpio) time telegram generator
|
||||
- Switch external power / battery
|
||||
@ -167,7 +167,7 @@ by pressing the button of the device.
|
||||
|
||||
# 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.
|
||||
|
||||
@ -548,4 +548,4 @@ Thanks to
|
||||
- [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
|
||||
- [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
|
||||
|
@ -111,6 +111,11 @@ typedef struct {
|
||||
float gas; // raw gas sensor signal
|
||||
} 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::array<uint64_t, 0xff>::iterator it;
|
||||
extern std::array<uint64_t, 0xff> beacons;
|
||||
|
@ -49,7 +49,7 @@ void IRAM_ATTR myRxCallback(void *pUserData, uint8_t port,
|
||||
void IRAM_ATTR myTxCallback(void *pUserData, int fSuccess);
|
||||
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
|
||||
const uint8_t tablesize);
|
||||
uint8_t getBattLevel(void);
|
||||
//u1_t os_getBattLevel(void);
|
||||
const char *getSfName(rps_t rps);
|
||||
const char *getBwName(rps_t rps);
|
||||
const char *getCrName(rps_t rps);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef _SDS011READ_H
|
||||
#define _SDS011READ_H
|
||||
|
||||
#include "globals.h"
|
||||
#include <SDS011.h>
|
||||
|
||||
#define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25"
|
||||
@ -9,5 +10,6 @@ bool sds011_init();
|
||||
void sds011_loop();
|
||||
void sds011_sleep(void);
|
||||
void sds011_wakeup(void);
|
||||
void sds011_store(sdsStatus_t *sds_store);
|
||||
|
||||
#endif // _SDS011READ_H
|
||||
|
@ -45,15 +45,15 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
|
||||
|
||||
[common]
|
||||
; 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!
|
||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
||||
debug_level = 2
|
||||
debug_level = 3
|
||||
extra_scripts = pre:build.py
|
||||
otakeyfile = ota.conf
|
||||
lorakeyfile = loraconf.h
|
||||
lmicconfigfile = lmic_config.h
|
||||
platform_espressif32 = espressif32@1.11.1
|
||||
platform_espressif32 = espressif32@1.11.2
|
||||
monitor_speed = 115200
|
||||
upload_speed = 115200
|
||||
lib_deps_lora =
|
||||
@ -73,12 +73,11 @@ lib_deps_sensors =
|
||||
Adafruit BME280 Library@>=2.0.0
|
||||
Adafruit BMP085 Library@>=1.0.1
|
||||
BSEC Software Library@1.5.1474
|
||||
;SDS011 sensor Library
|
||||
https://github.com/ricki-z/SDS011.git#33fd8b6
|
||||
https://github.com/ricki-z/SDS011.git
|
||||
lib_deps_basic =
|
||||
ArduinoJson@^5.13.1
|
||||
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
|
||||
AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He
|
||||
esp32-micro-sdcard
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)));
|
||||
@ -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
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
@ -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;
|
||||
@ -45,7 +42,8 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle) {
|
||||
sprintf(tempBuffer, "%d,%d", noWifi, noBle);
|
||||
fileSDCard.print(tempBuffer);
|
||||
#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);
|
||||
#endif
|
||||
fileSDCard.println();
|
||||
|
@ -1,5 +1,7 @@
|
||||
// routines for fetching data from the SDS011-sensor
|
||||
|
||||
#if (HAS_SDS011)
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = __FILE__;
|
||||
|
||||
@ -13,16 +15,13 @@ 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
|
||||
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
|
||||
|
@ -3,11 +3,6 @@
|
||||
|
||||
Ticker sendcycler;
|
||||
|
||||
#if (HAS_SDS011)
|
||||
extern float pm10;
|
||||
extern float pm25;
|
||||
#endif
|
||||
|
||||
void sendcycle() {
|
||||
xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL);
|
||||
}
|
||||
@ -71,6 +66,9 @@ void sendData() {
|
||||
#if (HAS_GPS)
|
||||
gpsStatus_t gps_status;
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user