1.调整目录结构

2.增加README
This commit is contained in:
DuXingJie
2022-08-07 19:40:35 +08:00
parent 7c32115ab7
commit e731a9472b
8 changed files with 39 additions and 0 deletions

37
sdk/合宙/README.md Normal file
View File

@@ -0,0 +1,37 @@
## 硬件端合宙SDK说明
#### 一、运行环境
- vs code 仿真
- air724板子 在选择底层库pac文件时注意 支持float 类型
1. 在vs code 里面安装 luatIDE
2. 安装air724 usb 相关驱动
3. 使用luatools
以上均参考 https://doc.openluat.com/wiki/26?wiki_page_id=3063
#### 二、运行代码
1. 在vs code 下仿真调试
mainVscode.lua 复制为 main.lua
注释掉 WeiMeiApp.lua 里面与硬件相关的代码 如adc 温度等
在WuMeiTest.lua 文件里面 配置 产品ID MQTT 等信息
仿真调试
2. 在air724硬件上运行代码
mainAir724.lua 复制为 main.lua
取消 WeiMeiApp.lua 里面与硬件相关的代码注释 如adc 温度等
在WuMeiTest.lua 文件里面 配置 产品ID MQTT 等信息
用luatools 建立工程 需要加载 main.lua WeiMeiApp.lua WeiMeiComAuth.lua WeiMeiComInteraction.lua WuMeiTest.lua 文件 以及带float 类型的底层库
#### 三、代码文件说明
1. WeiMeiComAuth.lua 用于认证处理
支持 简单认证和加密认证
2. WeiMeiComInteraction.lua 用户交互
支持 信息 属性 功能 事件 监控
支持 设置定时上传 属性 功能 事件
3. WeiMeiApp.lua
主要开发在这个文件里面
对外提供 信息 属性 功能 事件 数据函数 改函数直接返回打包好的json 字符串

83
sdk/合宙/WeiMeiApp.lua Normal file
View File

@@ -0,0 +1,83 @@
--- 模块功能物美MQTT应用
-- @author 杜兴杰
-- @module 物美MQTT应用
-- @license MIT
-- @copyright 杜兴杰
-- @email 1066950103@qq.com
-- @release 2022.8.5
module(..., package.seeall)
local VERSION = "0.1"
local m_strUserId = "1"
local m_strLongitude = "0"
local m_strLatitude = "0"
local m_nTemperature = 25
--local m_nVoltval = 4.0
--模块温度返回回调函数
--@temp温度srting类型如果要对该值进行运算可以使用带float的固件将该值转为number
local function getTemperatureCb(temp)
m_nTemperature = temp
end
--- ADC读取测试
-- @return 无
-- @usage read()
local function read0()
--ADC0接口用来读取电压
local ADC_ID = 0
local adcval,voltval = adc.read(ADC_ID)
log.info("testAdc0.read",adcval,(voltval-(voltval%3))/3,voltval)
-- 输出计算得出的原始电压值
m_nVoltval = voltval/3 * 3127 / 1000
log.info("testAdc0.Vbat", m_nVoltval)
end
--2秒循环查询模块温度
sys.timerLoopStart(misc.getTemperature,1000,getTemperatureCb)
sys.timerLoopStart(read0,1000)
-- 开启对应的adc通道
adc.open(0)
function FunctionData()
local jsonStr = ""
end
function PropertyData()
local jsonData = {{
id= "temperature",
value= m_nTemperature ,
remark="温度信息"
},{
id= "voltage",
value= m_nVoltval,
remark="电压信息"
}}
local jsonStr = json.encode(jsonData)
return jsonStr
end
function InformationData()
local jsonData = {
rssi = net.getRssi(),
firmwareVersion = VERSION,
status = 3 ,
userId = m_strUserId ,
longitude = m_strLongitude ,
latitude = m_strLatitude,
summary = {
name= "device",
chip = "air724",
author = "duxingjie",
version=0.1,
create = "2022-08-07"
}
}
local jsonStr = json.encode(jsonData)
return jsonStr
end

