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

Thanks!! Ill be trying it on a HUZZAH ESP8266. Ill report back how I go. Its Friday afternoon where I am so there may be a few beers between now and the time I get around to it :rofl:

Sorry, is it possible to add another sensor to convert from meters per second to kph?

Just implement the math in the windsonic.h file, this is plain c++ programming.

It’s Also possible to use the tool from Gill Instruments to setup the sensor to report kph.

Thanks for your quick replies!! Im no programmer just a mechanic. You have been very helpful.

If I add something like this?

I think that will work,.

Anyway you have to setup the sensor thru the wind tool from Gill anyway, to get it to send the NMEA string with fixed field lenght, there you can also setup the unit to report.

Cool, Ill try over the weeked. I just thought it woukd be nice to have both measurements!

So Ive been trying to upload the code you provided but I keep running into this error

INFO Reading configuration /config/esphome/windsonic.yaml…
INFO Generating C++ source…
INFO Compiling app…
INFO Running: platformio run -d /config/esphome/windsonic
Processing windsonic (board: huzzah; framework: arduino; platform: [email protected])

HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- 1.2.2
| |-- 1.0
|-- 1.0
|-- 1.2
| |-- 1.0
|-- 1.2.6
| |-- 1.2.2
| | |-- 1.0
| |-- 1.0
| |-- 1.0
|-- 1.1.1
| |-- 1.0
Compiling /data/windsonic/.pioenvs/windsonic/src/main.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:143:31: error: expected type-specifier before ‘Windsonic’
auto my_windsonic = new Windsonic(wind);
^
src/main.cpp:145:81: error: could not convert ‘{, }’ from ‘’ to ‘std::vectoresphome::sensor::Sensor*
return {my_windsonic->winddirection_sensor, my_windsonic->windspeed_sensor};
^
src/main.cpp:146:3: warning: control reaches end of non-void function [-Wreturn-type]
});
^
*** [/data/windsonic/.pioenvs/windsonic/src/main.cpp.o] Error 1
========================== [FAILED] Took 9.53 seconds ==========================

What am I doing wrong here?

If that is what is in your file, that is not in the code @jorgenn posted.

I copied and pasted the yaml and the windsonic.h code. It throws this error when I try to upload it to my esp8266

auto my_windsonic = new Windsonic(id(wind));

You appear to have (according to the error message)

auto my_windsonic = new Windsonic(wind);

please check.

I found the issue, I deleted the includes section when I was changing the board type from esp32 to esp8266 :crazy_face:
Now its complaining that I dont have sensor.h

INFO Reading configuration /config/esphome/windsonic.yaml…
INFO Generating C++ source…
INFO Compiling app…
INFO Running: platformio run -d /config/esphome/windsonic
Processing windsonic (board: huzzah; framework: arduino; platform: [email protected])

HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- 1.2.2
| |-- 1.0
|-- 1.0
|-- 1.2
| |-- 1.0
|-- 1.2.6
| |-- 1.2.2
| | |-- 1.0
| |-- 1.0
| |-- 1.0
|-- 1.1.1
| |-- 1.0
Compiling /data/windsonic/.pioenvs/windsonic/src/main.cpp.o
In file included from src/main.cpp:17:0:
src/windsonic.h:2:20: fatal error: sensor.h: No such file or directory


  • Looking for sensor.h dependency? Check our library registry!
  • CLI > platformio lib search “header:sensor.h”
  • Web > PlatformIO Registry

#include “sensor.h”
^
compilation terminated.
*** [/data/windsonic/.pioenvs/windsonic/src/main.cpp.o] Error 1

I have updatet the windsonic.h, i found that changing from component to pollingcomponent made it far better.

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

class Windsonic : public PollingComponent, public UARTDevice {
 public:
  Windsonic(UARTComponent *parent) : PollingComponent(1000), UARTDevice(parent) {}
  Sensor *winddirection_sensor = new Sensor();
  Sensor *windspeed_sensor = new Sensor();
  
  
  
