SIM800L 与 Web 服务器进行 HTTP 通信

Ali*_*ehr 0 webserver http arduino sim800

我使用 SIM800L 模块和 Arduino Uno 与网络服务器进行通信。我有一个 Arduino 读取的传感器。我想将传感器的值存储到我的数据库中。

在我的 Web 服务器上,我有一个 PHP 页面,用于将数据保存到数据库中。我正在使用这样的 GET 方法:http://www.isj.ir/Samples/sample.php?sen1=27.2
我正在将这个库用于 SIM800L。

但在这个例子中我无法传递传感器的值。我很困惑!您能帮帮我并告诉我该怎么办吗?

sprintf(body, "{\"name\": \"%s\"}", "Arduino");
result = http.post("isj.ir/Samples", body, response);
Serial.println(body);
print(F("HTTP POST: "), result);
if (result == SUCCESS) {
    Serial.println(response);
    StaticJsonBuffer<32> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(response);
    lastRunTime = millis();
    waitForRunTime = root["waitForRunTime"];
    print(F("Last run time: "), lastRunTime);
    print(F("Next post in: "), waitForRunTime);
}

result = http.get("isj.ir/Samples", response);
print(F("HTTP GET: "), result);
if (result == SUCCESS) {
    Serial.println(response);
    StaticJsonBuffer<32> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(response);
    lastRunTime = millis();
    waitForRunTime = root["waitForRunTime"];
    print(F("Last run time: "), lastRunTime);
    print(F("Next post in: "), waitForRunTime);
}
Run Code Online (Sandbox Code Playgroud)

Ali*_*oor 5

要使用 GET 方法发送数据,请使用以下 AT 命令:

AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","RighTel" // use your Operator  APN 
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="URL","http://yoursite.com?sen1=xxx&sen2=xxx&..."
AT+HTTPACTION=0 //(0=GET,1=POST,2=HEAD)
Run Code Online (Sandbox Code Playgroud)

那么您必须使用以下代码看到类似 +HTTPACTION: 0,200,xxx 的消息:

 AT+HTTPREAD:0,xxx
Run Code Online (Sandbox Code Playgroud)

如果您的 php 代码在处理后执行某些操作,您可以看到结果