View File

@@ -0,0 +1,175 @@
--- 模块功能物美MQTT认证
-- @author 杜兴杰
-- @module 物美MQTT通信
-- @license MIT
-- @copyright 杜兴杰
-- @email 1066950103@qq.com
-- @release 2022.8.4
module(..., package.seeall)
require"http"
require"utils"
require "common"
require"misc"
local m_strEncryptionMode
local m_strProductId
local m_strDeviceId
local m_strUserId
local m_strUser
local m_strPassword
local m_nTimeout
local m_strIp
local m_strDeviceAuthorizationCode = nil
local m_strProductPassword = nil
local m_InitCallback = nil
local m_strOutPassword
local m_strClientId
local m_nTimeSyncFlag
local function CreateCommunicationPassword()
if m_strEncryptionMode == "S" then
if nil == m_strDeviceAuthorizationCode then
m_strOutPassword = m_strPassword
else
m_strOutPassword = m_strPassword .. "&" .. m_strDeviceAuthorizationCode
end
return true
end
if m_strEncryptionMode == "E" then
m_strOutPassword = AesPassword()
return true
end
return false
end
local function Callback(nResult)
log.info("Callback" .. nResult)
if m_InitCallback ~= nil then
m_InitCallback(nResult)
end
end
local function ParameterCheck()
return true
end
local function FormatUnixTime2Date(unixTime)
if unixTime and unixTime >= 0 then
unixTime = unixTime /1000
local ntim = os.date("*t", unixTime)
return ntim
end
end
local function CreatedClientId()
m_strClientId = m_strEncryptionMode .. "&" .. m_strDeviceId .. "&" .. m_strProductId .. "&" .. m_strUserId
end
local function httpCallbackFun(result,prompt,head,body)
log.info("GetTimeHttp.cbFnc",result,prompt)
if result and body then
log.info("GetTimeHttp.cbFnc"..body.."bodyLen="..body:len())
local nDeviceRunTickMs = rtos.tick() * 5
local jsonObj = json.decode(body)
local nDeviceSendTime = jsonObj["deviceSendTime"]
local nServerSendTime = jsonObj["serverSendTime"]
local nServerRecvTime = jsonObj["serverRecvTime"]
local nSyncTime = (nServerRecvTime + nServerSendTime + nDeviceRunTickMs - nDeviceSendTime)/2
log.info("nSyncTime=" .. nSyncTime)
local tTime = FormatUnixTime2Date(nSyncTime)
log.info("tTime" .. tTime.year)
misc.setClock(tTime,nil)
--rtos.set_time(tTime.year,tTime.month,tTime.day,tTime.hour,tTime.min,tTime.sec)
--创建客户端ID
CreatedClientId()
--创建密码
CreateCommunicationPassword()
Callback(1)
m_nTimeSyncFlag = 1
end
end
function SyncTime()
local nDeviceRunTickMs = rtos.tick() * 5
local strUrl = "http://" .. m_strIp .. ":8080/iot/tool/ntp?deviceSendTime=" .. nDeviceRunTickMs
http.request("GET",strUrl,nil,nil,nil,nil,httpCallbackFun)
end
local function GetCurrentTime()
local tm = misc.getClock()
local nCurrentTime = os.time(tm)
return nCurrentTime
end
local function AesPassword()
local nCurrentTime = GetCurrentTime()
local nExpireTime = m_nTimeout + nCurrentTime
local strAesSource = nil
if nil == m_strDeviceAuthorizationCode then
strAesSource = m_strPassword .. "&" .. nExpireTime
else
strAesSource = m_strPassword .. "&" .. nExpireTime .. "&" .. m_strDeviceAuthorizationCode
end
--加密内容: mqtt密码 & expireTime & 授权码(可选)
--加密模式CBC填充方式Pkcs5Padding密钥1234567890123456密钥长度128 bit偏移量1234567890666666
encodeStr = crypto.aes_encrypt("CBC","PKCS5",strAesSource,m_strProductPassword,"wumei-smart-open")
log.info("AesPassword strAesSource" .. strAesSource .. " encodeStr " .. encodeStr )
encodeStr = crypto.base64_encode(encodeStr,slen(encodeStr))
log.info("AesPassword strAesSource" .. strAesSource .. " encodeStrbase64 " .. encodeStr )
return encodeStr
end
--- mqtt认证初始化
-- @string strEncryptionMode,string类型,认证类型S=简单认证E=加密认证
-- @string strProductId,string类型物美里面定义的产品ID
-- @string strDeviceId,string类型设备ID 一般用imei
-- @string strUserId,string类型用户ID
-- @string strUser,string类型用户
-- @string strPassword,string类型密码
-- @number nTimeout,number类型延迟秒为单位
-- @string strIp,string类型Ip
-- @string strDeviceAuthorizationCode,string类型 设备认证码 不用不填
-- @string strProductPassword,string类型 产品密码
-- @return nil
function Init(strEncryptionMode,strProductId,strDeviceId,strUserId,strUser,strPassword,nTimeout,strIp,strDeviceAuthorizationCode,strProductPassword,callback)
m_strEncryptionMode = strEncryptionMode
m_strProductId = strProductId
m_strDeviceId = strDeviceId
m_strUserId = strUserId
m_strUser = strUser
m_strPassword = strPassword
m_nTimeout = nTimeout
m_strIp = strIp
if nil == strDeviceAuthorizationCode then
m_strDeviceAuthorizationCode = strDeviceAuthorizationCode
end
if nil == strProductPassword then
m_strProductPassword = strProductPassword
end
m_nTimeSyncFlag = 0
m_InitCallback = callback
--if ParameterCheck() == false then
-- Callback(0)
-- end
SyncTime()
end
function GetUser()
return m_strUser
end
function GetPassword()
return m_strOutPassword
end
function GetClientId()
return m_strClientId
end
function GetIP()
return m_strIp
end