  void setup() override {
    // nothing to do here
  }
  void update() override {
    // Use Arduino API to read data, for example  
  
  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 = "";
	
	
  }
  
};
1 Like

I just cannot get this to compile

INFO Reading configuration /config/esphome/windsonic.yaml…
INFO Generating C++ source…
INFO Compiling app…
INFO Running: platformio run -d /config/esphome/windsonic
Processing windsonic (board: huzzah; framework: arduino; platform: [email protected])

HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- 1.2.2
| |-- 1.0
|-- 1.0
|-- 1.2
| |-- 1.0
|-- 1.2.6
| |-- 1.2.2
| | |-- 1.0
| |-- 1.0
| |-- 1.0
|-- 1.1.1
| |-- 1.0
Compiling /data/windsonic/.pioenvs/windsonic/src/filter.cpp.o
Compiling /data/windsonic/.pioenvs/windsonic/src/main.cpp.o
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:17:7: error: redefinition of ‘class esphome::sensor::Filter’
class Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:17:7: error: previous definition of ‘class esphome::sensor::Filter’
class Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:53:7: error: redefinition of ‘class esphome::sensor::MedianFilter’
class MedianFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:53:7: error: previous definition of ‘class esphome::sensor::MedianFilter’
class MedianFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:84:7: error: redefinition of ‘class esphome::sensor::SlidingWindowMovingAverageFilter’
class SlidingWindowMovingAverageFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:84:7: error: previous definition of ‘class esphome::sensor::SlidingWindowMovingAverageFilter’
class SlidingWindowMovingAverageFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:116:7: error: redefinition of ‘class esphome::sensor::ExponentialMovingAverageFilter’
class ExponentialMovingAverageFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:116:7: error: previous definition of ‘class esphome::sensor::ExponentialMovingAverageFilter’
class ExponentialMovingAverageFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:144:7: error: redefinition of ‘class esphome::sensor::LambdaFilter’
class LambdaFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:144:7: error: previous definition of ‘class esphome::sensor::LambdaFilter’
class LambdaFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:158:7: error: redefinition of ‘class esphome::sensor::OffsetFilter’
class OffsetFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:158:7: error: previous definition of ‘class esphome::sensor::OffsetFilter’
class OffsetFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:169:7: error: redefinition of ‘class esphome::sensor::MultiplyFilter’
class MultiplyFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:169:7: error: previous definition of ‘class esphome::sensor::MultiplyFilter’
class MultiplyFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:180:7: error: redefinition of ‘class esphome::sensor::FilterOutValueFilter’
class FilterOutValueFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:180:7: error: previous definition of ‘class esphome::sensor::FilterOutValueFilter’
class FilterOutValueFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:190:7: error: redefinition of ‘class esphome::sensor::ThrottleFilter’
class ThrottleFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:190:7: error: previous definition of ‘class esphome::sensor::ThrottleFilter’
class ThrottleFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:201:7: error: redefinition of ‘class esphome::sensor::DebounceFilter’
class DebounceFilter : public Filter, public Component {
^
In file included from src/filter.cpp:1:0:
src/filter.h:201:7: error: previous definition of ‘class esphome::sensor::DebounceFilter’
class DebounceFilter : public Filter, public Component {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:213:7: error: redefinition of ‘class esphome::sensor::HeartbeatFilter’
class HeartbeatFilter : public Filter, public Component {
^
In file included from src/filter.cpp:1:0:
src/filter.h:213:7: error: previous definition of ‘class esphome::sensor::HeartbeatFilter’
class HeartbeatFilter : public Filter, public Component {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:231:7: error: redefinition of ‘class esphome::sensor::DeltaFilter’
class DeltaFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:231:7: error: previous definition of ‘class esphome::sensor::DeltaFilter’
class DeltaFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:242:7: error: redefinition of ‘class esphome::sensor::OrFilter’
class OrFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:242:7: error: previous definition of ‘class esphome::sensor::OrFilter’
class OrFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:266:7: error: redefinition of ‘class esphome::sensor::CalibrateLinearFilter’
class CalibrateLinearFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:266:7: error: previous definition of ‘class esphome::sensor::CalibrateLinearFilter’
class CalibrateLinearFilter : public Filter {
^
In file included from src/sensor.h:5:0,
from src/filter.cpp:2:
src/esphome/components/sensor/filter.h:276:7: error: redefinition of ‘class esphome::sensor::CalibratePolynomialFilter’
class CalibratePolynomialFilter : public Filter {
^
In file included from src/filter.cpp:1:0:
src/filter.h:276:7: error: previous definition of ‘class esphome::sensor::CalibratePolynomialFilter’
class CalibratePolynomialFilter : public Filter {
^
*** [/data/windsonic/.pioenvs/windsonic/src/filter.cpp.o] Error 1
In file included from src/windsonic.h:2:0,
from src/main.cpp:17:
src/sensor.h:30:7: error: redefinition of ‘class esphome::sensor::Sensor’
class Sensor : public Nameable {
^
In file included from src/esphome/core/application.h:15:0,
from src/esphome/components/api/api_connection.h:4,
from src/esphome.h:2,
from src/main.cpp:3:
src/esphome/components/sensor/sensor.h:30:7: error: previous definition of ‘class esphome::sensor::Sensor’
class Sensor : public Nameable {
^
In file included from src/windsonic.h:2:0,
from src/main.cpp:17:
src/sensor.h:192:7: error: redefinition of ‘class esphome::sensor::PollingSensorComponent’
class PollingSensorComponent : public PollingComponent, public Sensor {
^
In file included from src/esphome/core/application.h:15:0,
from src/esphome/components/api/api_connection.h:4,
from src/esphome.h:2,
from src/main.cpp:3:
src/esphome/components/sensor/sensor.h:192:7: error: previous definition of ‘class esphome::sensor::PollingSensorComponent’
class PollingSensorComponent : public PollingComponent, public Sensor {
^
*** [/data/windsonic/.pioenvs/windsonic/src/main.cpp.o] Error 1
========================== [FAILED] Took 8.73 seconds ==========================

Can you publish the YAML file you are using, I think there might be something in it to look into.

esphome:
  name: windsonic
  platform: ESP8266
  board: huzzah
  includes:
    - windsonic.h

wifi:
  ssid: "xxxx"
  password: "xxxx"

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxx"

ota:
  password: "xxxx"


uart:
  id: wind
  tx_pin: 15
  rx_pin: 13
  baud_rate: 9600


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

There is some difference in the framework from the arduino platform for the esp8266 to esp32.

Do you have an ESP32 based board aviable ?
To me it’s look’s like the framework difference is the reason you have trouble with this. I have never testet this on the 8266 platform.

No I dont, sorry. I just deleted everything and tried again. Still no good. Its a shame it doesnt work on the 8266.

INFO Reading configuration /config/esphome/windsonic.yaml...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/esphome/windsonic
Processing windsonic (board: huzzah; framework: arduino; platform: [email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
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/windsonic/.pioenvs/windsonic/src/main.cpp.o
Compiling /data/windsonic/.pioenvs/windsonic/lib4d9/ESP8266WiFi/CertStoreBearSSL.cpp.o
In file included from src/main.cpp:17:0:
src/windsonic.h:2:20: fatal error: sensor.h: No such file or directory

****************************************************************
* Looking for sensor.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:sensor.h"
* Web  > https://platformio.org/lib/search?query=header:sensor.h
*
****************************************************************

 #include "sensor.h"
                    ^
compilation terminated.
*** [/data/windsonic/.pioenvs/windsonic/src/main.cpp.o] Error 1
========================== [FAILED] Took 6.08 seconds ==========================

I see you are running on the 2.2.3 arduino version, try to update this to newer version.
reead in this link Esphome core component

I added
arduino_version: 2.5.2
to the yaml but it still tries to build it with 2.2.3 :thinking: more research required

You have to update the library wich the compiler reads it’s files