All Projects → bertmelis → SDS011

bertmelis / SDS011

Licence: MIT License
Non blocking SDS011 sensor library for ESP8266

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to SDS011

EnviroMonitorStation
Arduino compatible software for ESP8266 based environmental monitoring station. Includes temperature, humidity, barometric pressure and PM2.5, PM10 dust monitoring
Stars: ✭ 71 (+373.33%)
Mutual labels:  esp8266, sensor, pm25, pm10
ESPHome-Air-Quality-Monitor
ESPHome configuration for a DIY indoor air quality monitor for CO₂ concentration, PM2.5 and PM10 concentrations, and temperature, humidity and pressure
Stars: ✭ 42 (+180%)
Mutual labels:  esp8266, pm25, pm10, sds011
DustViewerSharp
UART-USB based dust sensor viewer(and also logging) program by C#
Stars: ✭ 38 (+153.33%)
Mutual labels:  pm25, pm10, sds011
Pysmartnode
Micropython Smarthome framework
Stars: ✭ 58 (+286.67%)
Mutual labels:  esp8266, sensor
M5Stack-Air-Quality-ESPHome
ESPHome configuration for M5Stack's PM2.5 Air Quality Kit with the PMSA003 particulate matter sensor and the SHT20 temperature and humidity sensor
Stars: ✭ 19 (+26.67%)
Mutual labels:  pm25, pm10
Esp8266 Tiny Door And Window Sensor
Battery powered door and window sensor with ultra low standby power. Arduino, ESP-12, Reed switch, ATtiny, LDO
Stars: ✭ 146 (+873.33%)
Mutual labels:  esp8266, sensor
Onewirehub
OneWire slave device emulator
Stars: ✭ 195 (+1200%)
Mutual labels:  esp8266, sensor
Mycontroller V1 Legacy
The Open Source Controller
Stars: ✭ 135 (+800%)
Mutual labels:  esp8266, sensor
openair
国家空气质量数据获取库,包含完整的API,不再信任地方检测站
Stars: ✭ 85 (+466.67%)
Mutual labels:  pm25, pm10
canairio sensorlib
Particle sensor manager for multiple sensors: Honeywell, Plantower, Panasonic, Sensirion, etc. This is sensors layer of CanAirIO project too.
Stars: ✭ 24 (+60%)
Mutual labels:  sensor, pm25
PMserial
Arduino library for PM sensors with serial interface
Stars: ✭ 41 (+173.33%)
Mutual labels:  pm25, pm10
esp-homekit-multi-sensor
Homekit muti sensor, motion, temperate, humidity and light with OTA
Stars: ✭ 15 (+0%)
Mutual labels:  esp8266, sensor
sps30
Sensirion SPS30 driver for ESP32, SODAQ, MEGA2560, UNO, ESP8266, Particle-photon on UART OR I2C coummunication
Stars: ✭ 57 (+280%)
Mutual labels:  esp8266, sensor
VisonicAlarm-for-Hassio
Visonic/Bentel/Tyco Alarm System integrtation for Home Assistant
Stars: ✭ 14 (-6.67%)
Mutual labels:  sensor
hassio
ESPHome Hass.io addon files
Stars: ✭ 175 (+1066.67%)
Mutual labels:  esp8266
WebServer tng
ESP8266/ESP32 WebServer
Stars: ✭ 65 (+333.33%)
Mutual labels:  esp8266
Cicada-FW
IoT Communications Module for Energy Access. An easy way to get production ready, bi-directional communications for your IoT embedded device. Proiect supported by the EnAccess Foundation - https://enaccess.org
Stars: ✭ 12 (-20%)
Mutual labels:  esp8266
arduino-esp8266-mh-z19-serial
CO2, humidity and temperature sensor on ESP8266
Stars: ✭ 57 (+280%)
Mutual labels:  esp8266
wbec
Control Heidelberg Wallbox Energy Control over WiFi using ESP8266
Stars: ✭ 62 (+313.33%)
Mutual labels:  esp8266
kwswitch
智能开关平台,包含服务端、硬件端、安卓端和前端。关键词:物联网开关、远程开关、红外线遥控开关、WIFI继电器、MQTT协议、ESP8266、Iot smart switch、Android、Spring boot、Vue、Arduino
Stars: ✭ 59 (+293.33%)
Mutual labels:  esp8266

SDS011

Build Status

SDS011 particle matter sensor library for the Arduino framework for ESP8266 and ESP32.

This is yet another SDS011 library, this time completely non blocling. It does come with a loop()-method to poll the serial port.

Installation

Usage

You cannot use Serial on ESP8266 as there's only 1 full UART available which will be used by the sensor.

To do something useful you can combine this lib with MQTT (like async-mqtt-client) as in the example below.

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <SDS011.h>

const char SSID[] = "My_WiFi";
const char PASS[] = "My_Pass";
const IPAddress BROKER = {192, 168, 1, 10};

SDS011 sds011;
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;

bool connected = false;

void connectToWifi() {
  WiFi.begin(SSID, PASS);
}

void onWifiConnect(const WiFiEventStationModeGotIP& event) {
  connectToMqtt();
}

void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
  mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
  wifiReconnectTimer.once(2, connectToWifi);
}

void connectToMqtt() {
  mqttClient.connect();
}

void onMqttConnected(bool sessionPresent) {
  connected = true;
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  connected = false;
  if (WiFi.isConnected()) {
    mqttReconnectTimer.once(2, connectToMqtt);
  }
}

void setup() {
  wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
  wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

  mqttClient.onConnect(onMqttConnected);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.setServer(BROKER, 1883);

  sds011.setup(&Serial);
  sds011.onData([](float pm25Value, float pm10Value) {
    if (connected) {
      mqttClient.publish("/SENSOR/PM2_5", 1, false, String(pm25Value, 1).c_str());
      mqttClient.publish("/SENSOR/PM10", 1, false, String(pm10Value, 1).c_str());
    }
  });
  sds011.onResponse([](uint8_t command, uint8_t set, uint8_t result){
    // command has been executed
  });
  sds011.onError([](int8_t error){
    // error happened
    // -1: CRC error
  });
  sds011.setWorkingPeriod(5);

  connectToWifi();
}

void loop() {
  sds011.loop();
}

To Do

  • adjust readings based on humidity
  • possible timeout after sending a command
  • implement missing commands
  • multiple sensors (apparently the firmware supports this. However, they implemented hardware using 1-1 UART) ???

Issues, improvements?

Please create a ticket or pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].