SDS011 or UART bug?

hi,
I just got an SDS011 sensor and connected that to a clean ESP8266 (ESP12e) according to the instructions and config entries here in the official ESPHome page. Several builds and tries and can’t get it to work (it does connect over OTA), so I tried to add the code to an existing board (to exclude the chance that the board was defective)

Working code:

esphome:
  name: weatherstation
  platform: ESP8266
  board: esp12e

wifi:
  ssid: SSID
  password: WifiPassword

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Weatherstation Fallback Hotspot"
    password: "anuCUTxEIfKo"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: Password

ota:
  password: Password

# configuration DHT22 on pin D1
sensor:
  - platform: dht
    pin: GPIO5
    model: DHT22
    temperature:
      name: "Weatherstation Temperature"
    humidity:
      name: "Weatherstation Humidity"
    update_interval: 60s

When adding the lines for UART and SDS011:

esphome:
  name: weatherstation
  platform: ESP8266
  board: esp12e

wifi:
  ssid: SSID
  password: WifiPassword

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Weatherstation Fallback Hotspot"
    password: "anuCUTxEIfKo"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: Password

ota:
  password: Password

uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600

# configuration DHT22 on pin D1 and SDS011
sensor:
  - platform: dht
    pin: GPIO5
    model: DHT22
    temperature:
      name: "Weatherstation Temperature"
    humidity:
      name: "Weatherstation Humidity"
    update_interval: 60s
  - platform: sds011
    pm_2_5:
      name: "Particulate Matter <2.5Β΅m Concentration"
    pm_10_0:
      name: "Particulate Matter <10.0Β΅m Concentration"

I get the connection error… see entire log:

ESPHome Dashboardmore_vert
OTA (Over-The-Air)
memory
irrecevier launchmore_vert
 . Full path: /config/esphome/irrecevier.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
memory
testespmore_vert
 . Full path: /config/esphome/testesp.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
memory
weatherstationmore_vert
 . Full path: /config/esphome/weatherstation.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
Compile And Upload weatherstation.yaml
INFO Reading configuration /config/esphome/weatherstation.yaml...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/esphome/weatherstation
Processing weatherstation (board: esp12e; framework: arduino; platform: [email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 2.20502.0 (2.5.2) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - toolchain-xtensa 1.40802.2 (4.8.2)
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.2
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.6
|   |-- <ESPAsyncTCP-esphome> 1.2.2
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
Compiling /data/weatherstation/.pioenvs/weatherstation/src/main.cpp.o
Linking /data/weatherstation/.pioenvs/weatherstation/firmware.elf
Building /data/weatherstation/.pioenvs/weatherstation/firmware.bin
Retrieving maximum program size /data/weatherstation/.pioenvs/weatherstation/firmware.elf
Checking size /data/weatherstation/.pioenvs/weatherstation/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=====     ]  46.2% (used 37820 bytes from 81920 bytes)
Flash: [====      ]  39.3% (used 410300 bytes from 1044464 bytes)
Creating BIN file "/data/weatherstation/.pioenvs/weatherstation/firmware.bin" using "/data/weatherstation/.pioenvs/weatherstation/firmware.elf"
========================= [SUCCESS] Took 9.88 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of weatherstation.local
INFO  -> 192.168.1.100
INFO Uploading /data/weatherstation/.pioenvs/weatherstation/firmware.bin (414448 bytes)
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from weatherstation.local using esphome API
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: timed out). Re-Trying in 1 seconds
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: timed out). Re-Trying in 1 seconds
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: [Errno 113] No route to host). Re-Trying in 2 seconds
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: [Errno 113] No route to host). Re-Trying in 3 seconds
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: [Errno 113] No route to host). Re-Trying in 5 seconds

When exiting and leaving the screen for a short time, ESP comes online and when checking the log, I get this:

INFO Reading configuration /config/esphome/weatherstation.yaml...
INFO Starting log output from weatherstation.local using esphome API
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: [Errno 111] Connection refused). Re-Trying in 1 seconds
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: [Errno 111] Connection refused). Re-Trying in 1 seconds
INFO Connecting to weatherstation.local:6053 (192.168.1.100)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.100: [Errno 111] Connection refused). Re-Trying in 2 seconds

Logically, removing the code back to the original code, all is fine again…

I am definitely not an expert, but really not seeing what could be wrong … any ideas what it could be would be appreciated.

Just one tip:

if you use the ESPHome Flasher and use it as a logger, you get every log output of the ESP including the stuff that you do not see in the HA ESPHome logging thing since the ESP is not connected yet.
The pre wifi connected logs often helped me out in such scenarios.

