[英]How to parse string from Serial monitor in Arduino?
My code:我的代码:
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
Serial1.write("AT+DTTX\n");
delay(5000);
while (Serial1.available()) {
String txtMsg = Serial1.readString();
Serial.println(txtMsg);
}
}
Serial monitor:串行监视器:
1
1
AT+DTTX OK
AT+DTTX 正常
Radio Tx Done RadioTxDelayDone Radio Rx Done Len:2 RSSI:-93 SNR:33
Radio Tx Done RadioTxDelayDone Radio Rx Done Len:2 RSSI:-93 SNR:33
2
2
AT+DTTX OK
AT+DTTX 正常
Radio Tx Done RadioTxDelayDone Radio Rx Done Len:2 RSSI:-90 SNR:32
Radio Tx Done RadioTxDelayDone Radio Rx Done Len:2 RSSI:-90 SNR:32
3 AT+DTTX OK
3 AT+DTTX 正常
Radio Tx Done RadioTxDelayDone Radio Rx Done Len:2 RSSI:-92 SNR:22
Radio Tx Done RadioTxDelayDone Radio Rx Done Len:2 RSSI:-92 SNR:22
How to get RSSI and SNR from Serial monitor?如何从串行监视器获取 RSSI 和 SNR?
I want results like:我想要这样的结果:
1 RSSI:-93 SNR:33 1 RSSI:-93 信噪比:33
2 RSSI:-90 SNR:32 2 RSSI:-90 信噪比:32
3 RSSI:-92 SNR:22 3 RSSI:-92 信噪比:22
char *tmp = strstr (strtoparse, "RRSI");
Tmp points to it or is NULL. Tmp 指向它或为 NULL。
Then you can do whatever you want with it.然后你可以用它做任何你想做的事。 I assume the format you provided us.
我假设您提供给我们的格式。 If it is not parsing may be quite complicated
如果不解析可能会相当复杂
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.