// See if the SIM900 is ready
AT
OK
// SIM card inserted and unlocked?
AT+CPIN?
+CPIN: READY
OK
// Is the SIM card registered?
AT+CREG?
+CREG: 0,5
OK
// Is GPRS attached?
AT+CGATT?
+CGATT: 1
OK
// Check signal strength - should be 9 or higher
AT+CSQ
+CSQ: 20,0
OK
// Set connection type to GPRS
AT+SAPBR=3,1,“Contype”,“GPRS”
OK
// Set the APN - this will depend on your network/service provider
AT+SAPBR=3,1,“APN”,“CMNET”
OK
// Enable GPRS - this will take a moment or two
AT+SAPBR=1,1
OK
// Check to see if connection is correct and get your IP address
AT+SAPBR=2,1
+SAPBR: 1,1,“10.79.223.61”
OK
/////////////////////////////////////////////////////////////////
AT+CIPSTART=“TCP”,“183.230.40.33”,“80”
OK
CONNECT OK
/////////////////////////////////////////////////////////////
AT+CIPSEND
>
在發送框中填入一下數據這裏的設備ID和APIKey需要與自己的項目中的設備相關的信//息對應 本例中設備ID和APIKey分別爲4059176,jebuoO6YrgCmy2TwMfRTTNWwCMI=,則發送的內容應該替代爲
POST /devices/4059176/datapoints HTTP/1.1
api-key: jebuoO6YrgCmy2TwMfRTTNWwCMI=
Host: api.heclouds.com
Content-Length: 82
{"datastreams":[{"id":"location","datapoints":[{"value":{"lon":116,"lat":30}}]}]}
SIM900A發送成功響應數據
SEND OK
服務器的響應數據
HTTP/1.1 200 OK
Date: Thu, 24 Nov 2016 13:43:28 GMT
Content-Type: application/json
Content-Length: 26
Connection: keep-alive
Server: Apache-Coyote/1.1
Pragma: no-cache
{"errno":0,"error":"succ"}
//OK
- 數據內容中的"lon""lat"字段分別表示經度和緯度值,目前只能顯示國內數據,所以在設///置該值的時候要將其設爲國內的位置點
- Content-Length表示數據的長度,需要與後面的數據內容長度保持一致
- 發送的數據內容中有幾個回車字符(\r\n)是不能少的
- 以16進制發送"1A"完成數據發送
參考資料:
- http://open.iot.10086.cn/bbs/forum.php?mod=viewthread&tid=399
- http://electronics.stackexchange.com/questions/231224/posting-to-php-server-using-sim900-gprs-with-at-commands/231225#231225 需翻牆
- http://jingyan.baidu.com/article/5d6edee2f03ae099eadeec36.html
- http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands需翻牆
- http://www.cnblogs.com/Mysterious/p/5907125.html