Browse Source

change sds011 library to a better one

main
Hendrik Langer 7 years ago
parent
commit
756e25c10e
  1. 1
      README.md
  2. 2
      platformio.ini
  3. 28
      src/main.cpp
  4. 2
      src/main.h

1
README.md

@ -91,7 +91,6 @@ RadiationD-v1.1(CAJOE):
measures up to ~30V
## ToDo
* change SDS011 library to a better one. pio id 5422?: https://github.com/lewapek/sds-dust-sensors-arduino-library
* https://tinker.yeoman.com.au/2016/05/29/running-nodemcu-on-a-battery-esp8266-low-power-consumption-revisited/
* deep_sleep (connect D0 to RST)
* https://hackaday.com/2014/10/25/use-a-cheap-pin-diode-as-a-geiger-counter/ (opengeiger.de/elektronik.html)

2
platformio.ini

@ -31,7 +31,7 @@ lib_deps =
DHT sensor library
; SDS011 sensor Library
; https://github.com/Zanop/SDS011.git#more-sensor-modes
https://github.com/h3ndrik/SDS011.git#more-sensor-modes
Nova Fitness Sds dust sensors library
EspSoftwareSerial
RunningAverage
MQTT

28
src/main.cpp

@ -23,7 +23,7 @@ extern "C" {
#include <RunningAverage.h>
#include <SDS011.h>
#include <SdsDustSensor.h>
#include <XD0OTA.h>
#include "main.h"
@ -89,7 +89,7 @@ RunningAverage geigeraverage(10);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
DHT dht(DHT22_PIN, DHTTYPE);
SDS011 sds;
SdsDustSensor sds(SDS_RX, SDS_TX);
volatile unsigned long geiger_counts = 0;
unsigned long geiger_previousMillis;
unsigned long last_dhcp = 0;
@ -156,11 +156,15 @@ void ICACHE_FLASH_ATTR sendValues() {
sd.voltage = analogRead(A0)*0.04285078 -0.05942125; // by linear regression for my(!) voltage divider. else: sd.voltage = analogRead(A0)*3.3*(R1+R2)/(R2*1024)
#endif
int sds_error = sds.query(&(sd.p25), &(sd.p10));
if(!sds_error) {
// DEBUG_MSG("SDS011 updated.\n");
// sds.wakeup(); delay(30000); // working 30 seconds
PmResult pm = sds.queryPm();
bool sds_updated = false;
if(pm.isOk()) {
sd.p25 = pm.pm25;
sd.p10 = pm.pm10;
sds_updated = true;
} else {
// DEBUG_MSG("SDS011 no new values.\n");
sds_updated = false;
}
// sds.sleep();
@ -178,8 +182,8 @@ void ICACHE_FLASH_ATTR sendValues() {
DEBUG_MSG("Humidity : %6.2f%% (DHT22)\n", sd.humidity);
DEBUG_MSG("Temperature : %6.2f°C (BMP180)\n", sd.temp2);
DEBUG_MSG("Pressure : %6.2fhPa (BMP180)\n", sd.pressure);
if (!sds_error) DEBUG_MSG("Particles 10 : %6.2fµg/m³ (SDS011)\n", sd.p10);
if (!sds_error) DEBUG_MSG("Particles 2.5: %6.2fµg/m³ (SDS011)\n", sd.p25);
if (sds_updated) DEBUG_MSG("Particles 10 : %6.2fµg/m³ (SDS011)\n", sd.p10);
if (sds_updated) DEBUG_MSG("Particles 2.5: %6.2fµg/m³ (SDS011)\n", sd.p25);
if (sd.cpm > 0) DEBUG_MSG("Radiation : %6.2fµSv/h (J305)\n", sd.radioactivity);
DEBUG_MSG("Voltage : %6.2fV (ESP8266)\n", sd.voltage);
@ -203,7 +207,7 @@ void ICACHE_FLASH_ATTR sendValues() {
pressureObject["value"] = sd.pressure;
root["pressure"] = sd.pressure;
if (!sds_error) {
if (sds_updated) {
JsonObject& pm10Object = array.createNestedObject();
pm10Object["sensor"] = SENSOR4_ID;
pm10Object["value"] = sd.p10;
@ -385,9 +389,9 @@ void setup() {
//wifi_status_led_uninstall();
sds.begin(SDS_TX, SDS_RX);
sds.mode_mon_300();
sds.mode_query();
sds.begin();
sds.setCustomWorkingPeriod(5); // sensor sends data every 5 minutes
sds.setQueryReportingMode(); // ensures sensor is in 'query' reporting mode
Wire.begin(BMP_SDA, BMP_SCL);
if (!bmp.begin(BMP085_MODE_STANDARD)) {

2
src/main.h

@ -7,6 +7,6 @@
#define DEBUG_MSG(...)
#endif
#define FW_VERSION 17
#define FW_VERSION 18
#endif /* _MAIN_H */

Loading…
Cancel
Save