我正在尝试使用 at+location=2 从板 a9g 获取坐标 小图书馆有时工作有时不工作。 以字符串形式获取坐标的函数是:
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
mySerial.println(command);
long int time = millis();
while ((time + timeout) > millis())
{
while (mySerial.available()){
char c = mySerial.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}
检索坐标
coordinates =sendData("AT+LOCATION=2", 1000, DEBUG);
int index = coordinates.indexOf(',');
lat = coordinates.substring(17, index);
lng = coordinates.substring(index + 1);
印刷:
lat = 42.850
lng = 2.8500
但是当我发送到 php 时
"AT+HTTPGET=\"http://carles.ho.submit_data01.php?data1=" + String(lat) +"&data2=" + String(lng) + "&data3=" + mac + "&data4=" + String(flag) + "\"";
这不起作用。 at+location 的文档是这样的:
AT+LOCATION=1(返回:,OK) xx.xxxxx,xxx.xxxxxx(固定为小数点后6位) OK 直接返回经纬度,无需转换
我尝试过不同的选择,但我不能。 预先感谢。
我想知道返回什么样的响应以及如何解决。
提高液化天然气的准确性:
lat = coordinates.substring(17, index);
lng = coordinates.substring(index + 1, index + 10);
清洁效果避免不良字符:
tring sanitizeString(String input) {
String result = "";
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (isAlphaNumeric(c) || c == '.' || c == ',' || c == '-') {
result += c;
}
}
return result;
}