当前位置: 首页 > 工具软件 > phpml > 使用案例 >

ML302 4G模块 HTTP AT指令使用流程

太叔景曜
2023-12-01

一、首先入网

[18:34:00.684]发→◇AT+CGACT=1,1

[18:34:00.699]收←◆AT+CGACT=1,1

[18:34:00.885]收←◆
+CGACT: 1,1

OK

二、初始化模块的HTTP功能

[18:34:11.214]发→◇AT+MHTTPINIT

[18:34:11.229]收←◆AT+MHTTPINIT

OK

三、设置需要GET或POST的URL

[18:43:09.940]发→◇AT+MHTTPSET=“http://www.wanzhou.com.cn/”

[18:43:09.970]收←◆AT+MHTTPSET=“http://www.wanzhou.com.cn/”

OK

四、向URL所在的服务器发送GET请求

[18:37:53.078]发→◇AT+MHTTPGET

[18:37:53.093]收←◆AT+MHTTPGET

OK

[18:37:54.731]收←◆+MHTTPGET:200,22821

五、从刚刚返回的22821字节的返回数据中读取数据

(1)读取前面的10个字节

[18:38:02.649]发→◇AT+MHTTPREAD=0,10

[18:38:02.666]收←◆AT+MHTTPREAD=0,10

OK
+HTTPREAD: 10
锘匡豢<!DO

(2)读取前面的1000个字节

[18:38:16.480]发→◇AT+MHTTPREAD=0,1000

[18:38:16.480]收←◆AT+MHTTPREAD=0,1000

OK
+HTTPREAD: 1000
锘匡豢

涓囨床鐢垫皵瀹樼綉-鑷村姏浜庡叏闈㈢郴缁熻妭鑳斤紝鏈嶅姟鑳界涓績寤鸿

六、POST例子1

(1)先设置URL

[19:04:27.270]发→◇AT+MHTTPSET=“http://www.baidu.com:80/index.php”

[19:04:27.295]收←◆AT+MHTTPSET=“http://www.baidu.com:80/index.php”

OK

(2)POST消息

[19:04:56.037]发→◇AT+MHTTPPOST

[19:04:56.053]收←◆AT+MHTTPPOST

//--------------------这里等待模组返回">"后才能发送接下来的内容
[19:04:58.547]发→◇GET http://www.baidu.com/index.php HTTP/1.1
Host: www.baidu.com
Connection: keep-alive

[19:04:58.562]收←◆GET http://www.baidu.com/index.php HTTP/1.1
Host: www.baidu.com
Connection: keep-alive

[19:05:01.257]发→◇□//--------------------这里发送HEX字节“0X1A”表示内容结束
[19:05:01.759]收←◆
OK

[19:05:02.176]收←◆+MHTTPPOST:302,15//--------------------这是模组返回的服务器信息

七、POST例子2

[20:03:00.453]发→◇AT+MHTTPSET=“http://api.heclouds.com:80/devices/588931880/datapoints?type=3”

[20:03:00.554]收←◆AT+MHTTPSET=“http://api.heclouds.com:80/devices/588931880/datapoints?type=3”

OK

[20:05:14.528]发→◇AT+MHTTPPOST

[20:05:14.559]收←◆AT+MHTTPPOST

[20:05:20.680]发→◇"{“temperature”:%d,“humidity”:%d}",“api-key:=R0RMR6=oZ674OYGKD5TjIgzI=“□
[20:05:20.717]收←◆”{“temperature”:%d,“humidity”:%d}","api-key:=R0RMR6=oZ674OYGK
D5TjIgzI=”
[20:05:21.705]发→◇□
[20:05:22.201]收←◆
OK

[20:05:22.640]收←◆+MHTTPPOST:200,73//----------------200表示服务器相应OK

//如果上面的URL不对,则返回如下:
[20:51:06.066]收←◆+MHTTPPOST:404,162

 类似资料: