Score
0
Watch 77 Star 332 Fork 68

合宙Luat / LuatOSLuaMIT

CTwing

任务
已完成
handrap  Opened this issue

ctiot demo每次只发送成功两次,第三次显示tx ok,但平台没收到。后面都tx fail是为什么?

[11:18:16.171]收←◆I/luat.pm poweron: Wakup Hib by
[11:18:16.196]收←◆RTC
I/luat.main LuatOS@ec616 V0003, build at: Sep 8 2020 17:11:15
I/luat.fs LFS_Init re=0
D/luat.fs.LFS luat_fs_fopen /update.bin rb 00000000
D/luat.fs.LFS luat_fs_fopen /rollback_mark rb 00000000
D/luat.main Lua complied with LUA_32BITS
D/luat.main luavm 73720 11864 11896
D/luat.main sys 30720 9916 10556
D/luat.pkg open file=/main.luac ret=0
D/luat.pkg file size = 2342
I/luat.pkg module require result=2
D/luat.pkg open file=/sys.luac ret=0
D/luat.pkg file size = 4518
I/luat.pkg module require result=2
I/luat.pm request mode=1, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
I/user.ctiot after 221.229.214.202 5683 300
D/luat.ctiot luat_ctiot_callback 163:3,0,0x00000000,0
I/user.ctiot wakeup and wait ready

[11:18:16.768]收←◆I/user.ctiot test tx
D/luat.ctiot luat_ctiot_callback 163:255,255,0x00000000,33
I/user.ctiot true nil
I/user.ctiot other false 255 255

[11:18:16.867]收←◆D/luat.ctiot luat_ctiot_callback 163:5,1,0x00000000,33

[11:18:17.634]收←◆D/luat.ctiot luat_ctiot_callback 163:5,0,0x00000000,33
D/luat.ctiot luat_ctiot_callback 163:10,1,0x00000000,33
I/user.ctiot tx ok 33
I/luat.pm request mode=4, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE/SLEEP1/SLEEP2/HIB
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: NULL Vote count: 0

[11:18:38.625]收←◆D/luat.pm Entry into Hibernate = aabbccdd

[11:19:17.612]收←◆I/luat.pm poweron: Wakup Hib by RTC
I/luat.main LuatOS@ec616 V0003, build at: Sep 8 2020 17:11:15
I/luat.fs LFS_Init re=0
D/luat.fs.LFS luat_fs_fopen /update.bin rb 00000000
D/luat.fs.LFS luat_fs_fopen /rollback_mark rb 00000000
D/luat.main Lua complied with LUA_32BITS
D/luat.main luavm 73720 11872 11904
D/luat.main sys 30720 9916 10556
D/luat.pkg open file=/main.luac ret=0
D/luat.pkg file size = 2342
I/luat.pkg module require result=2
D/luat.pkg open file=/sys.luac ret=0
D/luat.pkg file size = 4518
I/luat.pkg module require result=2
I/luat.pm request mode=1, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
I/user.ctiot after 221.229.214.202 5683 300
D/luat.ctiot luat_ctiot_callback 163:3,0,0x00000000,0
I/user.ctiot wakeup and wait ready

[11:19:18.209]收←◆I/user.ctiot test tx
D/luat.ctiot luat_ctiot_callback 163:255,255,0x00000000,33
I/user.ctiot true nil
I/user.ctiot other false 255 255

[11:19:18.308]收←◆D/luat.ctiot luat_ctiot_callback 163:5,1,0x00000000,33

[11:19:19.108]收←◆D/luat.ctiot luat_ctiot_callback 163:5,0,0x00000000,33
D/luat.ctiot luat_ctiot_callback 163:10,1,0x00000000,33
I/user.ctiot tx ok 33
I/luat.pm request mode=4, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE/SLEEP1/SLEEP2/HIB
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: NULL Vote count: 0

[11:19:40.083]收←◆D/luat.pm Entry into Hibernate =
[11:19:40.105]收←◆ aabbccdd

