Hi
I’m trying to get a custom_component to work on ESPHome,
I will try to get an instrument that sends data in NMEA 0183 (it’s not a GPS) via rs232 ttl adapter to uart on a esp32.
I’m a bit stuck, I’m new to this platform.
So far I have done this:
From my YAML file:
uart:
id: wind
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 19200
custom_component:
- lambda: |-
auto Windsonic = new Windsonic(id(wind));
return {Windsonic->retning, Windsonic->hastighet};
From my Windsonic.h file
#include "esphome.h"
class Windsonic : public Component, public UARTDevice {
public:
Windsonic(UARTComponent *parent) : UARTDevice(parent) {}
float retning = 0;
float hastighet = 0;
void setup() override {
// nothing to do here
}
void loop() override {
// Use Arduino API to read data, for example
String line = readStringUntil('\n');
retning = parse_float(line.substring(8, 10));
hastighet = parse_float(line.substring(15, 19));
}
// etc
// void update() override {
// retning->publish_state(retning);
// hastighet->publish_state(hastighet);
// }
};
From my compile log:
src/main.cpp:113:3: warning: multi-line comment [-Wcomment]
// lambda: !lambda "auto Windsonic = new Windsonic(id(wind));\nreturn {Windsonic->retning,\
^
In file included from src/main.cpp:14:0:
src/windsonic.h: In member function 'virtual void Windsonic::loop()':
src/windsonic.h:15:41: error: invalid initialization of reference of type 'const string& {aka const std::__cxx11::basic_string<char>&}' from expression of type 'String'
retning = parse_float(line.substring(8, 10));
^
In file included from src/esphome/core/application.h:8:0,
from src/esphome/components/api/api_connection.h:4,
from src/esphome.h:2,
from src/main.cpp:3:
src/esphome/core/helpers.h:44:17: note: in passing argument 1 of 'esphome::optional<float> esphome::parse_float(const string&)'
optional<float> parse_float(const std::string &str);
^
In file included from src/main.cpp:14:0:
src/windsonic.h:16:40: error: invalid initialization of reference of type 'const string& {aka const std::__cxx11::basic_string<char>&}' from expression of type 'String'
hastighet = parse_float(line.substring(15, 19));
^
In file included from src/esphome/core/application.h:8:0,
from src/esphome/components/api/api_connection.h:4,
from src/esphome.h:2,
from src/main.cpp:3:
src/esphome/core/helpers.h:44:17: note: in passing argument 1 of 'esphome::optional<float> esphome::parse_float(const string&)'
optional<float> parse_float(const std::string &str);
^
src/main.cpp: In lambda function:
src/main.cpp:121:28: error: expected type-specifier before 'Windsonic'
auto Windsonic = new Windsonic(wind);
^
src/main.cpp:122:55: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<esphome::Component*>'
return {Windsonic->retning, Windsonic->hastighet};
^
*** [/data/vind/.pioenvs/vind/src/main.cpp.o] Error 1
I need som advice on how to get this right.