英文:
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 \<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();
}
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论