Thanks!
Tried that now and basically took the generated .bin from ESPHome. flashed with esphome-flasher. All seemed fine until the connection with Wifi was made according the log and then the below… I really do not know what to make of it.

Using 'COM6' as serial port.
Unexpected error: could not open port 'COM6': PermissionError(13, 'Access is denied.', None, 5)
[20:33:57][C][ota:364]: There have been 5 suspected unsuccess[20:33:57] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[20:33:57]
[20:33:57]load 0x4010f000, len 1384, room 16 
[20:33:57]tail 8
[20:33:57]chksum 0x2d
[20:33:57]csum 0x2d
[20:33:57]v8b899c12
[20:33:57]~ld
[20:33:57][I][logger:156]: Log initialized
[20:34:08][C][ota:364]: There have been 6 suspected unsuccess[20:34:08] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[20:34:08]
[20:34:08]load 0x4010f000, len 1384, room 16 
[20:34:08]tail 8
[20:34:08]chksum 0x2d
[20:34:08]csum 0x2d
[20:34:08]v8b899c12
[20:34:08]~ld
[20:34:08][I][logger:156]: Log initialized
[20:34:19][C][ota:364]: There have been 7 suspected unsuccess[20:34:19] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[20:34:19]
[20:34:19]load 0x4010f000, len 1384, room 16 
[20:34:19]tail 8
[20:34:19]chksum 0x2d
[20:34:19]csum 0x2d
[20:34:19]v8b899c12
[20:34:19]~ld
[20:34:19][I][logger:156]: Log initialized
[20:34:30][C][ota:364]: There have been 8 suspected unsuccess[20:34:30] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[20:34:30]
[20:34:30]load 0x4010f000, len 1384, room 16 
[20:34:30]tail 8
[20:34:30]chksum 0x2d
[20:34:30]csum 0x2d
[20:34:30]v8b899c12
[20:34:30]~ld
[20:34:30][I][logger:156]: Log initialized
[20:34:41][C][ota:364]: There have been 9 suspected unsuccess[20:34:41] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[20:34:41]
[20:34:41]load 0x4010f000, len 1384, room 16 
[20:34:41]tail 8
[20:34:41]chksum 0x2d
[20:34:41]csum 0x2d
[20:34:41]v8b899c12
[20:34:41]~ld
[20:34:41][I][logger:156]: Log initialized
[20:34:41][C][ota:364]: There have been 10 suspected unsuccessful boot attempts.
[20:34:41][E][ota:369]: Boot loop detected. Proceeding to safe mode.
[20:34:41][I][app:028]: Running through setup()...
[20:34:41][C][wifi:033]: Setting up WiFi...
[20:34:41][D][wifi:304]: Starting scan...
[20:34:47][D][wifi:319]: Found networks:
[20:34:47][I][wifi:365]: - 'Holland_Vilamari' (B4:FB:E4:74:10:7B) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:366]:     Channel: 6
[20:34:47][D][wifi:367]:     RSSI: -54 dB
[20:34:47][I][wifi:365]: - 'Holland_Vilamari' (18:E8:29:A4:1D:2D) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:366]:     Channel: 1
[20:34:47][D][wifi:367]:     RSSI: -84 dB
[20:34:47][D][wifi:369]: - '' (B6:FB:E4:74:10:7B) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'ONO3713' (08:95:2A:81:83:B6) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - '' (FA:8F:CA:76:F7:05) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MiFibra-D0B2' (94:6A:B0:9F:D0:B4) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'TP-LINK_2FC9E4' (EC:08:6B:2F:C9:E4) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'AndroidAP05ee' (0A:C5:E1:A5:05:EE) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'carcamari2' (80:29:94:71:82:37) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'AVG2017' (F0:9F:C2:37:94:49) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MiFibra-4E8D' (EC:F4:51:D9:1C:90) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'SETUP' (C0:F8:DA:1F:A4:50) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MOVISTAR_6076' (34:57:60:B2:60:78) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - '' (F6:9F:C2:37:94:49) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'vodafoneB2D5' (F4:E3:FB:CC:B2:DC) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'PS4-33D51CFE27AD' (60:5B:B4:46:EE:C7) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'sagemcom0150' (F0:81:75:1E:01:56) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MIWIFI_2G_aPtM' (D8:7D:7F:88:6A:AD) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - '_ONOWiFi' (F4:E3:FB:CC:B2:DD) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MOVISTAR_BC05' (98:97:D1:A2:BC:06) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MOVISTAR_6210' (C8:B4:22:DE:62:1F) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - '' (1A:E8:29:A4:1D:2D) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'Suite_Pier' (04:95:E6:7A:77:E9) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'Arda' (44:FE:3B:39:BE:EA) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'carcamari2_EXT' (B0:95:75:80:55:5B) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MOVISTAR_CASA' (F8:BF:53:C0:9A:B1) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MiFibra-1D69' (EC:F4:51:6B:1D:6B) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MiFibra-3F8C' (EC:F4:51:9B:3F:8E) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'WIFIDECASA' (08:7E:64:EF:BA:80) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MiFibra-8753' (EC:F4:51:54:87:55) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MiFibra-4E8D' (48:8D:36:FD:4E:8F) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MIWIFI_2G_QJq6' (8C:E1:17:EF:47:AD) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MIWIFI_2G_Ghg4' (88:5D:FB:CB:DB:10) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MOVISTAR_2' (E8:DE:27:C8:68:ED) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MOVISTAR_8C3B' (D4:7B:B0:8A:8C:3C) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'VILAMARI_EXT' (D4:6E:0E:2F:17:BB) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'MIWIFI_2G_QmRa' (D8:7D:7F:87:FE:BD) β–‚β–„β–†β–ˆ
[20:34:47][D][wifi:369]: - 'OPPO A5 2020' (F4:D6:20:6A:91:5E) β–‚β–„β–†β–ˆ
[20:34:47][I][wifi:193]: WiFi Connecting to 'Holland_Vilamari'...
[20:34:50][I][wifi:423]: WiFi Connected!
[20:34:50][C][wifi:283]:   SSID: 'Holland_Vilamari'
[20:34:50][C][wifi:284]:   IP Address: 192.168.1.102
[20:34:50][C][wifi:286]:   BSSID: B4:FB:E4:74:10:7B
[20:34:50][C][wifi:287]:   Hostname: 'irrecevier'
[20:34:50][C][wifi:291]:   Signal strength: -58 dB β–‚β–„β–†β–ˆ
[20:34:50][C][wifi:295]:   Channel: 6
[20:34:50][C][wifi:296]:   Subnet: 255.255.255.0
[20:34:50][C][wifi:297]:   Gateway: 192.168.1.1
[20:34:50][C][wifi:298]:   DNS1: xx.xx.xx.xxx
[20:34:50][C][wifi:299]:   DNS2: xx.xx.xx.xxx
[20:34:50][C][ota:029]: Over-The-Air Updates:
[20:34:50][C][ota:030]:   Address: irrecevier.local:8266
[20:34:50][C][ota:032]:   Using Password.
[20:34:50][W][ota:036]: Last Boot was an unhandled reset, will proceed to safe mode in 0 restarts
[20:34:50][I][app:058]: setup() finished successfully!
[20:34:50][I][ota:379]: Waiting for OTA attempt.
[20:34:50][I][app:100]: ESPHome version 1.14.5 compiled on Sep 11 2020, 20:25:27
[20:34:50][C][wifi:415]: WiFi:
[20:34:50][C][wifi:283]:   SSID: 'Holland_Vilamari'
[20:34:50][C][wifi:284]:   IP Address: 192.168.1.102
[20:34:50][C][wifi:286]:   BSSID: B4:FB:E4:74:10:7B
[20:34:50][C][wifi:287]:   Hostname: 'irrecevier'
[20:34:50][C][wifi:291]:   Signal strength: -58 dB β–‚β–„β–†β–ˆ
[20:34:50][C][wifi:295]:   Channel: 6
[20:34:50][C][wifi:296]:   Subnet: 255.255.255.0
[20:34:50][C][wifi:297]:   Gateway: 192.168.1.1
[20:34:50][C][wifi:298]:   DNS1: xx.xx.xx.xxx
[20:34:50][C][wifi:299]:   DNS2: xx.xx.xx.xxx
[20:34:50][C][logger:175]: Logger:
[20:34:50][C][logger:176]:   Level: DEBUG
[20:34:50][C][logger:177]:   Log Baud Rate: 115200
[20:34:50][C][logger:178]:   Hardware UART: UART0
[20:34:51][C][ota:029]: Over-The-Air Updates:
[20:34:51][C][ota:030]:   Address: irrecevier.local:8266
[20:34:51][C][ota:032]:   Using Password.
[20:34:51][W][ota:036]: Last Boot was an unhandled reset, will proceed to safe mode in 0 restarts

