我目前正在使用带有CoolTerm和PL203串口转USB连接器的SIM5320e 3G开发板。我的目标是,一旦我可以成功实现HTTP / HTTPS GET请求,我就可以将其合并到一个微控制器项目中,该项目将数据从远程传感器传输到EDGE / GPRS / 3G的互联网。
但是我的问题是我还没有成功获得GET请求。我已经搜索了互联网和这个网站,除了数据表之外,这个主板上没有大量的信息,这非常复杂。我确信我错过了一个关键的步骤,但看不出它是什么。
以下是(典型的)终端输出以及我的评论
AT
OK // Module is working
AT+CGSOCKCONT=1,"IP","giffgaff.com" // Setting the APN I am using Giffgaff UK sim card, this is the APN
OK
AT+CSOCKSETPN=1 // Not sure what this step is, but seems to need to happen according to the application note
OK
AT+CIPMODE=0 // Same again
OK
AT+NETOPEN=,,1
Network opened
OK // Opens the network connection via GPRS
AT+IPADDR
+IPADDR: 10.146.130.153
OK // Appears to successfully get a network address
AT+CHTTPSSTART
OK // Starts the HTTPS/HTTP stack
AT+CHTTPSOPSE="www.iforce2d.net", 80,1
OK // Opens a connection to the host on port 80
AT+CHTTPSSEND=23 // Request to send 23 chars of data
>GET /test.php HTTP/1.1 // Web page exists, displays the time in UTC
OK // Says OK
AT+CHTTPSSEND
OK
+CHTTPSSEND: 0 // Says sent with no issue
AT+CHTTPSSEND? // However, I query it
+CHTTPSSEND: 0 // However has sent no chars!
OK
+CHTTPSNOTIFY: PEER CLOSED
AT+CHTTPSRECV? //Query if anything has been received?
+CHTTPSRECV: LEN,0 // Hasn't received anything!
OK
我错过了什么?
感谢您的光临。
威尔
答案 0 :(得分:1)
经过大量测试,设法使CHTTPSPOST
正常工作。
我的测试平台是SIM7600E,并且该模块的博客或资源还很少。
Serial2.println("AT+CHTTPSSTART"); xcode=SIM_receiveSerial(5, 0); wdt_reset();
Serial2.println("AT+CHTTPSOPSE=\"test.com/db\",443,2"); xcode=SIM_receiveSerial(5, 0); wdt_reset();
Serial.print (" -Server conn "); Serial.println(xcode); delay(100);
SIM_receiveSerial(1, 0);
SIM_receiveSerial(1, 0);
Serial2.println("AT+CHTTPSSEND=147");
xcode=SIM_receiveSerial(1, 0); wdt_reset(); Serial.print (" -Server conn "); Serial.println(xcode);
Serial.println("IN METHOD");
Serial2.print("POST https://test/com/db HTTP/1.1"); Serial2.write(13); Serial2.write(10); Serial.println(" -Post ");
Serial2.print("Host: test.com"); Serial2.write(13); Serial2.write(10); Serial.println(" -host ");
Serial2.print("Accept:*/*"); Serial2.write(13); Serial2.write(10);
Serial2.print("Content-Type:application/x-www-form-urlencoded"); Serial2.write(13); Serial2.write(10); Serial.println(" -Content-Type: ");
Serial.println(" -Cache-Control: ");
Serial.println(" -Accept-Charset: ");
Serial.println(" -Pragma: ");
Serial2.print("Content-Length:10");
Serial2.write(13); Serial2.write(10); Serial.println(" -Content-Length: ");
Serial2.print(""); Serial2.write(13); Serial2.write(10); Serial.println(" -NL ");
Serial2.print("¶m=11"); Serial.println(" -api_token ");
Serial2.write(13); Serial2.write(10);
Serial2.write(13); Serial2.write(10);
Serial2.write(0x1a); Serial.println(" -CTRL+Z ");
xcode=SIM_receiveSerial(2, 0);
xcode=SIM_receiveSerial(2, 0);
xcode=SIM_receiveSerial(2, 0);
xcode=SIM_receiveSerial(2, 0);
xcode=SIM_receiveSerial(2, 0);
xcode=SIM_receiveSerial(2, 0);
Serial2.println("AT+CHTTPSRECV?"); xcode=SIM_receiveSerial(2, 0); wdt_reset(); Serial.print (" -Server conn "); Serial.println(xcode);
xcode=SIM_receiveSerial(2, 0);
xcode=SIM_receiveSerial(2, 0);
Serial2.println("AT+CHTTPSSTATE"); xcode=SIM_receiveSerial(2, 0); wdt_reset();
Serial.print (" -Server conn "); Serial.println(xcode);
您可以使用AT+CHTTPRECV
SIM_receiveSerial
是等待sim模块回复的功能
答案 1 :(得分:0)
我希望这会有用。我使用TeraTerm将这些命令发送到我的SIM5320E
。因此,我使用了<Ctrl M>
和<Ctrl J>
而不是'<CR> <LF> OR /n/r'
个字符。
网络设置
AT+CGDCONT=1,"IP","<your APN>","0.0.0.0"
AT+CGSOCKCONT=1,"IP","<your APN>"
AT+CSOCKSETPN=1
启动HTTP服务 如果响应不正确,您可以停止并启动服务。
AT+CHTTPSSTART
AT+CHTTPACT="www.iforce2d.net",80
HTTP GET请求
GET /test.php HTTP/1.1 <-- don't hit enter, instead hit the below 2 keys
<Ctrl M>
<Ctrl J>
Host: www.iforce2d.net <-- don't hit enter, instead hit the below 2 keys
<Ctrl M>
<Ctrl J>
Connection: close <-- don't hit enter, instead hit the below 4 keys. This is useful when connecting to REST APIs to download the the respective result only.
<Ctrl M>
<Ctrl J>
<Ctrl M>
<Ctrl J>
结束命令并接收结果:
<Ctrl Z>
您将在此处收到很多数据。
停止HTTP服务
AT+CHTTPSCLSE
AT+CHTTPSSTOP
您将获得网站的内容。可能它应该包含您需要的数据(我没有测试内容。也许您将需要对结果进行一点分析。)