esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

SM300D2 Sensor - Invalid Preamble - Reading Data Time out #3767

Open EdDickens opened 2 years ago

EdDickens commented 2 years ago

The problem

I have a new SM300D2 sensor connected to an ESP01. I’ve got the ESP flashed with a basic config to get things running. All the Entities show up in HA with no problems. The problem is actually reading from the sensor. Seem to be having the same issues reported here. From that thread it seems the issue was fixed at one point but I cannot get anything from the sensor.

Which version of ESPHome has the issue?

2022.10.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2022.10.5

What platform are you using?

ESP8266

Board

ESP-01

Component causing the issue

SM300D2

Example YAML snippet

esphome:
  name: air-quality

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
#  password: !secret haapi_password

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi1_ssid
  password: !secret wifi1_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Air-Quality Fallback Hotspot"
    password: !secret fb_password

captive_portal:

switch:
  - platform: restart
    id: AirQual_restart
    name: "Air Quality Restart"

uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600

sensor:
  - platform: sm300d2
    co2:
      name: "CO2"
      id: "AirQual_CO2"
    formaldehyde:
      name: "Formaldehyde"
      id: "AirQual_Formaldehyde"
    tvoc:
      name: "TVOC"
      id: "AirQual_TVOC"
    pm_2_5:
      name: "PM2.5"
      id: "AirQual_PM25"
    pm_10_0:
      name: "PM10"
      id: "AirQual_PM10"
    temperature:
      name: "Temperature"
      id: "AirQual_Temperature"
    humidity:
      name: "Humidity"
      id: "AirQual_Humidity"
    update_interval: 60s

Anything in the logs that might be useful for us?

[13:43:49][W][sm300d2:026]: Invalid preamble for SM300D2 response!
[13:44:50][E][uart:015]: Reading from UART timed out at byte 0!
[13:44:50][W][sm300d2:020]: Reading data from SM300D2 failed!
[13:45:50][E][uart:015]: Reading from UART timed out at byte 0!
[13:45:50][W][sm300d2:020]: Reading data from SM300D2 failed!
[13:46:50][E][uart:015]: Reading from UART timed out at byte 0!
[13:46:50][W][sm300d2:020]: Reading data from SM300D2 failed!
[13:47:50][W][sm300d2:026]: Invalid preamble for SM300D2 response!
[13:48:50][E][uart:015]: Reading from UART timed out at byte 0!
[13:48:50][W][sm300d2:020]: Reading data from SM300D2 failed!

Additional information

A bit more info after some troubleshooting.

Using a USB to Serial adapter, I'm able to read the messages from the sensor.

What I’m seeing is 17 bytes most of the time with 18 showing up on occasion. When there’s 18 bytes the last byte is always 0x00.

First two bytes are 0x7F and 0x7E.

Using the test data values from the SM300D2 Documentation, I get the correct calculated values for all parameters. image

Switch to live data and I probably wouldn’t be able to type this if these values were true. image

Duker4444 commented 1 year ago

I'm seeing the same thing. using a D1 mini on ESPHOME 2022.12.13

Serial Data is incoming however it's not being processed correctly.. None of the datasamples are picked up.. The 1st four placements appear to be some sort of markup and board Gen/Rev since those never change. Only the later data is changing..

Sample of that debug output from the UART. I was able to find the data pattern and aligned them here.

01:03:0E:01:93:00:00:00:02:00:00:00:00:08:BD:0C:EC:A4:EF 01:03:0E:01:93:00:00:00:02:00:00:00:00:08:BB:0C:E6:C4:E9 01:03:0E:01:90:00:00:00:00:00:00:00:00:08:C0:0C:E5:E8:52 01:03:0E:01:90:00:00:00:00:00:00:00:00:08:BE:0C:E8:49:8F 01:03:0E:01:91:00:00:00:01:00:00:00:00:08:BB:0C:E6:D7:5B 01:03:0E:01:94:00:00:00:03:00:00:00:00:08:BD:0C:E6:22:3F 01:03:0E:01:93:00:00:00:02:00:00:00:00:08:BE:0C:E9:94:EC 01:03:0E:01:94:00:00:00:03:00:00:00:00:08:BD:0C:E8:A3:FB 01:03:0E:01:93:00:00:00:02:00:00:00:00:08:BB:0C:E6:C4:E9 01:03:0E:01:90:00:00:00:00:00:00:00:00:08:BD:0C:E1:79:89 01:03:0E:01:91:00:00:00:01:00:00:00:00:08:BB:0C:E5:97:5A 01:03:0E:01:91:00:00:00:01:00:00:00:00:08:BD:0C:E2:36:99 01:03:0E:01:90:00:00:00:00:00:00:00:00:08:BD:0C:E4:B9:8A 01:03:0E:01:91:00:00:00:01:00:00:00:00:08:BD:0C:E5:77:5B

These are two brand new sensors , It looks like they have started using 19 vs the old 17 placements. and thus throwing off the reading and processing of the feed. -Thanks

redyuan43 commented 1 year ago

same issue.

Duker4444 commented 1 year ago

I think I may have stumbled on the new sequence.

Byte name Description

B1 Slave address Address value

B2 function code 03h

B3 Return the number of bytes 0x0E

B4 data eCO2 High byte

B5 data eCO2 Low byte

B6 data eCH2O High byte

B7 data eCH2O Low byte

B8 data TVOC High byte

B9 data TVOC Low byte

B10 data PM2.5 High byte

B11 data PM2.5 Low byte

B12 data PM10 High byte

B13 data PM10 Low byte

B14 data Temperature "High" byte

B15 data Temperature "Low" byte

B16 data Humidity "High" byte

B17 data Humidity "Low" byte

B18 CRC 16 low

B19 CRC16 high

Working to validate these since my readings seem a little high.

Duker4444 commented 1 year ago

I've got the values worked out. Should see a new component here soon called sm300d2v2 since this is a v2 hardware variant. Submitting for contribute.

rotilho commented 1 year ago

Hey Duker! I see that you closed your PR, did anything change?

Duker4444 commented 1 year ago

I've got it working. however i'm stalled on getting it approved for commit. The ESPhome owner wanted to see if I could somehow merge the two devices instead of creating a 2nd hardware type. Unfortunately, My skills aren't quite that high. I've made a few attempts, But due to how the Serial is parsed. I haven't been able to make it universal and merge with the original code. The New hardware code is under a device called sm300d2v2

https://github.com/Duker4444/esphome Here's the link to the codebase. It's still in there. Feel free to take a look.