Skip to content

Commit

Permalink
add: 把test目录全部提交一下,好久没提交了,累计到21个了
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Dec 22, 2023
1 parent 418f18a commit 4936478
Show file tree
Hide file tree
Showing 18 changed files with 674 additions and 31 deletions.
23 changes: 16 additions & 7 deletions test/001.helloworld/main.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@

_G.sys = require("sys")

print('Go')
-- print('Go')

sys.timerStart(function()
log.info("timer", "timeout once")
end, 1000)
-- sys.timerStart(function()
-- log.info("timer", "timeout once")
-- end, 1000)

sys.timerLoopStart(function()
log.info("timer", "3s repeat")
end, 3000)
-- sys.timerLoopStart(function()
-- log.info("timer", "3s repeat")
-- end, 3000)

sys.taskInit(function()
while 1 do
sys.wait(1000)
log.info("lua", rtos.meminfo())
log.info("sys", rtos.meminfo("sys"))
end

end)

sys.run()
4 changes: 3 additions & 1 deletion test/002.tcp/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
_G.sys = require("sys")
require "sysplus"

log.info("socket.ip", socket.localIP())

sys.taskInit(function()
sys.wait(100)
while 1 do
Expand All @@ -23,7 +25,7 @@ sys.taskInit(function()
log.info("netc", netc)
socket.config(netc)
socket.debug(netc, true)
socket.connect(netc, "112.125.89.8", 46631)
socket.connect(netc, "112.125.89.8", 41506)

while running do
sys.wait(100)
Expand Down
Binary file added test/004.http/gzip
Binary file not shown.
47 changes: 42 additions & 5 deletions test/004.http/main.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "httpdemo"
VERSION = "1.0.0"

_G.sys = require("sys")
require "sysplus"

sys.taskInit(function()
sys.wait(100)
local code, headers, body = http.request("GET", "https://www.air32.cn").wait()
log.info("http", code, json.encode(headers), body)
sys.waitUntil("IP_READY")
-- local code, headers, body = http.request("GET", "https://www.air32.cn").wait()
-- log.info("http", code, json.encode(headers), body)
local code, headers, body = http.request("POST", "http://ql.betterforyou.com.cn:9090/ck/app/appUpgrade/findMiniUpgrade?equId=QL10000001&equType=1").wait()
log.info("http.get", code, headers, body)

log.info("GoGoGo")
sys.wait(1000)

local code, headers, body = http.request("GET", "https://air32.cn").wait()
log.info("http", code, json.encode(headers), body)
local body = io.readFile("/luadb/wifi.json")
local code, headers, body = http.request("POST", "http://wifi.air32.cn/wifi", nil, body).wait()
log.info("http", code, json.encode(headers), #body)
-- log.info("http", "body", #body)
-- log.info("http", "body", body)

socket.sslLog(5)
local httpplus = require "httpplus"
-- local code, resp = httpplus.request({url="https://vaviri-back-ph4lj.ondigitalocean.app/state"})
local code, resp = httpplus.request({
url="http://wifi.air32.cn/wifi",
body=io.readFile("/luadb/wifi.json"),
headers={"Content-Type", "application/json"},
method="POST"}
)
local body = resp.body:query()
-- log.info("http", code, json.encode(resp.headers), #body)
log.info("http", "body", #body)
log.info("http", "body", body)
log.info("http", "body", body:toHex())

-- body = io.readFile("/luadb/gzip")
-- log.info("gzip", #body)
-- -- log.info("http", miniz.uncompress(body:sub(11)))
-- log.info("http", miniz.uncompress(body:sub(11), 0))
-- log.info("http", body:toHex())

-- local code, headers, body = http.request("GET", "http://quan.suning.com/getSysTime.do", {Accept="*/*", ["User-Agent"]="ABC"}, nil, {debug=true})
-- log.info("http", code, json.encode(headers), body)

-- local code, resp = httpplus.request({url="http://quan.suning.com/getSysTime.do"})
-- log.info("http", code, resp.body:query())
end)

sys.run()
1 change: 1 addition & 0 deletions test/004.http/wifi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"imei":"861551056435449","wifis":[{"mac":"6EB158564935","rssi":-46},{"mac":"6CB158A64935","rssi":-47},{"mac":"88C397CE0E89","rssi":-62},{"mac":"8EC397CE0E89","rssi":-63},{"mac":"A439B3D208A2","rssi":-68},{"mac":"AA39B3D208A2","rssi":-70},{"mac":"50D2F516AA9D","rssi":-76},{"mac":"8CDEF97FEB89","rssi":-78},{"mac":"345BBBF2D112","rssi":-78},{"mac":"6C06D6080B30","rssi":-82},{"mac":"92DEF97FEB89","rssi":-86},{"mac":"3446ECF3AEE1","rssi":-86},{"mac":"0C31DCC75D34","rssi":-86},{"mac":"3446ECD3AEDC","rssi":-87},{"mac":"1475905ABE04","rssi":-89},{"mac":"143CC39C61CC","rssi":-89},{"mac":"3095E361696D","rssi":-91},{"mac":"CC08FB75FE85","rssi":-91},{"mac":"3295E311696D","rssi":-92},{"mac":"A29D7E7E6223","rssi":-93}],"iccid":"89860323750207458090","unique_id":"3238363435061A4C4330","key":"freedemo"}
10 changes: 5 additions & 5 deletions test/005.mqtt/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ end
-- pm.request(pm.LIGHT)

--根据自己的服务器修改以下参数
local mqtt_host = "lbsmqtt.airm2m.com"
local mqtt_port = 1884
local mqtt_host = "124.223.67.31"
local mqtt_port = 1883
local mqtt_isssl = false
local client_id = "abc"
local user_name = "user"
local password = "password"
local client_id = "124"
local user_name = "1"
local password = "124"

local pub_topic = "/luatos/pub/" .. "pc"
local sub_topic = "/luatos/sub/" .. "pc"
Expand Down
101 changes: 101 additions & 0 deletions test/009.ftp/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "ftpdemo"
VERSION = "1.0.0"

--[[
本demo需要ftp库, 大部分能联网的设备都具有这个库
ftp也是内置库, 无需require
]]

-- sys库是标配
_G.sys = require("sys")
--[[特别注意, 使用ftp库需要下列语句]]
_G.sysplus = require("sysplus")

sys.taskInit(function()
-----------------------------
-- 统一联网函数, 可自行删减
----------------------------
if wlan and wlan.connect then
-- wifi 联网, ESP32系列均支持
local ssid = "luatos1234"
local password = "12341234"
log.info("wifi", ssid, password)
-- TODO 改成esptouch配网
-- LED = gpio.setup(12, 0, gpio.PULLUP)
wlan.init()
wlan.setMode(wlan.STATION)
wlan.connect(ssid, password, 1)
local result, data = sys.waitUntil("IP_READY", 30000)
log.info("wlan", "IP_READY", result, data)
device_id = wlan.getMac()
elseif rtos.bsp() == "AIR105" then
-- w5500 以太网, 当前仅Air105支持
-- w5500.init(spi.SPI_2, 24000000, pin.PB03, pin.PC00, pin.PC03)
w5500.init(spi.HSPI_0, 24000000, pin.PC14, pin.PC01, pin.PC00)
log.info("auto mac", w5500.getMac():toHex())
w5500.config() --默认是DHCP模式
w5500.bind(socket.ETH0)
-- LED = gpio.setup(62, 0, gpio.PULLUP)
sys.wait(1000)
-- TODO 获取mac地址作为device_id
elseif mobile then
-- Air780E/Air600E系列
--mobile.simid(2)
-- LED = gpio.setup(27, 0, gpio.PULLUP)
device_id = mobile.imei()
sys.waitUntil("IP_READY", 30000)
end

-- -- 打印一下支持的加密套件, 通常来说, 固件已包含常见的99%的加密套件
-- if crypto.cipher_suites then
-- log.info("cipher", "suites", json.encode(crypto.cipher_suites()))
-- end
while true do
sys.wait(1000)
log.info("ftp 启动")
print(ftp.login(nil,"121.43.224.154",21,"ftp_user","3QujbiMG").wait())

print(ftp.command("NOOP").wait())
print(ftp.command("SYST").wait())

print(ftp.command("TYPE I").wait())
print(ftp.command("PWD").wait())
print(ftp.command("MKD QWER").wait())
print(ftp.command("CWD /QWER").wait())

print(ftp.command("CDUP").wait())
print(ftp.command("RMD QWER").wait())

print(ftp.command("LIST").wait())

-- io.writeFile("/1222.txt", "23noianfdiasfhnpqw39fhawe;fuibnnpw3fheaios;fna;osfhisao;fadsfl")
-- print(ftp.push("/1222.txt","/12222.txt").wait())

print(ftp.pull("/122224.txt","/122224.txt").wait())

local f = io.open("/122224.txt", "r")
if f then
local data = f:read("*a")
f:close()
log.info("fs", "writed data", data)
else
log.info("fs", "open file for read failed")
end

print(ftp.command("DELE /12222.txt").wait())
print(ftp.push("/122224.txt","/12222.txt").wait())
print(ftp.close().wait())
log.info("meminfo", rtos.meminfo("sys"))
sys.wait(15000)
end


end)


-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!
16 changes: 9 additions & 7 deletions test/011.onenet_coap/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ require "sysplus"
udp_host = "183.230.102.122"
udp_port = 5683
-- 设备信息
produt_id = "SJaLt5cVL2"
product_id = "SJaLt5cVL2"
device_name = "luatospc"
device_key = "dUZVVWRIcjVsV2pSbTJsckd0TmgyRXNnMTJWMXhIMkk="

_, _, main_token = iotauth.onenet(produt_id,device_name,device_key,"sha1")
_, _, main_token = iotauth.onenet(product_id,device_name,device_key,"sha1")

-- UDP事件处理函数
local rxbuff = zbuff.create(1500)
Expand Down Expand Up @@ -46,8 +46,9 @@ function udpcb(sc, event)
elseif event == socket.ON_LINE then
log.info("udp", "UDP已准备就绪,可以上行")
-- 上行登陆包
local data = ercoap.onenet("login", produt_id, device_name, main_token)
-- log.info("上行登陆包", data:toHex())
log.info("登陆参数", product_id, device_name, main_token)
local data = ercoap.onenet("login", product_id, device_name, main_token)
log.info("上行登陆包", data:toHex())
socket.tx(sc, data)
else
log.info("udp", "其他事件", event)
Expand All @@ -72,8 +73,8 @@ sys.taskInit(function()
break
end
-- 上行心跳包
-- onenet_coap_auth(string.format("$sys/%s/%s/keep_alive", produt_id, device_name))
local data = ercoap.onenet("keep_alive", produt_id, device_name, main_token)
-- onenet_coap_auth(string.format("$sys/%s/%s/keep_alive", product_id, device_name))
local data = ercoap.onenet("keep_alive", product_id, device_name, main_token)
-- log.info("上行心跳包", data:toHex())
socket.tx(netc, data)

Expand All @@ -94,7 +95,8 @@ sys.taskInit(function()
log.info("uplink", jdata)
-- jdata = [[{"id":"3","version":"1.0","params":{"WaterMeterState":{"value":0}}}]]
-- log.info("uplink2", jdata)
local data = ercoap.onenet("thing/property/post", produt_id, device_name, post_token, jdata)
log.info("uplink", "thing/property/post", product_id, device_name, post_token:toHex(), jdata)
local data = ercoap.onenet("thing/property/post", product_id, device_name, post_token, jdata)
-- log.info("onenet", "上行物模型数据", data:toHex())
socket.tx(netc, data)
end
Expand Down
12 changes: 6 additions & 6 deletions test/012.sqlite3/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ _G.sys = require("sys")

sys.taskInit(function()
sys.wait(1000)
local db = sqlite3.open("/ram/test.db")
local db = sqlite3.open("test.db")
log.info("sqlite3", db)
if db then
sqlite3.exec(db, "CREATE TABLE devs(ID INT PRIMARY KEY NOT NULL, name CHAR(50));")
sqlite3.exec(db, "insert into devs values(1, \"ABC\");")
sqlite3.exec(db, "insert into devs values(2, \"DEF\");")
sqlite3.exec(db, "insert into devs values(3, \"HIJ\");")
local ret, data = sqlite3.exec(db, "select * from devs;")
sqlite3.exec(db, "CREATE TABLE devs(ID INT PRIMARY KEY NOT NULL, name CHAR(50))")
sqlite3.exec(db, "insert into devs values(1, \"ABC\")")
sqlite3.exec(db, "insert into devs values(2, \"DEF\")")
sqlite3.exec(db, "insert into devs values(3, \"HIJ\")")
local ret, data = sqlite3.exec(db, "select * from devs where id > 1 order by id desc limit 2")
log.info("查询结果", ret, data)
if ret then
for k, v in pairs(data) do
Expand Down
41 changes: 41 additions & 0 deletions test/013.libgnss/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

_G.sys = require("sys")

PROJECT = "logtest"
VERSION = "1.0.0"

sys.taskInit(function()
local tm = {
year = 2023,
month = 11,
mon = 11,
day = 22,
hour = 15,
min = 30,
sec = 44
}
local lla = {
lat = "113.5",
lng = "022.5"
}
log.info(">>", json.encode(os.date("!*t")))
local aid = libgnss.casic_aid(tm, lla)
log.info("AID", aid:toHex())
-- BACE38000B010000000000605C400000000000803640000000000000000000000000D43A1341
-- 0000000000000000000000000000000000000000F108 00 23 FD 23 B1 E5
-- BACE38000B010000000000605C400000000000803640000000000000000000000000D43A1341
-- 0000000000000000000000000000000060FD0601F108 00 23 5D 21 B8 E6
-- BACE38000B010000000000605C400000000000803640000000000000000000000000D43A1341
-- 0000000000000000000000000000000000000000F108 00 23 FD 23 B1 E5

local str = "$GNRMC,000625.00,A,3557.35652,N,13854.27058,E,1.681,73.98,111223,,,A,V*32\r\n"
-- libgnss.init()
libgnss.parse(str)
log.info("GNSS", libgnss.getIntLocation())
log.info("GNSS", 1.681 * 1852)
log.info("GNSS", libgnss.getIntLocation(1))
log.info("GNSS", libgnss.getIntLocation(2))
log.info("GNSS", libgnss.getIntLocation(3))
end)

sys.run()
16 changes: 16 additions & 0 deletions test/014.ntp/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

_G.sys = require("sys")

sys.taskInit(function()
sys.waitUntil("IP_READY")
while 1 do
socket.sntp()
sys.waitUntil("NTP_UPDATE", 10000)
local tm = socket.ntptm()
log.info("tm数据", json.encode(tm))
log.info("时间戳", string.format("%u.%03d", tm.tsec, tm.tms))
sys.wait(5000)
end
end)

sys.run()
23 changes: 23 additions & 0 deletions test/015.lvgl_switch_event/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

sys = require "sys"
log.info("lvgl", lvgl.init())

local function event_handler(obj, event)
log.info("event", event)
end

sys.taskInit(function()
local sw1 = lvgl.switch_create(lvgl.scr_act(), nil);
lvgl.obj_align(sw1, nil, lvgl.ALIGN_CENTER, 0, -50);
lvgl.obj_set_event_cb(sw1, event_handler);

while 1 do
sys.wait(1000)
lvgl.switch_on(sw1, lvgl.ANIM_ON)
sys.wait(1000)
lvgl.switch_off(sw1, lvgl.ANIM_OFF)
end
end)

sys.run()

Loading

0 comments on commit 4936478

Please sign in to comment.