2 -- LuaTools需要PROJECT和VERSION这两个信息
7 本demo需要socket库, 大部分能联网的设备都具有这个库
12 _G
.sys
= require("sys")
13 httpplus
= require
"httpplus"
16 -- Air780E的AT固件默认会为开机键防抖, 导致部分用户刷机很麻烦
17 if rtos
.bsp() == "EC618" and pm
and pm
.PWK_MODE
then
18 pm
.power(pm
.PWK_MODE
, false)
22 sys
.taskInit(function()
23 -----------------------------
25 ----------------------------
26 if wlan
and wlan
.connect
then
27 -- wifi 联网, ESP32系列均支持
28 local ssid
= "luatos1234"
29 local password
= "12341234"
30 log.info("wifi", ssid
, password
)
32 -- LED = gpio.setup(12, 0, gpio.PULLUP)
34 wlan
.setMode(wlan
.STATION
)
35 wlan
.connect(ssid
, password
, 1)
36 local result
, data
= sys
.waitUntil("IP_READY", 30000)
37 log.info("wlan", "IP_READY", result
, data
)
38 device_id
= wlan
.getMac()
39 elseif rtos
.bsp() == "AIR105" then
40 -- w5500 以太网, 当前仅Air105支持
41 w5500
.init(spi
.HSPI_0
, 24000000, pin
.PC14
, pin
.PC01
, pin
.PC00
)
42 w5500
.config() --默认是DHCP模式
43 w5500
.bind(socket
.ETH0
)
44 -- LED = gpio.setup(62, 0, gpio.PULLUP)
46 -- TODO 获取mac地址作为device_id
50 -- LED = gpio.setup(27, 0, gpio.PULLUP)
51 device_id
= mobile
.imei()
52 log.info("ipv6", mobile
.ipv6(true))
53 sys
.waitUntil("IP_READY", 30000)
55 sys
.waitUntil("IP_READY")
59 log.info("http", "当前固件未包含http库")
63 sys
.publish("net_ready")
66 function test_httpplus()
67 sys
.waitUntil("net_ready")
72 -- local code, resp =httpplus.request({method="POST", url="https://abc:qq@whoami.k8s.air32.cn/goupupup"})
73 -- log.info("http", code, resp)
76 -- local code, resp = httpplus.request({method="POST", url="https://air32.cn/goupupup"})
77 -- log.info("http", code, resp)
79 -- local code, resp = httpplus.request({method="POST", url="https://httpbin.air32.cn/post", files={abcd="/luadb/libfastlz.a"}})
80 -- log.info("http", code, resp)
82 -- local code, resp = httpplus.request({method="POST", url="https://httpbin.air32.cn/anything", forms={abcd="12345"}})
83 -- log.info("http", code, resp)
85 -- local code, resp = httpplus.request({method="POST", url="https://httpbin.air32.cn/post", files={abcd="/luadb/abc.txt"}})
86 -- log.info("http", code, resp)
89 local code
, resp
= httpplus
.request({url
="https://httpbin.air32.cn/"})
90 log.info("http", code
, resp
)
93 -- local code, resp = httpplus.request({url="https://httpbin.air32.cn/post", body="123456", method="POST"})
94 -- log.info("http", code, resp)
97 -- local code, resp = httpplus.request({url="https://httpbin.air32.cn/post", files={myfile="/luadb/abc.txt"}})
98 -- log.info("http", code, resp)
101 -- local code, resp = httpplus.request({url="https://httpbin.air32.cn/get", headers={Auth="12312234"}})
102 -- log.info("http", code, resp)
105 -- local code, resp = httpplus.request({url="https://wendal:123@httpbin.air32.cn/get", headers={Auth="12312234"}})
106 -- log.info("http", code, resp)
109 -- local code, resp = httpplus.request({url="https://httpbin.air32.cn/put", method="PUT", body="123"})
110 -- log.info("http", code, resp)
113 -- local code, resp = httpplus.request({url="https://httpbin.air32.cn/post", forms={abc="123"}})
114 -- log.info("http", code, resp)
117 local code
, resp
= httpplus
.request({url
="https://httpbin.air32.cn/stream/1"})
118 log.info("http", code
, resp
)
120 log.info("http", "headers", json
.encode(resp
.headers
))
121 local body
= resp
.body
:query()
122 log.info("http", "body", body
:toHex())
123 log.info("http", "body", body
)
124 log.info("http", "body", json
.decode(body
:trim()))
125 -- log.info("http", "body", json.decode(resp.body))
129 sys
.taskInit(test_httpplus
)
131 -- 用户代码已结束---------------------------------------------
134 -- sys.run()之后后面不要加任何语句!!!!!