I need some help with ESPHome, uart port and a Windsonic anemonemeter

Ive ordered an ESP32, Ill try again when I get here

1 Like

You probably will be better off for the UART on the esp32

Friends, thank you very much for this topic. I have not received the result yet. Help me please.
I have an ESP32 wemos lolin and a BENETECH UART GM8904 anemometer.
In the logs I get the message “Reading from UART timed out at byte 0”. I have had many attempts to change on UART2 and also but so far it does not work. Any ideas? Thank you.

This is my logs:

[04:23:32][E][uart_esp32:147]: Reading from UART timed out at byte 0!
[04:23:32][D][sensor:092]: 'Wind direction': Sending state 0.00000 gr with 3 decimals of accuracy
[04:23:32][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy

I managed to do without errors. But the readings are now zero. I think to deal with the instructions of the anemometer. How can I write the code correctly?

here is my yaml file

substitutions:
  device_name: windsonic
esphome:
  name: ${device_name}
  platform: ESP32
  board: lolin32
  includes:
    - windsonic.h

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # fast_connect: true

captive_portal:

api:
  password: !secret wifi_api
  reboot_timeout: 0s
ota:
  password: !secret wifi_ota

web_server:
  port: 80

logger:
  # level: DEBUG
  baud_rate: 9600
  # hardware_uart: UART1
uart:
  id: wind
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 19200

sensor:
  - platform: custom 
    lambda: |-
      auto my_windsonic = new Windsonic(id(wind));
      App.register_component(my_windsonic);
      return {my_windsonic->winddirection_sensor, my_windsonic->windspeed_sensor};
      
      
    sensors:
    - name: "Wind direction"
      unit_of_measurement: "gr"
#      accuracy_decimals: 3
      icon: mdi:compass-rose
    - name: "Wind speed"
      unit_of_measurement: "m/s"
      accuracy_decimals: 3
      icon: mdi:weather-windy 
      

here is my windsonic.h

#include "esphome.h"
#include "sensor.h"

class Windsonic : public Component, public UARTDevice {
 public:
  Windsonic(UARTComponent *parent) : UARTDevice(parent) {}
  Sensor *winddirection_sensor = new Sensor();
  Sensor *windspeed_sensor = new Sensor();
  
  
  
  void setup() override {
    // nothing to do here
  }
  void loop() override {
    // Use Arduino API to read data, for example
  //String line = "";  
  
  String line = readStringUntil('\n');
  String r = line.substring(7, 10);
  String s = line.substring(13, 19);
  float winddirection = r.toFloat();
  float windspeed = s.toFloat();
  winddirection_sensor->publish_state(winddirection);
  windspeed_sensor->publish_state(windspeed);
  winddirection = 0;
  windspeed = 0;
  r = "";
  s = "";
	
	
  }
  
};

here are my logs

[21:09:59][D][sensor:099]: 'Wind direction': Sending state 0.00000 gr with 0 decimals of accuracy
[21:10:00][D][sensor:099]: 'Wind speed': Sending state 0.00000 m/s with 3 decimals of accuracy
[21:10:00][C][uart_esp32:088]: UART Bus:
[21:10:00][C][uart_esp32:090]:   TX Pin: GPIO17
[21:10:00][C][uart_esp32:093]:   RX Pin: GPIO16
[21:10:00][C][uart_esp32:094]:   RX Buffer Size: 256
[21:10:00][C][uart_esp32:096]:   Baud Rate: 19200 baud
[21:10:00][C][uart_esp32:097]:   Data Bits: 8
[21:10:00][C][uart_esp32:098]:   Parity: NONE
[21:10:00][C][uart_esp32:099]:   Stop bits: 1
[21:10:01][D][sensor:099]: 'Wind direction': Sending state 0.00000 gr with 0 decimals of accuracy
[21:10:01][D][sensor:099]: 'Wind speed': Sending state 0.00000 m/s with 3 decimals of accuracy

manual anemometr gm8904 link

Please, help me!

1 Like

Hello,

can you send the data sample you want to shred?

the complicator reports an error to me

Processing kotownia-termometry (board: featheresp32; framework: arduino; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <AsyncTCP-esphome> 1.2.2
|-- <WiFi> 1.0
|-- <FS> 1.0
|-- <Update> 1.0
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <AsyncTCP-esphome> 1.2.2
|-- <DNSServer> 1.1.0
|-- <ESPmDNS> 1.0
|-- <Wire> 1.0.1
|-- <ArduinoJson> 6.18.5
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/src/main.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib64d/WiFi/WiFiMulti.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib64d/WiFi/WiFiSTA.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib64d/WiFi/WiFiScan.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib64d/WiFi/WiFiServer.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib64d/WiFi/WiFiUdp.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib01c/FS/FS.cpp.o
In file included from src/main.cpp:48:0:
src/windsonic.h: In member function 'virtual void Windsonic::loop()':
src/windsonic.h:19:37: error: 'readStringUntil' was not declared in this scope
   String line = readStringUntil('\n');
                                     ^
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/lib01c/FS/vfs_api.cpp.o
Compiling /data/kotownia-termometry/.pioenvs/kotownia-termometry/libbc6/Update/HttpsOTAUpdate.cpp.o
*** [/data/kotownia-termometry/.pioenvs/kotownia-termometry/src/main.cpp.o] Error 1
========================= [FAILED] Took 40.68 seconds =========================

I have no idea what’s wrong.

esphome:
  includes:
     - windsonic.h
  name: kotownia-termometry
  platform: ESP32
#  board: featheresp32
  board: lolin32