我们需要从串口 发送指令,然后串口有回复
需要把回复的数据进行处理
例如:串口发
回复:+HEART=当前心率
+HEART=66
我们需要把心率值66提出来
float sendCommand(String command, const int timeout)
{
String response = “”;
WIFISerial.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis())
{
while(WIFISerial.available())
{
// The esp has data so display its output to the serial window
char c = WIFISerial.read(); // read the next character.
response+=c;
}
}
if ( response.indexOf(“NULL”)==-1 )//过滤输出 NULL 的情况
{
// Serial.print(response);
int x=response.indexOf("="); //体温 1–6
return( (response.substring(x+1,x+5)).toFloat() );
}
}