HTTP json post on SİM800L problem. HTTPACTION responses are 301, 603, and 606.

huangapple go评论62阅读模式
英文:

HTTP json post on SİM800L problem. HTTPACTION responses are 301, 603 and 606

问题

#include <SoftwareSerial.h>

String apn = "internet";               //APN
String apn_u = "";                     //APN-Username
String apn_p = "";                     //APN-Password
String url = "https://airpm.io/denek/GetData";  //URL of Server - Website is https://

SoftwareSerial mySerial(14, 12); // sim800l_TX_pin, sim800l_RX_pin
int counter = 0;

void setup() {
    Serial.begin(9600);
    Serial.println("SIM800 AT CMD Test");
    mySerial.begin(9600);
    delay(5000);
    while (mySerial.available()) {
        Serial.write(mySerial.read());
    }
    delay(2000);
    configure_gprs();
}

void loop() {
    counter++;
    String data = String(counter); //write your data here
    send_to_server("{\"KEY\":" + data + "}");
    delay(2000);
}

void send_to_server(String data) {
    String sendURL = url;
    Serial.println(" --- Start GPRS & HTTP --- ");
    send_to_serial("AT+SAPBR=1,1");
    send_to_serial("AT+SAPBR=2,1");
    send_to_serial("AT+HTTPINIT");
    send_to_serial("AT+HTTPPARA=CID,1");
    send_to_serial("AT+HTTPPARA=URL," + sendURL);
    send_to_serial("AT+HTTPPARA=CONTENT,application/json");
    send_to_serial("AT+HTTPDATA=" + String(data.length()) + ",10000");
    send_to_serial(data);
    //send_to_serial("AT+HTTPSSL=1");
    send_to_serial("AT+HTTPACTION=1");
    send_to_serial("AT+HTTPREAD");
    send_to_serial("AT+HTTPTERM");
    send_to_serial("AT+SAPBR=0,1");
}

//AT+CGACT=1,1
// "AT+CGDCONT=1,"IP","<APN>","0.0.0.0",0,0"

// "AT+CGDNSIP=1,"<PRIMARY_DNS>","<SECONDARY_DNS>""

// send_to_serial("AT+HTTPSSL=1");

void configure_gprs() {
    Serial.println(" --- CONFIG GPRS --- ");
    send_to_serial("AT+SAPBR=3,1,Contype,GPRS");
    send_to_serial("AT+SAPBR=3,1,APN," + apn);
    if (apn_u != "") {
        send_to_serial("AT+SAPBR=3,1,USER," + apn_u);
    }
    if (apn_p != "") {
        send_to_serial("AT+SAPBR=3,1,PWD," + apn_p);
    }
}

void send_to_serial(String command) {
    Serial.println("Send ->: " + command);
    mySerial.println(command);
    long wtimer = millis();
    while (wtimer + 5000 > millis()) {
        while (mySerial.available()) {
            Serial.write(mySerial.read());
        }
    }
    Serial.println();
}

这是你提供的代码的翻译部分,我已经去除了HTML实体编码和注释。

英文:
#include \&lt;SoftwareSerial.h\&gt;
String apn = &quot;internet&quot;;               //APN
String apn_u = &quot;&quot;;                     //APN-Username
String apn_p = &quot;&quot;;                     //APN-Password
String url = &quot;https://airpm.io/denek/GetData&quot;;  //URL of Server - Website is https://
SoftwareSerial mySerial(14, 12); // sim800l_TX_pin, sim800l_RX_pin
int counter = 0;
void setup()
{
Serial.begin(9600);
Serial.println(&quot;SIM800 AT CMD Test&quot;);
mySerial.begin(9600);
delay(5000);
while (mySerial.available()) {
Serial.write(mySerial.read());
}
delay(2000);
configure_gprs();
}
void loop() {
counter++;
String data = String(counter); //write your data here
send_to_server(&quot;{&quot;KEY&quot;:&quot; + data + &quot;}&quot;);
delay(2000);
}
void send_to_server( String data) {
String sendURL = url;
Serial.println(&quot; --- Start GPRS &amp; HTTP --- &quot;);
send_to_serial(&quot;AT+SAPBR=1,1&quot;);
send_to_serial(&quot;AT+SAPBR=2,1&quot;);
send_to_serial(&quot;AT+HTTPINIT&quot;);
send_to_serial(&quot;AT+HTTPPARA=CID,1&quot;);
send_to_serial(&quot;AT+HTTPPARA=URL,&quot; + sendURL);
send_to_serial(&quot;AT+HTTPPARA=CONTENT,application/json&quot;);
send_to_serial(&quot;AT+HTTPDATA=&quot; + String(data.length()) + &quot;,10000&quot;);
send_to_serial(data);
//send_to_serial(&quot;AT+HTTPSSL=1&quot;);
send_to_serial(&quot;AT+HTTPACTION=1&quot;);
send_to_serial(&quot;AT+HTTPREAD&quot;);
send_to_serial(&quot;AT+HTTPTERM&quot;);
send_to_serial(&quot;AT+SAPBR=0,1&quot;);
}
//AT+CGACT=1,1
// &quot;AT+CGDCONT=1,&quot;IP&quot;,&quot;\&lt;APN\&gt;&quot;,&quot;0.0.0.0&quot;,0,0&quot;
// &quot;AT+CGDNSIP=1,&quot;\&lt;PRIMARY_DNS\&gt;&quot;,&quot;\&lt;SECONDARY_DNS\&gt;&quot;&quot;
//  send_to_serial(&quot;AT+HTTPSSL=1&quot;);
void configure_gprs() {
Serial.println(&quot; --- CONFIG GPRS --- &quot;);
send_to_serial(&quot;AT+SAPBR=3,1,Contype,GPRS&quot;);
send_to_serial(&quot;AT+SAPBR=3,1,APN,&quot; + apn);
if (apn_u != &quot;&quot;) {
send_to_serial(&quot;AT+SAPBR=3,1,USER,&quot; + apn_u);
}
if (apn_p != &quot;&quot;) {
send_to_serial(&quot;AT+SAPBR=3,1,PWD,&quot; + apn_p);
}
}
void send_to_serial(String command) {
Serial.println(&quot;Send -\&gt;: &quot; + command);
mySerial.println(command);
long wtimer = millis();
while (wtimer + 5000 \&gt; millis()) {
while (mySerial.available()) {
Serial.write(mySerial.read());
}
}
Serial.println();
}

I tried to post json data to a website on simcard(SIM800L).
The website is https://
When I put this line send_to_serial("AT+HTTPSSL=1"); out of comment, I get 606 error. When its in comment, I get 603 error.
When send_to_serial("AT+HTTPSSL=1"); line is in comment and When I use http:// url I get 301 error.

I use ESP32-Wroom-32D, not an arduino(ATMEL)

答案1

得分: 0

我找到了问题,
SIM800L支持TLS1.0,但我们的网站使用TLS1.2。
因此,我降低了网站的TLS级别。它起作用了。

英文:

I found the problem,
The SIM800L has TLS1.0 but our website has TLS1.2.
So, I lowered the website's TLS level. It worked.

huangapple
  • 本文由 发表于 2023年3月7日 20:49:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定