You are showing us the code/configuration of a node called β€œweatherstation”, but you are showing the log of a node called β€œirreceiver”?

What concerns me is this line:

[20:34:41][C][ota:364]: There have been 10 suspected unsuccessful boot attempts.
[20:34:41][E][ota:369]: Boot loop detected. Proceeding to safe mode.

It boots only in safe mode and in normal mode it just resets, which indicates some sort of hardware error as stated in the ESPHome documentation:

ESPHome also has an β€œOTA safe mode”. If for some reason your node gets into a boot loop, ESPHome will automatically try to detect this and will go over into a safe mode after 10 unsuccessful boot attempts. In that mode, all components are disabled and only Serial Logging+WiFi+OTA are initialized, so that you can upload a new binary.

So I recommend commenting all non Serial Logging+WiFi+OTA code and disconnect all hardware. If the ESP then connects normally, step one is done. Then uncomment the code but do not connect the hardware. Check all hardware definitions (Board type, Pins, pin definitions). If the full code connects to HA without problems, reconnect the hardware (check all wires/pinnings/connections). and see if it connects.
Somewhere along this line it will fail and we will be able to circle the problem.

@CeeCee and @exxamalte
Thanks both for your help and time.

Yes. The code and log are indeed from 2 different device because I tried on both a new, clean one (irreceiver) and an existing one (weatherstation). Same result when adding the code sections UART and Sensor for sds011 and when I remove these sections things work again so I doubt it’s the hardware. In fact, even when nothing is connected to the esp, it shows this behavior.