View File

@@ -0,0 +1,289 @@
--- 模块功能物美MQTT交互
-- @author 杜兴杰
-- @module 物美MQTT通信
-- @license MIT
-- @copyright 杜兴杰
-- @email 1066950103@qq.com
-- @release 2022.8.5
module(..., package.seeall)
local m_strProductId
local m_strDeviceNum
local m_tMessageQueue = {}
local m_callbackPropertyData = nil
local m_callbackFunctionData = nil
local m_callbackEventData = nil
local m_callbackDeviceInformationData = nil
local m_timePropertyId = 0
local m_timeFunctionId = 0
local m_timeEventId = 0
local m_nMonitorCount = 0
local m_nMonitorTime = 0
local m_timeMonitorId = 0
local function GetSubscriberDeviceInformation()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/info/get"
end
local function GetSubscriberDeviceInOta()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/ota/get"
end
local function GetSubscriberDeviceProperty()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/property/get"
end
local function GetSubscriberDevicePropertyOnline()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/property-online/get"
end
local function GetSubscriberDeviceFunction()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/function/get"
end
local function GetSubscriberDeviceFunctionOnline()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/function-online/get"
end
local function GetSubscriberDeviceMonitor()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/monitor/get"
end
local function GetSubscriberDeviceNtp()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/ntp/get"
end
local function GetPublishDeviceInformation()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/info/post"
end
local function GetPublishDeviceProperty()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/property/post"
end
local function GetPublishDeviceFunction()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/function/post"
end
local function GetPublishDeviceEvent()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/event/post"
end
local function GetPublishDeviceNtp()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/ntp/post"
end
local function GetPublishMonitorProperty()
return "/" .. m_strProductId .. "/" .. m_strDeviceNum .. "/monitor/post"
end
local function PropertyPush()
if m_callbackPropertyData ~= nil then
local strTopic = GetPublishDeviceProperty()
local strMessage = m_callbackPropertyData()
local nQos = 1
table.insert(m_tMessageQueue,{topic=strTopic,payload=strMessage,qosr=nQos})
log.info("------------------PropertyPush---------------")
end
end
local function FunctionPush()
if m_callbackFunctionData ~= nil then
local strTopic = GetPublishDeviceFunction()
local strMessage = m_callbackFunctionData()
local nQos = 1
table.insert(m_tMessageQueue,{topic=strTopic,payload=strMessage,qosr=nQos})
log.info("------------------FunctionPush---------------")
end
end
local function EventPush()
if m_callbackEventData ~= nil then
local strTopic = GetPublishDeviceEvent()
local strMessage = m_callbackEventData()
local nQos = 1
table.insert(m_tMessageQueue,{topic=strTopic,payload=strMessage,qosr=nQos})
log.info("------------------EventPush---------------")
end
end
local function MonitorPush()
if m_callbackPropertyData ~= nil then
local strTopic = GetPublishMonitorProperty()
local strMessage = m_callbackPropertyData()
local nQos = 1
table.insert(m_tMessageQueue,{topic=strTopic,payload=strMessage,qosr=nQos})
log.info("------------------MonitorPush---------------")
end
end
local function DeviceMonitorTimeCallback()
MonitorPush()
if m_nMonitorCount ~= 0 then
m_nMonitorCount = m_nMonitorCount -1
m_timeMonitorId = sys.timerStart(
DeviceMonitorTimeCallback
,m_nMonitorTime)
else
sys.timerStop(m_timeMonitorId)
m_timeMonitorId= 0
end
log.info("----m_nMonitorCount=" .. m_nMonitorCount)
end
local function DeviceInformationPush()
if m_callbackDeviceInformationData ~= nil then
local strTopic = GetPublishDeviceInformation()
local strMessage = m_callbackDeviceInformationData()
local nQos = 1
table.insert(m_tMessageQueue,{topic=strTopic,payload=strMessage,qosr=nQos})
end
end
--- mqtt交互初始化
-- @string strProductId,string类型,产品ID
-- @string strDeviceNum,string类型设备号 IMEI
-- @return nil
function Init(strProductId,strDeviceNum)
m_strProductId = strProductId
m_strDeviceNum = strDeviceNum
end
--- mqtt交互延时初始化
-- @return nil
function DelayInit()
DeviceInformationPush();
end
--- mqtt 获取待发送数据 一次取出一天且删除
-- @return bResult false 没有数据 true 有数据
-- @return strMessage 要发送的数据
-- @return strTopic 要发送的主题
-- @return nQos 发送消息级别
function GetData()
local bResult = false
local strMessage =""
local strTopic =""
local nQos = 0
if #m_tMessageQueue>0 then
local outMsg = table.remove(m_tMessageQueue,1)
bResult = true
strMessage = outMsg.payload
strTopic = outMsg.topic
nQos = outMsg.qosr
end
return bResult,strMessage,strTopic,nQos
end
--- mqtt 设置属性的获取获取函数,内部调用发送的时候会执行这个函数 这个函数外部实现
-- @function callback,函数类型, 数据函
function SetCallbackPropertyData(callback)
m_callbackPropertyData = callback
end
--- mqtt 设置功能的获取获取函数,内部调用发送的时候会执行这个函数 这个函数外部实现
-- @function callback,函数类型, 数据函
function SetCallbackFunctionData(callback)
m_callbackFunctionData = callback
end
--- mqtt 设置事件的获取获取函数,内部调用发送的时候会执行这个函数 这个函数外部实现
-- @function callback,函数类型, 数据函
function SetCallbackEventData(callback)
m_callbackEventData = callback
end
--- mqtt 设置设备信息获取函数,这个函数外部实现
-- @function callback,函数类型, 数据函
function SetCallbackInformationData(callback)
m_callbackDeviceInformationData = callback
end
--- mqtt 设置属性发布
-- @number nTime,数字类型, 0停止定时器 其他值开启定时器
function SetPropertyPush(nTime)
if m_timePropertyId ~= 0 then
sys.timerStop(m_timePropertyId)
m_timePropertyId = 0
end
if nTime~= 0 then
m_timePropertyId = sys.timerLoopStart(PropertyPush,nTime)
end
end
--- mqtt 设置功能发布
-- @number nTime,数字类型, 0停止定时器 其他值开启定时器
function SetFunctionPush(nTime)
if m_timeFunctionId ~= 0 then
sys.timerStop(m_timeFunctionId)
m_timeFunctionId = 0
end
if nTime~= 0 then
m_timeFunctionId = sys.timerLoopStart(FunctionPush,nTime)
end
end
--- mqtt 设置事件发布
-- @number nTime,数字类型, 0停止定时器 其他值开启定时器
function SetEventPush(nTime)
if m_timeEventId ~= 0 then
sys.timerStop(m_timeEventId)
m_timeEventId = 0
end
if nTime~= 0 then
m_timeEventId = sys.timerLoopStart(EventPush,nTime)
end
end
--- mqtt 获取要订阅的所有主题
-- @return tSubscriber,表类型, topic 主题 qos级别
function GetSubscriberAll()
local tSubscriber ={}
table.insert(tSubscriber,{topic=GetSubscriberDeviceInformation(),qos=1})
table.insert(tSubscriber,{topic=GetSubscriberDeviceProperty(),qos=1})
table.insert(tSubscriber,{topic=GetSubscriberDevicePropertyOnline(),qos=1})
table.insert(tSubscriber,{topic=GetSubscriberDeviceFunction(),qos=1})
table.insert(tSubscriber,{topic=GetSubscriberDeviceFunctionOnline(),qos=1})
table.insert(tSubscriber,{topic=GetSubscriberDeviceMonitor(),qos=1})
table.insert(tSubscriber,{topic=GetSubscriberDeviceNtp(),qos=1})
return tSubscriber
end
--- mqtt接受数据
-- @string topic,string类型,接收到的主题
-- @string message,string类型消息内容
-- @return nil
function OnRecvData(topic , message)
if topic == GetSubscriberDeviceInformation() then
DeviceInformationPush();
elseif topic == GetSubscriberDeviceInOta() then
local jsonObj = json.decode(message)
local strVersion = jsonObj["version"]
local strUrl = jsonObj["downloadUrl"]
elseif topic == GetSubscriberDeviceProperty() then
PropertyPush();
elseif topic == GetSubscriberDevicePropertyOnline() then
PropertyPush();
elseif topic == GetSubscriberDeviceFunction() then
FunctionPush();
elseif topic == GetSubscriberDeviceFunctionOnline() then
FunctionPush();
elseif topic == GetSubscriberDeviceMonitor() then
local jsonObj = json.decode(message)
m_nMonitorCount = jsonObj["count"]
m_nMonitorTime = jsonObj["interval"]
if m_timeMonitorId ~= 0 then
sys.timerStop(m_timeMonitorId)
m_timeMonitorId = 0
end
m_timeMonitorId = sys.timerStart(
DeviceMonitorTimeCallback
,m_nMonitorTime)
elseif topic == GetSubscriberDeviceNtp() then
log.info("--DeviceNtp---" .. message)
end
end