[11:20:19.087]收←◆I/luat.pm poweron: Wakup Hib by RTC
I/luat.main LuatOS@ec616 V0003, build at: Sep 8 2020 17:11:15
I/luat.fs LFS_Init re=0
D/luat.fs.LFS luat_fs_fopen /update.bin rb 00000000
D/luat.fs.LFS luat_fs_fopen /rollback_mark rb 00000000
D/luat.main Lua complied with LUA_32BITS
D/luat.main luavm 73720 11864 11896
D/luat.main sys 30720 9916 10556
D/luat.pkg open file=/main.luac ret=0
D/luat.pkg file size = 2342
I/luat.pkg module require result=2
D/luat.pkg open file=/sys.luac ret=0
D/luat.pkg file size = 4518
I/luat.pkg module require result=2
I/luat.pm request mode=1, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
I/user.ctiot after 221.229.214.202 5683 300
D/luat.ctiot luat_ctiot_callback 163:3,0,0x00000000,0
I/user.ctiot wakeup and wait ready

[11:20:19.685]收←◆I/user.ctiot test tx
D/luat.ctiot luat_ctiot_callback 163:255,255,0x00000000,33
I/user.ctiot true nil
I/user.ctiot other false 255 255

[11:20:19.784]收←◆D/luat.ctiot luat_ctiot_callback 163:5,1,0x00000000,33

[11:20:20.514]收←◆D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33
I/user.ctiot tx fail 4 0
I/luat.pm request mode=4, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE/SLEEP1/SLEEP2/HIB
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: NULL Vote count: 0
D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33

[11:20:41.524]收←◆D/luat.pm Entry into Hibernate = aabbccdd

[11:21:20.488]收←◆I/luat.pm poweron: Wakup Hib by
[11:21:20.506]收←◆RTC
I/luat.main LuatOS@ec616 V0003, build at: Sep 8 2020 17:11:15
I/luat.fs LFS_Init re=0
D/luat.fs.LFS luat_fs_fopen /update.bin rb 00000000
D/luat.fs.LFS luat_fs_fopen /rollback_mark rb 00000000
D/luat.main Lua complied with LUA_32BITS
D/luat.main luavm 73720 11864 11896
D/luat.main sys 30720 9916 10556
D/luat.pkg open file=/main.luac ret=0
D/luat.pkg file size = 2342
I/luat.pkg module require result=2
D/luat.pkg open file=/sys.luac ret=0
D/luat.pkg file size = 4518
I/luat.pkg module require result=2
I/luat.pm request mode=1, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
I/user.ctiot after 221.229.214.202 5683 300
D/luat.ctiot luat_ctiot_callback 163:3,0,0x00000000,0
I/user.ctiot wakeup and wait ready

[11:21:21.084]收←◆I/user.ctiot test tx
D/luat.ctiot luat_ctiot_callback 163:255,255,0x00000000,33
I/user.ctiot true nil
I/user.ctiot other false 255 255

[11:21:21.185]收←◆D/luat.ctiot luat_ctiot_callback
[11:21:21.210]收←◆ 163:5,1,0x00000000,33

[11:21:21.952]收←◆D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33
I/user.ctiot tx fail 4 0
I/luat.pm request mode=4, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE/SLEEP1/SLEEP2/HIB
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: NULL Vote count: 0
D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33

[11:21:42.962]收←◆D/luat.pm Entry into Hibernate =
[11:21:43.004]收←◆ aabbccdd

[11:22:21.928]收←◆I/luat.pm poweron: Wakup Hib by RTC

[11:22:21.959]收←◆I/luat.main LuatOS@ec616 V0003, build at: Sep 8 2020 17:11:15
I/luat.fs LFS_Init re=0
D/luat.fs.LFS luat_fs_fopen /update.bin rb 00000000
D/luat.fs.LFS luat_fs_fopen /rollback_mark rb 00000000
D/luat.main Lua complied with LUA_32BITS
D/luat.main luavm 73720 11872 11904
D/luat.main sys 30720 9916 10556
D/luat.pkg open file=/main.luac ret=0
D/luat.pkg file size = 2342
I/luat.pkg module require result=2
D/luat.pkg open file=/sys.luac ret=0
D/luat.pkg file size = 4518
I/luat.pkg module require result=2
I/luat.pm request mode=1, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
I/user.ctiot after 221.229.214.202 5683 300
D/luat.ctiot luat_ctiot_callback 163:3,0,0x00000000,0
I/user.ctiot wakeup and wait ready

[11:22:22.525]收←◆I/user.ctiot test tx
D/luat.ctiot luat_ctiot_callback 163:255,255,0x00000000,33
I/user.ctiot true nil
I/user.ctiot other false 255 255

[11:22:22.624]收←◆D/luat.ctiot luat_ctiot_callback 163:5,1,0x00000000,33