Two more things you could try:

  • Swap RX/TX around.
  • Try different pins to connect the SDS011. For example, on my device (not running ESPHome though) I’m using GPIO4 and GPIO5.

Tried both things and unfortunately no change…
I did connect the SDS011 with the RPI4 that runs home assistant directly and with the below code it works perfectly. Disadvantage is that I am now measuring the particles in a place I would not like to measure it.

#sds011
  - platform: serial_pm
    serial_device: /dev/ttyUSB1
    name: Nova
    brand: novafitness,sds011

Did anyone succeed in implementing the SDS directly with ESPHome? I’d love to compare the type of ESP, build and config…

is it possible to use a similar as the above code in an ESP to still get it and send over through for example MQTT?

Thanks!

As it happens I came here looking for a solution for the same problem. Reading in the docs that ESP8266 has 2 UARTs , one TX only and the other TX/RX used by the logger component, I tried disabling logger: in the configuration. and got it to work. Obviously I lost the log, so this is not an ideal solution. Still trying to figure out if I can change the logger UART to the TX only one.

I use an AMICA NodeMCU and the TX & RX pins for the UART component.

1 Like

If this is the solution, there is a solution for using both (from https://esphome.io/components/logger.html):


...
Advanced settings:
hardware_uart (Optional, string): The Hardware UART to use for logging. Defaults to UART0.
...
Hardware UARTs

The logger component makes use of platform-specific hardware UARTs for serial logging. By default, the logger will occupy UART0. The ESP32 has three hardware UARTs, all of which can be used for both transmit and receive. The ESP8266 only has two hardware UARTs, one of which is transmit-only. The ESP8266 UART0 can also be β€˜swapped’ to TX/RX on the CTS/RTS pins, if you need to use GPIO1 and GPIO3 for something else.

Possible Hardware UART configurations:

    UART0 - TX: GPIO1, RX: GPIO3
    UART0_SWAP - TX: GPIO15, RX: GPIO13 (Only on ESP8266)
    UART1 - TX: GPIO2, RX: None (Only on ESP8266)
    UART1 - TX: GPIO9, RX: GPIO10 (Only on ESP32)
    UART2 - TX: GPIO16, RX: GPIO17 (Only on ESP32)

For another reason, I needed the ESP8266 hardware UART0, but did not want to loose the UART logging. So the solution is routing the logging to UART1.

# Example configuration entry
logger:
  level: DEBUG
  hardware_uart: UART1

This frees UART0 and enables the logger. Still for UART logging (ESPHome flasher or similar) you will have to do some wirering tricks with f.ex. a separate FTDI UART to USB converter.

2 Likes

thanks @nanobra1n! this seemed to do the trick! thanks for this idea.
Agree with the logger and I’ll have a look at @CeeCee’s suggestion later (need some time to really understand what that all means :yum:)

thanks both!!

I got it to work (while retaining the log) with this configuration:

esphome:
  name: air_qual
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "*****"
  password: !secret ****_pwd
  manual_ip:
    static_ip: 192.168.1.230
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Air Qual Fallback Hotspot"
    password: "*********

captive_portal:

# Enable logging
logger:
  hardware_uart: UART1

# Enable Home Assistant API
api:

ota:

uart:
  rx_pin: RX
  tx_pin: TX
  baud_rate: 9600

sensor:
  - platform: sds011
    pm_2_5:
      name: "Particulate Matter <2.5Β΅m Concentration"
    pm_10_0:
      name: "Particulate Matter <10.0Β΅m Concentration"
    update_interval: 5min

Thanks for the tip @CeeCee

2 Likes

Indeed! that worked for me too.
again, thanks both for your help!

1 Like