1. sscanf函数
sscanf是C标准库函数,用于「从字符串中读取格式化输入」。...使用实例
提取信号强度
AT命令返回结果为:
+CSQ: 17,0
OK
先使用strstr找到标志字符:
str = strstr(buffer, "+CSQ");
if (!...= 2) {
return -1;
}
提取基站信息
AT命令返回结果为:
+CREG: 2,0,"252A","6DD2104",7
OK
使用sscanf提取「固定长度字符」:
sscanf(...buffer, "+CREG:%d,%d,\"%4s\",\"%7s\"", &n, &stat, lac_buf, ci_buf);
提取IP地址
AT命令返回结果为:
+CIFSR:STAIP,"...:
+CWLAP:(4,"TP-LINK_PocketAP_DFBCD4",-57,"38:83:45:df:bc:d4",6)
+CWLAP:(3,"LSTM",-61,"8c:21:0a:bc:8e