[11:22:23.404]收←◆D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33
I/user.ctiot tx fail 4 0
I/luat.pm request mode=4, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE/SLEEP1/SLEEP2/HIB
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: NULL Vote count: 0
D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33

[11:22:44.402]收←◆D/luat.pm Entry into Hibernate = aabbccdd

[11:23:23.379]收←◆I/luat.pm poweron: Wakup Hib by
[11:23:23.414]收←◆RTC
I/luat.main LuatOS@ec616 V0003, build at: Sep 8 2020 17:11:15
I/luat.fs LFS_Init re=0
D/luat.fs.LFS luat_fs_fopen /update.bin rb 00000000
D/luat.fs.LFS luat_fs_fopen /rollback_mark rb 00000000
D/luat.main Lua complied with LUA_32BITS
D/luat.main luavm 73720 11864 11896
D/luat.main sys 30720 9916 10556
D/luat.pkg open file=/main.luac ret=0
D/luat.pkg file size = 2342
I/luat.pkg module require result=2
D/luat.pkg open file=/sys.luac ret=0
D/luat.pkg file size = 4518
I/luat.pkg module require result=2
I/luat.pm request mode=1, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
I/user.ctiot after 221.229.214.202 5683 300
D/luat.ctiot luat_ctiot_callback 163:3,0,0x00000000,0
I/user.ctiot wakeup and wait ready

[11:23:23.975]收←◆I/user.ctiot test tx
D/luat.ctio
[11:23:23.995]收←◆t luat_ctiot_callback 163:255,255,0x00000000,33
I/user.ctiot true nil
I/user.ctiot other false 255 255

[11:23:24.076]收←◆D/luat.ctiot luat_ctiot_callback 163:5,1,0x00000000,33

[11:23:24.833]收←◆D/luat.ctiot luat_ctiot_callback
[11:23:24.856]收←◆ 163:5,4,0x00000000,33
I/user.ctiot tx fail 4 0
I/luat.pm request mode=4, prev mode=1
D/luat.pm Prev Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: Slp1 Vote count: 1
D/luat.pm allow IDLE/SLEEP1/SLEEP2/HIB
D/luat.pm Curr Sleep Handle setting====
D/luat.pm Handle: 0 Name: APP Prohibit State: NULL Vote count: 0
D/luat.ctiot luat_ctiot_callback 163:5,4,0x00000000,33

[11:23:45.811]收←◆D/luat.pm Entry into Hibernate = aabbccdd

=========================

这里输入代码
-- ctiot库API
-- ctiot.init() 
-- 初始化引擎,开机后只需要一次,没有参数输入输出
-- ctiot.ep(new_ep) 
-- 设置读取用户自定义EP,如果不设置,则使用IMEI,输入新的EP,同时输出当前EP,
-- 输入nil,则为读取,输入"",清除EP
-- ctiot.param(server_ip, server_port, lifetime)
-- 设置读取必要的参数,分别为服务器IP,端口和保活时间
-- 输入nil,则为读取参数
-- ctiot.connect()
-- 启动连接服务器
-- ctiot.disconnect()
-- 断开服务器
-- ctiot.write(data, mode, seq)
-- 发送数据,输入参数为数据,发送模式,发送序号
-- 发送模式为ctiot.CON, ctiot.NON, ctiot.NON_REL, ctiot.CON_REL
-- 发送序号只是一个标识,不会影响发送的数据和模式,在发送结果回调时会返回
-- ctiot.isReady()
-- 检测当前ctiot连接状态是否可以发送数据
-- 0可以,其他都不可以
PROJECT = "ctiot"
VERSION = "1.0.0"
local TAG="ctiot"
-- sys库是标配
_G.sys = require("sys")

local function cb_rx(data)
    log.info(TAG, "rx", data:toHex())
end

local function cb_dereg(error, error_code, param)
    log.info(TAG, "dereg", error, error_code, param)
end

local function cb_wakeup(error, error_code, param)
    log.info(TAG, "wakeup", error, error_code, param)
end

local function cb_fota(error, error_code, param)
    log.info(TAG, "fota", error, error_code, param)
end

local function cb_other(error, error_code, param)
    log.info(TAG, "other", error, error_code, param)
end

--sys.subscribe("CTIOT_TX", cb_tx)
sys.subscribe("CTIOT_RX", cb_rx)
--sys.subscribe("CTIOT_REG", cb_reg)
--sys.subscribe("CTIOT_DEREG", cb_dereg)
--sys.subscribe("CTIOT_WAKEUP", cb_wakeup)
sys.subscribe("CTIOT_OTHER", cb_other)
sys.subscribe("CTIOT_FOTA", cb_fota)

local function send_test()
    log.info(TAG, "test tx")
    local result, tx_error, error_code, param
    --发送的数据请按照自己的profile修改
    --发送数据,并要求服务器应答
    result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON, 33)
    --发送数据,并要求服务器应答,序号为11
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON, 11)
    --发送数据,不需要服务器应答
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON, 0)
    --发送数据,不需要服务器应答,序号为23
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON, 23)
    --发送数据,不需要服务器应答,发送完成后立刻释放RRC,加快进入休眠的速度
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON_REL, 0)
    --发送数据,不需要服务器应答,发送完成后立刻释放RRC,加快进入休眠的速度,序号为56
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON_REL, 56)
    --发送数据,并要求服务器应答,接收到应答后立刻释放RRC,加快进入休眠的速度
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON_REL, 0)
    --发送数据,并要求服务器应答,接收到应答后立刻释放RRC,加快进入休眠的速度,序号为255,序号最大255
    --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON_REL, 255)
    log.info(TAG, result, tx_error)
    result, tx_error, error_code, param = sys.waitUntilExt("CTIOT_TX", 20000)
    if result then
        if not tx_error then
            log.info(TAG, "tx ok", param)
        else
            log.info(TAG, "tx fail", error_code, param)
        end
    else
        log.info(TAG, "tx no work")
    end

end

local function task()
    local inSleep = false
    local isConnected = false
    local result, error, error_code, param
    if pm.lastReson() ~= 0 then
        --唤醒的不需要处理
        pm.request(pm.IDLE)
        log.info(TAG, "after", ctiot.ep(), ctiot.param())
        result, error, error_code, param = sys.waitUntilExt("CTIOT_WAKEUP", 30000)
        if not result then
            log.info(TAG, "wakeup but ctiot not ready")
        else
            while ctiot.isReady() > 0 do
                log.info(TAG, "wakeup and wait ready")
                sys.wait(500)
            end
            isConnected = true
        end
    else
        --设置自定义EP,如果不设置,则使用IMEI
        -- local ep="qweasdzxcrtyfgh"
        -- if ctiot.ep() ~= ep then
        --     ctiot.ep(ep)
        -- end
        --设置服务器IP,端口,保活时间
        ctiot.param("221.229.214.202", 5683, 300)
        local ip, port, keeptime = ctiot.param()
        log.info(TAG, "set param", ip, port, keeptime)
    end
	while not socket.isReady() do 
		log.info("net", "wait for network ready")
		sys.waitUntil("NET_READY", 1000)
    end
    -- 非普通上电/复位上电,那就是唤醒上电咯
    if pm.lastReson() ~= 0 then
        
    else
        --启动连接
        ctiot.connect()
        while true do
            result, error, error_code, param = sys.waitUntilExt("CTIOT_REG", 30000)
            if not result and error==nil then
                log.info(TAG, "reg wait timeout")
                break
            end
            log.info(TAG, result, error, error_code, param)
            if not error and param > 0 then
                log.info(TAG, "reg ok")
                isConnected = true
                break
            end
            if error then
                log.info(TAG, "reg fail")
                break
            end
        end

    end
    if isConnected then
        send_test()
    end
    -- 30秒后唤醒,发个测试数据
    if not inSleep then
        pm.dtimerStart(0, 60000)
        inSleep = true
    end
    -- 我要睡了!!! 事实上还会等几秒, 这时候服务器还能下发数据
    pm.request(pm.HIB)
    -- 退出CTIOT
    -- ctiot.dereg()
    -- result, dereg_error, error_code, param = sys.waitUntilExt("CTIOT_DEREG", 30000)
end
ctiot.init()
sys.taskInit(task)
sys.run()

Attachments
4674 wendal 1578914274 total 4 participants

Comments (3)

4674 wendal 1578914274
Wendal 2020-09-14 12:53 owner

代码也贴一下吧, 是demo里面的吗?

alien2017 2020-09-14 13:38 member

在ctwing管理界面里确认一下设备接入地址是不是221.229.214.202,还是180.101.147.115

诸葛钢铁 2020-09-18 17:50

保活时间太短了吧,才300?

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority