我用的 esphome 2022.4.0 版本,遇到了那个 readStringUntil 导致编译失败的问题,改了下代码总算能用了,下面是 su03t_uart_read.h 文件的代码:
#include "esphome.h"
class UartReadLineSensor : public Component, public UARTDevice, public TextSensor
{
public:
UartReadLineSensor(UARTComponent *parent) : UARTDevice(parent) {}
void setup() override
{
// nothing to do here
}
void loop() override
{
String str = "";
while (available())
{
char c = read();
if (c != '\n')
{
str = str + c;
}
delay(2);
}
if (str.length() != 0)
{
publish_state(str.c_str());
str = "";
}
delay(100);
}
};
|