|
|
@@ -15,7 +15,9 @@
|
|
|
-- 发送数据,输入参数为数据,发送模式,发送序号
|
|
|
-- 发送模式为ctiot.CON, ctiot.NON, ctiot.NON_REL, ctiot.CON_REL
|
|
|
-- 发送序号只是一个标识,不会影响发送的数据和模式,在发送结果回调时会返回
|
|
|
-
|
|
|
+-- ctiot.isReady()
|
|
|
+-- 检测当前ctiot连接状态是否可以发送数据
|
|
|
+-- 0可以,其他都不可以
|
|
|
PROJECT = "ctiot"
|
|
|
VERSION = "1.0.0"
|
|
|
local TAG="ctiot"
|
|
|
@@ -46,30 +48,32 @@ end
|
|
|
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_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修改
|
|
|
--发送数据,并要求服务器应答
|
|
|
- ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON, 33)
|
|
|
+ result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON, 33)
|
|
|
--发送数据,并要求服务器应答,序号为11
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON, 11)
|
|
|
+ --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON, 11)
|
|
|
--发送数据,不需要服务器应答
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON, 0)
|
|
|
+ --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON, 0)
|
|
|
--发送数据,不需要服务器应答,序号为23
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON, 23)
|
|
|
+ --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON, 23)
|
|
|
--发送数据,不需要服务器应答,发送完成后立刻释放RRC,加快进入休眠的速度
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON_REL, 0)
|
|
|
+ --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON_REL, 0)
|
|
|
--发送数据,不需要服务器应答,发送完成后立刻释放RRC,加快进入休眠的速度,序号为56
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON_REL, 56)
|
|
|
+ --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.NON_REL, 56)
|
|
|
--发送数据,并要求服务器应答,接收到应答后立刻释放RRC,加快进入休眠的速度
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON_REL, 0)
|
|
|
+ --result, tx_error = ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON_REL, 0)
|
|
|
--发送数据,并要求服务器应答,接收到应答后立刻释放RRC,加快进入休眠的速度,序号为255,序号最大255
|
|
|
- --ctiot.write(pack.pack("<bbA", 0x00,0x05, "hello"), ctiot.CON_REL, 255)
|
|
|
- local result, tx_error, error_code, param = sys.waitUntilExt("CTIOT_TX", 20000)
|
|
|
+ --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)
|
|
|
@@ -85,40 +89,55 @@ end
|
|
|
local function task()
|
|
|
local inSleep = false
|
|
|
local isConnected = false
|
|
|
- --设置自定义EP,如果不设置,则使用IMEI
|
|
|
- local ep="qweasdzxcrtyfgh"
|
|
|
- if ctiot.ep() ~= ep then
|
|
|
- ctiot.ep(ep)
|
|
|
+ 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("180.101.147.115", 5683, 300)
|
|
|
+ local ip, port, keeptime = ctiot.param()
|
|
|
+ log.info(TAG, "set param", ip, port, keeptime)
|
|
|
end
|
|
|
- --设置服务器IP,端口,保活时间
|
|
|
- ctiot.param("180.101.147.115", 5683, 300)
|
|
|
- local ip, port, keeptime = ctiot.param()
|
|
|
- log.info(TAG, "set param", ip, port, keeptime)
|
|
|
while not socket.isReady() do
|
|
|
log.info("net", "wait for network ready")
|
|
|
sys.waitUntil("NET_READY", 1000)
|
|
|
end
|
|
|
-- 非普通上电/复位上电,那就是唤醒上电咯
|
|
|
if pm.lastReson() ~= 0 then
|
|
|
- isConnected = true
|
|
|
+
|
|
|
else
|
|
|
--启动连接
|
|
|
- pm.request(pm.IDLE)
|
|
|
ctiot.connect()
|
|
|
- local result, reg_error, error_code, param
|
|
|
while true do
|
|
|
- result, reg_error, error_code, param = sys.waitUntilExt("CTIOT_REG", 30000)
|
|
|
- if not result and reg_error==nil then
|
|
|
+ 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, reg_error, error_code, param)
|
|
|
- if not reg_error and param > 0 then
|
|
|
+ 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 reg_error then
|
|
|
+ if error then
|
|
|
log.info(TAG, "reg fail")
|
|
|
break
|
|
|
end
|