133
sdk/合宙/WuMeiTest.lua Normal file
View File

@@ -0,0 +1,133 @@
--- 模块功能物美MQTT测试
-- @author 杜兴杰
-- @module 物美MQTT通信测试
-- @license MIT
-- @copyright 杜兴杰
-- @email 1066950103@qq.com
-- @release 2022.8.5
module(..., package.seeall)
require"WeiMeiComAuth"
require"WeiMeiComInteraction"
require"WeiMeiApp"
require"misc"
require"mqtt"
local ready = false
--物美配置参数相关配置
local m_strEncryptionMode = "S"
local m_strProductId = 220
local m_strDeviceId = nil
local m_strUserId = "1" -- admin
local m_strMqttUser = "wumei-smart"
local m_strMqttPassword = "PVMXS6V46205CAQ5"
local m_strProductPassword = "KC3169JOU816X5C0" --产品密码
local m_nMqttAuthenticationTimeout = 24*60*60*1000 --24小时
local m_strMqttIp = "wumei.live"
local m_strDeviceAuthorizationCode = "A25040D2E34B483DA371B5F9A315BB43" --设备授权码
local m_mqttClient = nil
local m_mqttFlag = 0
function AuthenticationResultCallback(nResult)
if nResult == 1 then
log.info("---AuthenticationResultCallback---ok")
WeiMeiComInteraction.Init(m_strProductId,m_strDeviceId)
m_mqttFlag = 1
end
end
local function MqttInit()
WeiMeiComAuth.Init(m_strEncryptionMode,m_strProductId,m_strDeviceId,m_strUserId,m_strMqttUser,m_strMqttPassword,m_nMqttAuthenticationTimeout,m_strMqttIp,m_strDeviceAuthorizationCode,m_strProductPassword,AuthenticationResultCallback)
end
-- 订阅所有主题
local function GetSubscriberAll()
local tSubscriber = WeiMeiComInteraction.GetSubscriberAll()
while #tSubscriber > 0 do
local ouSubscriber = table.remove(tSubscriber,1)
if m_mqttClient:subscribe({[ouSubscriber.topic]=ouSubscriber.qos}) == nil then
log.info("subscribe eeror ")
return false
end
end
return true
end
--- MQTT连接是否处于激活状态
-- @return 激活状态返回true非激活状态返回false
-- @usage mqttTask.isReady()
function isReady()
return ready
end
--启动MQTT客户端任务
sys.taskInit(
function()
local retryConnectCnt = 0
while true do
if not socket.isReady() then
retryConnectCnt = 0
--等待网络环境准备就绪超时时间是5分钟
sys.waitUntil("IP_READY_IND",300000)
end
if socket.isReady() then
m_strDeviceId = misc.getImei()
MqttInit()
while m_mqttFlag == 0 do
sys.wait(50)
end
--创建一个MQTT客户端
log.info("ClientId=" .. WeiMeiComAuth.GetClientId() )
log.info("User=" .. WeiMeiComAuth.GetUser() )
log.info("Password=" .. WeiMeiComAuth.GetPassword() )
log.info("Ip=" .. WeiMeiComAuth.GetIP() )
m_mqttClient = mqtt.client(WeiMeiComAuth.GetClientId(),600,WeiMeiComAuth.GetUser(),WeiMeiComAuth.GetPassword())
if m_mqttClient:connect(WeiMeiComAuth.GetIP(),1883,"tcp") then
retryConnectCnt = 0
ready = true
--订阅主题
if GetSubscriberAll() == true then
WeiMeiComInteraction.SetCallbackInformationData(WeiMeiApp.InformationData)
WeiMeiComInteraction.SetCallbackPropertyData(WeiMeiApp.PropertyData)
WeiMeiComInteraction.SetPropertyPush(1000*30) --30秒钟定时上传一次属性
WeiMeiComInteraction.DelayInit()
--循环处理接收和发送的数据
while true do
local result,data = m_mqttClient:receive(300,"APP_SOCKET_SEND_DATA")
if result or data=="timeout" or data=="APP_SOCKET_SEND_DATA" then
if result then
log.info("data.topic" .. data.topic .. "data.payload" .. data.payload)
WeiMeiComInteraction.OnRecvData(data.topic,data.payload);
end
else
break -- 出错了
end
result,strMessage,strTopic,nQos = WeiMeiComInteraction.GetData()
if result == true then
local mqttResult = m_mqttClient:publish(strTopic,strMessage,nQos)
if not mqttResult then
break
end
end
end
end
ready = false
else
retryConnectCnt = retryConnectCnt+1
end
--断开MQTT连接
m_mqttClient:disconnect()
if retryConnectCnt>=5 then link.shut() retryConnectCnt=0 end
sys.wait(5000)
else
--进入飞行模式20秒之后退出飞行模式
net.switchFly(true)
sys.wait(20000)
net.switchFly(false)
end
end
end
)

65
sdk/合宙/main.lua Normal file
View File

@@ -0,0 +1,65 @@
--必须在这个位置定义PROJECT和VERSION变量
--PROJECTascii string类型可以随便定义只要不使用,就行
--VERSIONascii string类型如果使用Luat物联云平台固件升级的功能必须按照"X.X.X"定义X表示1位数字否则可随便定义
PROJECT = "DTU"
VERSION = "1.0.0"
--加载日志功能模块,并且设置日志输出等级
--如果关闭调用log模块接口输出的日志等级设置为log.LOG_SILENT即可
require "log"
LOG_LEVEL = log.LOGLEVEL_TRACE
--[[
如果使用UART输出日志打开这行注释的代码"--log.openTrace(true,1,115200)"即可,根据自己的需求修改此接口的参数
如果要彻底关闭脚本中的输出日志包括调用log模块接口和Lua标准print接口输出的日志执行log.openTrace(false,第二个参数跟调用openTrace接口打开日志的第二个参数相同),例如:
1、没有调用过sys.opntrace配置日志输出端口或者最后一次是调用log.openTrace(true,nil,921600)配置日志输出端口此时要关闭输出日志直接调用log.openTrace(false)即可
2、最后一次是调用log.openTrace(true,1,115200)配置日志输出端口此时要关闭输出日志直接调用log.openTrace(false,1)即可
--]]
--log.openTrace(true,1,115200)
require "sys"
require "net"
--每1分钟查询一次GSM信号强度
--每1分钟查询一次基站信息
net.startQueryAll(60000, 60000)
--此处关闭RNDIS网卡功能
--否则模块通过USB连接电脑后会在电脑的网络适配器中枚举一个RNDIS网卡电脑默认使用此网卡上网导致模块使用的sim卡流量流失
--如果项目中需要打开此功能把ril.request("AT+RNDISCALL=0,1")修改为ril.request("AT+RNDISCALL=1,1")即可
--注意core固件V0030以及之后的版本、V3028以及之后的版本才以稳定地支持此功能
ril.request("AT+RNDISCALL=1,1")
--加载控制台调试功能模块此处代码配置的是uart2波特率115200
--此功能模块不是必须的,根据项目需求决定是否加载
--使用时注意控制台使用的uart不要和其他功能使用的uart冲突
--使用说明参考demo/console下的《console功能使用说明.docx》
--require "console"
--console.setup(2, 115200)
--加载网络指示灯和LTE指示灯功能模块
--根据自己的项目需求和硬件配置决定1、是否加载此功能模块2、配置指示灯引脚
--合宙官方出售的Air720U开发板上的网络指示灯引脚为pio.P0_1LTE指示灯引脚为pio.P0_4
require "netLed"
pmd.ldoset(2,pmd.LDO_VLCD)
netLed.setup(true,pio.P0_1,pio.P0_4)
--网络指示灯功能模块中默认配置了各种工作状态下指示灯的闪烁规律参考netLed.lua中ledBlinkTime配置的默认值
--如果默认值满足不了需求此处调用netLed.updateBlinkTime去配置闪烁时长
--LTE指示灯功能模块中配置的是注册上4G网络灯就常亮其余任何状态灯都会熄灭
--加载错误日志管理功能模块【强烈建议打开此功能】
--如下2行代码只是简单的演示如何使用errDump功能详情参考errDump的api
require "errDump"
errDump.request("udp://dev_msg1.openluat.com:12425", nil, true)
--加载远程升级功能模块【强烈建议打开此功能如果使用了阿里云的OTA功能可以不打开此功能】
--如下3行代码只是简单的演示如何使用update功能详情参考update的api以及demo/update
PRODUCT_KEY = "7wazHLKGOdfjrSoG5tXOr4uUg7D5wT9k"
--require "update"
--update.request()
--加载MQTT功能测试模块
require "WuMeiTest"
--启动系统框架
sys.init(0, 0)
sys.run()

