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

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

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

问题

  1. #include <SoftwareSerial.h>
  2. String apn = "internet"; //APN
  3. String apn_u = ""; //APN-Username
  4. String apn_p = ""; //APN-Password
  5. String url = "https://airpm.io/denek/GetData"; //URL of Server - Website is https://
  6. SoftwareSerial mySerial(14, 12); // sim800l_TX_pin, sim800l_RX_pin
  7. int counter = 0;
  8. void setup() {
  9. Serial.begin(9600);
  10. Serial.println("SIM800 AT CMD Test");
  11. mySerial.begin(9600);
  12. delay(5000);
  13. while (mySerial.available()) {
  14. Serial.write(mySerial.read());
  15. }
  16. delay(2000);
  17. configure_gprs();
  18. }
  19. void loop() {
  20. counter++;
  21. String data = String(counter); //write your data here
  22. send_to_server("{\"KEY\":" + data + "}");
  23. delay(2000);
  24. }
  25. void send_to_server(String data) {
  26. String sendURL = url;
  27. Serial.println(" --- Start GPRS & HTTP --- ");
  28. send_to_serial("AT+SAPBR=1,1");
  29. send_to_serial("AT+SAPBR=2,1");
  30. send_to_serial("AT+HTTPINIT");
  31. send_to_serial("AT+HTTPPARA=CID,1");
  32. send_to_serial("AT+HTTPPARA=URL," + sendURL);
  33. send_to_serial("AT+HTTPPARA=CONTENT,application/json");
  34. send_to_serial("AT+HTTPDATA=" + String(data.length()) + ",10000");
  35. send_to_serial(data);
  36. //send_to_serial("AT+HTTPSSL=1");
  37. send_to_serial("AT+HTTPACTION=1");
  38. send_to_serial("AT+HTTPREAD");
  39. send_to_serial("AT+HTTPTERM");
  40. send_to_serial("AT+SAPBR=0,1");
  41. }
  42. //AT+CGACT=1,1
  43. // "AT+CGDCONT=1,"IP","<APN>","0.0.0.0",0,0"
  44. // "AT+CGDNSIP=1,"<PRIMARY_DNS>","<SECONDARY_DNS>""
  45. // send_to_serial("AT+HTTPSSL=1");
  46. void configure_gprs() {
  47. Serial.println(" --- CONFIG GPRS --- ");
  48. send_to_serial("AT+SAPBR=3,1,Contype,GPRS");
  49. send_to_serial("AT+SAPBR=3,1,APN," + apn);
  50. if (apn_u != "") {
  51. send_to_serial("AT+SAPBR=3,1,USER," + apn_u);
  52. }
  53. if (apn_p != "") {
  54. send_to_serial("AT+SAPBR=3,1,PWD," + apn_p);
  55. }
  56. }
  57. void send_to_serial(String command) {
  58. Serial.println("Send ->: " + command);
  59. mySerial.println(command);
  60. long wtimer = millis();
  61. while (wtimer + 5000 > millis()) {
  62. while (mySerial.available()) {
  63. Serial.write(mySerial.read());
  64. }
  65. }
  66. Serial.println();
  67. }

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

英文:
  1. #include \&lt;SoftwareSerial.h\&gt;
  2. String apn = &quot;internet&quot;; //APN
  3. String apn_u = &quot;&quot;; //APN-Username
  4. String apn_p = &quot;&quot;; //APN-Password
  5. String url = &quot;https://airpm.io/denek/GetData&quot;; //URL of Server - Website is https://
  6. SoftwareSerial mySerial(14, 12); // sim800l_TX_pin, sim800l_RX_pin
  7. int counter = 0;
  8. void setup()
  9. {
  10. Serial.begin(9600);
  11. Serial.println(&quot;SIM800 AT CMD Test&quot;);
  12. mySerial.begin(9600);
  13. delay(5000);
  14. while (mySerial.available()) {
  15. Serial.write(mySerial.read());
  16. }
  17. delay(2000);
  18. configure_gprs();
  19. }
  20. void loop() {
  21. counter++;
  22. String data = String(counter); //write your data here
  23. send_to_server(&quot;{&quot;KEY&quot;:&quot; + data + &quot;}&quot;);
  24. delay(2000);
  25. }
  26. void send_to_server( String data) {
  27. String sendURL = url;
  28. Serial.println(&quot; --- Start GPRS &amp; HTTP --- &quot;);
  29. send_to_serial(&quot;AT+SAPBR=1,1&quot;);
  30. send_to_serial(&quot;AT+SAPBR=2,1&quot;);
  31. send_to_serial(&quot;AT+HTTPINIT&quot;);
  32. send_to_serial(&quot;AT+HTTPPARA=CID,1&quot;);
  33. send_to_serial(&quot;AT+HTTPPARA=URL,&quot; + sendURL);
  34. send_to_serial(&quot;AT+HTTPPARA=CONTENT,application/json&quot;);
  35. send_to_serial(&quot;AT+HTTPDATA=&quot; + String(data.length()) + &quot;,10000&quot;);
  36. send_to_serial(data);
  37. //send_to_serial(&quot;AT+HTTPSSL=1&quot;);
  38. send_to_serial(&quot;AT+HTTPACTION=1&quot;);
  39. send_to_serial(&quot;AT+HTTPREAD&quot;);
  40. send_to_serial(&quot;AT+HTTPTERM&quot;);
  41. send_to_serial(&quot;AT+SAPBR=0,1&quot;);
  42. }
  43. //AT+CGACT=1,1
  44. // &quot;AT+CGDCONT=1,&quot;IP&quot;,&quot;\&lt;APN\&gt;&quot;,&quot;0.0.0.0&quot;,0,0&quot;
  45. // &quot;AT+CGDNSIP=1,&quot;\&lt;PRIMARY_DNS\&gt;&quot;,&quot;\&lt;SECONDARY_DNS\&gt;&quot;&quot;
  46. // send_to_serial(&quot;AT+HTTPSSL=1&quot;);
  47. void configure_gprs() {
  48. Serial.println(&quot; --- CONFIG GPRS --- &quot;);
  49. send_to_serial(&quot;AT+SAPBR=3,1,Contype,GPRS&quot;);
  50. send_to_serial(&quot;AT+SAPBR=3,1,APN,&quot; + apn);
  51. if (apn_u != &quot;&quot;) {
  52. send_to_serial(&quot;AT+SAPBR=3,1,USER,&quot; + apn_u);
  53. }
  54. if (apn_p != &quot;&quot;) {
  55. send_to_serial(&quot;AT+SAPBR=3,1,PWD,&quot; + apn_p);
  56. }
  57. }
  58. void send_to_serial(String command) {
  59. Serial.println(&quot;Send -\&gt;: &quot; + command);
  60. mySerial.println(command);
  61. long wtimer = millis();
  62. while (wtimer + 5000 \&gt; millis()) {
  63. while (mySerial.available()) {
  64. Serial.write(mySerial.read());
  65. }
  66. }
  67. Serial.println();
  68. }

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:

确定