65
sdk/合宙/mainAir724.lua Normal file
View File

@@ -0,0 +1,65 @@
--必须在这个位置定义PROJECT和VERSION变量
--PROJECTascii string类型可以随便定义只要不使用,就行
--VERSIONascii string类型如果使用Luat物联云平台固件升级的功能必须按照"X.X.X"定义X表示1位数字否则可随便定义
PROJECT = "DTU"
VERSION = "1.0.0"
--加载日志功能模块,并且设置日志输出等级
--如果关闭调用log模块接口输出的日志等级设置为log.LOG_SILENT即可
require "log"
LOG_LEVEL = log.LOGLEVEL_TRACE
--[[
如果使用UART输出日志打开这行注释的代码"--log.openTrace(true,1,115200)"即可,根据自己的需求修改此接口的参数
如果要彻底关闭脚本中的输出日志包括调用log模块接口和Lua标准print接口输出的日志执行log.openTrace(false,第二个参数跟调用openTrace接口打开日志的第二个参数相同),例如:
1、没有调用过sys.opntrace配置日志输出端口或者最后一次是调用log.openTrace(true,nil,921600)配置日志输出端口此时要关闭输出日志直接调用log.openTrace(false)即可
2、最后一次是调用log.openTrace(true,1,115200)配置日志输出端口此时要关闭输出日志直接调用log.openTrace(false,1)即可
--]]
--log.openTrace(true,1,115200)
require "sys"
require "net"
--每1分钟查询一次GSM信号强度
--每1分钟查询一次基站信息
net.startQueryAll(60000, 60000)
--此处关闭RNDIS网卡功能
--否则模块通过USB连接电脑后会在电脑的网络适配器中枚举一个RNDIS网卡电脑默认使用此网卡上网导致模块使用的sim卡流量流失
--如果项目中需要打开此功能把ril.request("AT+RNDISCALL=0,1")修改为ril.request("AT+RNDISCALL=1,1")即可
--注意core固件V0030以及之后的版本、V3028以及之后的版本才以稳定地支持此功能
ril.request("AT+RNDISCALL=1,1")
--加载控制台调试功能模块此处代码配置的是uart2波特率115200
--此功能模块不是必须的,根据项目需求决定是否加载
--使用时注意控制台使用的uart不要和其他功能使用的uart冲突
--使用说明参考demo/console下的《console功能使用说明.docx》
--require "console"
--console.setup(2, 115200)
--加载网络指示灯和LTE指示灯功能模块
--根据自己的项目需求和硬件配置决定1、是否加载此功能模块2、配置指示灯引脚
--合宙官方出售的Air720U开发板上的网络指示灯引脚为pio.P0_1LTE指示灯引脚为pio.P0_4
require "netLed"
pmd.ldoset(2,pmd.LDO_VLCD)
netLed.setup(true,pio.P0_1,pio.P0_4)
--网络指示灯功能模块中默认配置了各种工作状态下指示灯的闪烁规律参考netLed.lua中ledBlinkTime配置的默认值
--如果默认值满足不了需求此处调用netLed.updateBlinkTime去配置闪烁时长
--LTE指示灯功能模块中配置的是注册上4G网络灯就常亮其余任何状态灯都会熄灭
--加载错误日志管理功能模块【强烈建议打开此功能】
--如下2行代码只是简单的演示如何使用errDump功能详情参考errDump的api
require "errDump"
errDump.request("udp://dev_msg1.openluat.com:12425", nil, true)
--加载远程升级功能模块【强烈建议打开此功能如果使用了阿里云的OTA功能可以不打开此功能】
--如下3行代码只是简单的演示如何使用update功能详情参考update的api以及demo/update
PRODUCT_KEY = "7wazHLKGOdfjrSoG5tXOr4uUg7D5wT9k"
--require "update"
--update.request()
--加载MQTT功能测试模块
require "WuMeiTest"
--启动系统框架
sys.init(0, 0)
sys.run()

10
sdk/合宙/mainVscode.lua Normal file
View File

@@ -0,0 +1,10 @@
PROJECT = 'test'
VERSION = '2.0.0'
require 'log'
LOG_LEVEL = log.LOGLEVEL_TRACE
require 'sys'
require "WuMeiTest"
sys.init(0, 0)
sys.run()