123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- module(...,package.seeall)
- require"http"
- require"nvm"
- require "funlib"
- local rfidType = nvm.get("rfidType")
- local devId = nvm.get("devId")
- local devSn = nvm.get("devSn")
- local moduleImei = nvm.get("moduleImei")
- local httpDevopsUrl = nvm.get("httpDevopsUrl")
- local httpDevopsInterval = nvm.get("httpDevopsInterval")
- local isHttpRequesting = false
- --920设备状态 0:offline 1:online
- local g91State = 0
- local function cbFnc(result,prompt,head,body)
- isHttpRequesting = false
- log.info("httpTask.cbFnc","result:",result,"prompt:",prompt)
- --[[
- if result and head then
- for k,v in pairs(head) do
- log.info("httpTask.cbFnc",k..": "..v)
- end
- end
- ]]
- if result and body then
- log.info("httpTask.cbFnc","bodyLen="..body:len(), body)
- local res_config = json.decode(body)
- if not res_config then
- log.error("httpTask.cbFnc","json decode error!")
- return false
- end
- if not res_config.success then
- log.error("httpTask.cbFnc",res_config.message)
- return false
- end
- if not res_config.data then
- log.error("httpTask.cbFnc","res_config.data empty!")
- return false
- end
- if res_config.data.deviceId ~= devId then
- log.error("httpTask.cbFnc","res_config.data.deviceId ~= devId!")
- return false
- end
- local isReboot = false
- if res_config.data.httpDevopsUrl ~= "" and res_config.data.httpDevopsUrl ~= nvm.get("httpDevopsUrl") then
- if not nvm.set("httpDevopsUrl", res_config.data.httpDevopsUrl) then
- log.error("httpTask.cbFnc","nvm set httpDevopsUrl failed!")
- return false
- end
- isReboot = true
- end
- if res_config.data.errorLogReportUrl ~= "" and res_config.data.errorLogReportUrl ~= nvm.get("errorLogReportUrl") then
- if not nvm.set("errorLogReportUrl", res_config.data.errorLogReportUrl) then
- log.error("httpTask.cbFnc","nvm set errorLogReportUrl failed!")
- return false
- end
- isReboot = true
- end
- local _errorLogReportInterval = tonumber(res_config.data.errorLogReportInterval)
- if type(_errorLogReportInterval) == "number" and _errorLogReportInterval >= 30 and _errorLogReportInterval ~= nvm.get("errorLogReportInterval") then
- if not nvm.set("errorLogReportInterval", _errorLogReportInterval) then
- log.error("httpTask.cbFnc","nvm set errorLogReportInterval failed!")
- return false
- end
- isReboot = true
- end
- local _httpDevopsInterval = tonumber(res_config.data.httpDevopsInterval)
- if type(_httpDevopsInterval) == "number" and _httpDevopsInterval >= 30 and _httpDevopsInterval ~= nvm.get("httpDevopsInterval") then
- if not nvm.set("httpDevopsInterval", _httpDevopsInterval) then
- log.error("httpTask.cbFnc","nvm set httpDevopsInterval failed!")
- return false
- end
- isReboot = true
- end
- local _httpEnableParamsReport = tonumber(res_config.data.httpEnableParamsReport)
- if type(_httpEnableParamsReport) == "number" and _httpEnableParamsReport ~= nvm.get("httpEnableParamsReport") then
- if not nvm.set("httpEnableParamsReport", _httpEnableParamsReport) then
- log.error("httpTask.cbFnc","nvm set httpEnableParamsReport failed!")
- return false
- end
- isReboot = true
- end
- local _devRebootTime = res_config.data.devRebootTime
- if _devRebootTime ~= "" and _devRebootTime ~= nvm.get("devRebootTime") then
- if not string.find(_devRebootTime, "(%d%d:%d%d:%d%d)") then
- log.error("httpTask.cbFnc","devRebootTime format error!",_devRebootTime)
- else
- if not nvm.set("devRebootTime", _devRebootTime) then
- log.error("httpTask.cbFnc","nvm set devRebootTime failed!")
- return false
- end
- isReboot = true
- end
- end
- local _isRebootDevice = tonumber(res_config.data.isRebootDevice)
- if _isRebootDevice == 1 then
- log.info("httpTask.cbFnc","receive device reboot command")
- isReboot = true
- end
-
- local _isRestoreDevice = tonumber(res_config.data.isRestoreDevice)
- if _isRestoreDevice == 1 then
- log.info("httpTask.cbFnc","receive device restore command")
- nvm.restore()
- isReboot = true
- end
- local _isStartOta = tonumber(res_config.data.isStartOta)
- if _isStartOta == 1 then
- log.info("httpTask.cbFnc","receive device start ota command, publish message: device_command_ota_start")
- sys.publish("device_command_ota_start")
- return
- end
- local _otaCheckInterval = tonumber(res_config.data.otaCheckInterval)
- if type(_otaCheckInterval) == "number" and _otaCheckInterval >= 30 and _otaCheckInterval ~= nvm.get("otaCheckInterval") then
- if not nvm.set("otaCheckInterval", _otaCheckInterval) then
- log.error("httpTask.cbFnc","nvm set otaCheckInterval failed!")
- return false
- end
- isReboot = true
- end
-
- local _rfidRssiFilterVal = tonumber(res_config.data.rfidRssiFilterVal)
- if type(_rfidRssiFilterVal) == "number" and _rfidRssiFilterVal > 0 and _rfidRssiFilterVal ~= nvm.get("rfidRssiFilterVal") then
- if not nvm.set("rfidRssiFilterVal", _rfidRssiFilterVal) then
- log.error("httpTask.cbFnc","nvm set rfidRssiFilterVal failed!")
- return false
- end
- isReboot = true
- end
-
- local enableUploadRfid24 = tonumber(res_config.data.enableUploadRfid24)
- if type(enableUploadRfid24) == "number" and (enableUploadRfid24 == 0 or enableUploadRfid24 == 1) and enableUploadRfid24 ~= nvm.get("enableUploadRfid24") then
- if not nvm.set("enableUploadRfid24", enableUploadRfid24) then
- log.error("httpTask.cbFnc","nvm set enableUploadRfid24 failed!")
- return false
- end
- isReboot = true
- end
- if rfidType == "tiandiren" then
- if res_config.data.ddzxIp ~= "" and res_config.data.ddzxIp ~= nvm.get("ddzxIp") then
- if not nvm.set("ddzxIp", res_config.data.ddzxIp) then
- log.error("httpTask.cbFnc","nvm set ddzxIp failed!")
- return false
- end
- isReboot = true
- end
- local _ddzxTcpPort = res_config.data.ddzxTcpPort
- if _ddzxTcpPort ~= "" and _ddzxTcpPort ~= nvm.get("ddzxTcpPort") then
- if not nvm.set("ddzxTcpPort", _ddzxTcpPort) then
- log.error("httpTask.cbFnc","nvm set ddzxTcpPort failed!")
- return false
- end
- isReboot = true
- end
- local _ddzxWaitRecvMsgMaxTime = tonumber(res_config.data.ddzxWaitRecvMsgMaxTime)
- if type(_ddzxWaitRecvMsgMaxTime) == "number" and _ddzxWaitRecvMsgMaxTime > 0 and _ddzxWaitRecvMsgMaxTime ~= nvm.get("ddzxWaitRecvMsgMaxTime") then
- if not nvm.set("ddzxWaitRecvMsgMaxTime", _ddzxWaitRecvMsgMaxTime) then
- log.error("httpTask.cbFnc","nvm set ddzxWaitRecvMsgMaxTime failed!")
- return false
- end
- isReboot = true
- end
- local _rfidOfflineTimeout = tonumber(res_config.data.rfidOfflineTimeout)
- if type(_rfidOfflineTimeout) == "number" and _rfidOfflineTimeout > 0 and _rfidOfflineTimeout ~= nvm.get("rfidOfflineTimeout") then
- if not nvm.set("rfidOfflineTimeout", _rfidOfflineTimeout) then
- log.error("httpTask.cbFnc","nvm set rfidOfflineTimeout failed!")
- return false
- end
- isReboot = true
- end
-
- local _rfidMinDiffTime = tonumber(res_config.data.rfidMinDiffTime)
- if type(_rfidMinDiffTime) == "number" and _rfidMinDiffTime > 0 and _rfidMinDiffTime ~= nvm.get("rfidMinDiffTime") then
- if not nvm.set("rfidMinDiffTime", _rfidMinDiffTime) then
- log.error("httpTask.cbFnc","nvm set rfidMinDiffTime failed!")
- return false
- end
- isReboot = true
- end
- local _enableFilterTdrRfid = tonumber(res_config.data.enableFilterTdrRfid)
- if type(_enableFilterTdrRfid) == "number" and (_enableFilterTdrRfid == 0 or _enableFilterTdrRfid == 1) and _enableFilterTdrRfid ~= nvm.get("enableFilterTdrRfid") then
- if not nvm.set("enableFilterTdrRfid", _enableFilterTdrRfid) then
- log.error("httpTask.cbFnc","nvm set enableFilterTdrRfid failed!")
- return false
- end
- isReboot = true
- end
- local _onlyDevTypeVal = res_config.data.onlyDevTypeVal
- if _onlyDevTypeVal ~= nvm.get("onlyDevTypeVal") then
- if not nvm.set("onlyDevTypeVal", _onlyDevTypeVal) then
- log.error("httpTask.cbFnc","nvm set onlyDevTypeVal failed!")
- return false
- end
- isReboot = true
- end
-
- local _msgQueueMaxLen = tonumber(res_config.data.msgQueueMaxLen)
- if type(_msgQueueMaxLen) == "number" and _msgQueueMaxLen > 0 and _msgQueueMaxLen ~= nvm.get("msgQueueMaxLen") then
- if not nvm.set("msgQueueMaxLen", _msgQueueMaxLen) then
- log.error("httpTask.cbFnc","nvm set msgQueueMaxLen failed!")
- return false
- end
- isReboot = true
- end
- elseif rfidType == "renlian" then
- if (res_config.data.enableHeartbeat == 0 or res_config.data.enableHeartbeat == 1) and res_config.data.enableHeartbeat ~= nvm.get("enableHeartbeat") then
- if not nvm.set("enableHeartbeat", res_config.data.enableHeartbeat) then
- log.error("httpTask.cbFnc","nvm set enableHeartbeat failed!")
- return false
- end
- isReboot = true
- end
- if funlib.ipFormatVerify(res_config.data.heartbeatIp) and res_config.data.heartbeatIp ~= nvm.get("heartbeatIp") then
- if not nvm.set("heartbeatIp", res_config.data.heartbeatIp) then
- log.error("httpTask.cbFnc","nvm set heartbeatIp failed!")
- return false
- end
- isReboot = true
- end
-
- local heartbeatTcpPort = res_config.data.heartbeatTcpPort or ""
- if heartbeatTcpPort ~= "" and heartbeatTcpPort ~= nvm.get("heartbeatTcpPort") then
- if not nvm.set("heartbeatTcpPort", heartbeatTcpPort) then
- log.error("httpTask.cbFnc","nvm set heartbeatTcpPort failed!")
- return false
- end
- isReboot = true
- end
-
- local heartbeatInterval = res_config.data.heartbeatInterval or 0
- if heartbeatInterval >= 10 and heartbeatInterval ~= nvm.get("heartbeatInterval") then
- if not nvm.set("heartbeatInterval", heartbeatInterval) then
- log.error("httpTask.cbFnc","nvm set heartbeatInterval failed!")
- return false
- end
- isReboot = true
- end
- if res_config.data.dataIp ~= "" and res_config.data.dataIp ~= nvm.get("dataIp") then
- if not nvm.set("dataIp", res_config.data.dataIp) then
- log.error("httpTask.cbFnc","nvm set dataIp failed!")
- return false
- end
- isReboot = true
- end
-
- local _dataTcpPort = res_config.data.dataTcpPort
- if _dataTcpPort ~= "" and _dataTcpPort ~= nvm.get("dataTcpPort") then
- if not nvm.set("dataTcpPort", _dataTcpPort) then
- log.error("httpTask.cbFnc","nvm set dataTcpPort failed!")
- return false
- end
- isReboot = true
- end
-
- local _dataUdpPort = res_config.data.dataUdpPort
- if _dataUdpPort ~= "" and _dataUdpPort ~= nvm.get("dataUdpPort") then
- if not nvm.set("dataUdpPort", _dataUdpPort) then
- log.error("httpTask.cbFnc","nvm set dataUdpPort failed!")
- return false
- end
- isReboot = true
- end
- local _rfidEnableThrottleRlian = tonumber(res_config.data.rfidEnableThrottleRlian)
- if _rfidEnableThrottleRlian >=0 and _rfidEnableThrottleRlian ~= nvm.get("rfidEnableThrottleRlian") then
- if not nvm.set("rfidEnableThrottleRlian", _rfidEnableThrottleRlian) then
- log.error("httpTask.cbFnc","nvm set rfidEnableThrottleRlian failed!")
- return false
- end
- isReboot = true
- end
- local _rfidReportIntervalRlian = tonumber(res_config.data.rfidReportIntervalRlian)
- if type(_rfidReportIntervalRlian) == "number" and _rfidReportIntervalRlian >0 and _rfidReportIntervalRlian ~= nvm.get("rfidReportIntervalRlian") then
- if not nvm.set("rfidReportIntervalRlian", _rfidReportIntervalRlian) then
- log.error("httpTask.cbFnc","nvm set rfidReportIntervalRlian failed!")
- return false
- end
- isReboot = true
- end
- local _rfidBufferMaxCountRlian = tonumber(res_config.data.rfidBufferMaxCountRlian)
- if type(_rfidBufferMaxCountRlian) == "number" and _rfidBufferMaxCountRlian >0 and _rfidBufferMaxCountRlian ~= nvm.get("rfidBufferMaxCountRlian") then
- if not nvm.set("rfidBufferMaxCountRlian", _rfidBufferMaxCountRlian) then
- log.error("httpTask.cbFnc","nvm set rfidBufferMaxCountRlian failed!")
- return false
- end
- isReboot = true
- end
- local _rfidOfflineTimeoutRlian = tonumber(res_config.data.rfidOfflineTimeoutRlian)
- if type(_rfidOfflineTimeoutRlian) == "number" and _rfidOfflineTimeoutRlian >0 and _rfidOfflineTimeoutRlian ~= nvm.get("rfidOfflineTimeoutRlian") then
- if not nvm.set("rfidOfflineTimeoutRlian", _rfidOfflineTimeoutRlian) then
- log.error("httpTask.cbFnc","nvm set rfidOfflineTimeoutRlian failed!")
- return false
- end
- isReboot = true
- end
- elseif rfidType == "dahua" then
- if res_config.data.ddzxIpDahua ~= "" and res_config.data.ddzxIpDahua ~= nvm.get("ddzxIpDahua") then
- if not nvm.set("ddzxIpDahua", res_config.data.ddzxIpDahua) then
- log.error("httpTask.cbFnc","nvm set ddzxIpDahua failed!")
- return false
- end
- isReboot = true
- end
- local _ddzxTcpPortDahua = res_config.data.ddzxTcpPortDahua
- if _ddzxTcpPortDahua ~= "" and _ddzxTcpPortDahua ~= nvm.get("ddzxTcpPortDahua") then
- if not nvm.set("ddzxTcpPortDahua", _ddzxTcpPortDahua) then
- log.error("httpTask.cbFnc","nvm set ddzxTcpPortDahua failed!")
- return false
- end
- isReboot = true
- end
- local _rfidBufferMaxCountDahua = tonumber(res_config.data.rfidBufferMaxCountDahua)
- if type(_rfidBufferMaxCountDahua) == "number" and _rfidBufferMaxCountDahua > 0 and _rfidBufferMaxCountDahua ~= nvm.get("rfidBufferMaxCountDahua") then
- if not nvm.set("rfidBufferMaxCountDahua", _rfidBufferMaxCountDahua) then
- log.error("httpTask.cbFnc","nvm set rfidBufferMaxCountDahua failed!")
- return false
- end
- isReboot = true
- end
- local _rfidReportIntervalDahua = tonumber(res_config.data.rfidReportIntervalDahua)
- if type(_rfidReportIntervalDahua) == "number" and _rfidReportIntervalDahua > 0 and _rfidReportIntervalDahua ~= nvm.get("rfidReportIntervalDahua") then
- if not nvm.set("rfidReportIntervalDahua", _rfidReportIntervalDahua) then
- log.error("httpTask.cbFnc","nvm set rfidReportIntervalDahua failed!")
- return false
- end
- isReboot = true
- end
- else
- log.error("httpTask.cbFnc","invalid rfidType!! rfidType:", rfidType)
- return false
- end
-
- if isReboot then
- log.info("httpTask.cbFnc","config updated, need reboot now ...")
- sys.restart("config.lua updated")
- return
- end
- end
- end
- local function http_heartbeat()
- local coreVersion = rtos.get_version() or ""
- local scriptVersion = _G.VERSION or ""
- local simIccid = nvm.get("simIccid") or ""
- local simImsi = nvm.get("simImsi") or ""
- local httpDevopsInterval = nvm.get("httpDevopsInterval") or ""
- local devRebootTime = nvm.get("devRebootTime") or ""
- local otaUrl = nvm.get("otaUrl") or ""
- local otaCheckInterval = nvm.get("otaCheckInterval") or ""
- local errorLogReportUrl = nvm.get("errorLogReportUrl") or ""
- local errorLogReportInterval = nvm.get("errorLogReportInterval") or ""
- local bootNum = nvm.get("bootNum") or ""
- local devModel = nvm.get("devModel") or ""
- local rfidRssiFilterVal = nvm.get("rfidRssiFilterVal") or ""
- local httpEnableParamsReport = nvm.get("httpEnableParamsReport") or 0
- local enableUploadRfid24 = nvm.get("enableUploadRfid24") or 1
- moduleImei = misc.getImei() or ""
- if not coreVersion then
- log.error("httpTask.http_heartbeat","coreVersion not existed!!")
- return false
- end
- if not scriptVersion then
- log.error("httpTask.http_heartbeat","scriptVersion not existed!!")
- return false
- end
- if not simIccid then
- log.error("httpTask.http_heartbeat","simIccid not existed!!")
- return false
- end
- if not simImsi then
- log.error("httpTask.http_heartbeat","simImsi not existed!!")
- return false
- end
- if not devId then
- log.error("httpTask.http_heartbeat","devId not existed!!")
- return false
- end
- if not devSn then
- log.error("httpTask.http_heartbeat","devSn not existed!!")
- return false
- end
- if not moduleImei then
- log.error("httpTask.http_heartbeat","moduleImei not existed!!")
- return false
- end
- if not httpDevopsUrl then
- log.error("httpTask.http_heartbeat","httpDevopsUrl not existed!!")
- return false
- end
- local ramUsed = _G.collectgarbage("count")
- local freeFlash = rtos.get_fs_free_size()
- local netRssi = net.getRssi()
- local reqUrl = ""
- if httpEnableParamsReport == 1 then
- reqUrl = httpDevopsUrl.."&deviceId="..devId.."&deviceImei="..moduleImei.."&deviceSn="..devSn.."&coreVersion="..coreVersion
- .."&scriptVersion="..scriptVersion.."&simIccid="..simIccid.."&simImsi="..simImsi
- .."&httpDevopsInterval="..httpDevopsInterval.."&devRebootTime="..devRebootTime
- .."&otaUrl="..otaUrl.."&otaCheckInterval="..otaCheckInterval.."&errorLogReportUrl="..errorLogReportUrl
- .."&errorLogReportInterval="..errorLogReportInterval.."&bootNum="..bootNum.."&devModel="..devModel
- .."&ramUsed="..ramUsed.."&freeFlash="..freeFlash.."&netRssi="..netRssi.."&rfidRssiFilterVal="..rfidRssiFilterVal
- .."&enableUploadRfid24="..enableUploadRfid24
- if rfidType == "tiandiren" then
- local ddzxIp = nvm.get("ddzxIp") or ""
- local ddzxTcpPort = nvm.get("ddzxTcpPort") or ""
- local ddzxWaitRecvMsgMaxTime = nvm.get("ddzxWaitRecvMsgMaxTime") or ""
- local rfidOfflineTimeout = nvm.get("rfidOfflineTimeout") or ""
- local rfidMinDiffTime = nvm.get("rfidMinDiffTime") or ""
- local msgQueueMaxLen = nvm.get("msgQueueMaxLen") or ""
- local enableFilterTdrRfid = nvm.get("enableFilterTdrRfid") or 1
- local onlyDevTypeVal = nvm.get("onlyDevTypeVal") or ""
- reqUrl = reqUrl.."&ddzxIp="..ddzxIp.."&ddzxTcpPort="..ddzxTcpPort.."&ddzxWaitRecvMsgMaxTime="..ddzxWaitRecvMsgMaxTime
- .."&rfidOfflineTimeout="..rfidOfflineTimeout.."&msgQueueMaxLen="..msgQueueMaxLen
- .."&rfidMinDiffTime="..rfidMinDiffTime.."&enableFilterTdrRfid="..enableFilterTdrRfid.."&onlyDevTypeVal="..onlyDevTypeVal
- elseif rfidType == "renlian" then
- local enableHeartbeat = nvm.get("enableHeartbeat") or 0
- local dataIp = nvm.get("dataIp") or ""
- local dataTcpPort = nvm.get("dataTcpPort") or ""
- local dataUdpPort = nvm.get("dataUdpPort") or ""
- local heartbeatIp = nvm.get("heartbeatIp") or ""
- local heartbeatTcpPort = nvm.get("heartbeatTcpPort") or ""
- local heartbeatUdpPort = nvm.get("heartbeatUdpPort") or ""
- local heartbeatInterval = nvm.get("heartbeatInterval") or 0
- local rfidReportIntervalRlian = nvm.get("rfidReportIntervalRlian") or ""
- local rfidBufferMaxCountRlian = nvm.get("rfidBufferMaxCountRlian") or ""
- local rfidEnableThrottleRlian = nvm.get("rfidEnableThrottleRlian")
- local rfidOfflineTimeoutRlian = nvm.get("rfidOfflineTimeoutRlian") or ""
- reqUrl = reqUrl.."&dataIp="..dataIp.."&dataTcpPort="..dataTcpPort.."&dataUdpPort="..dataUdpPort
- .."&rfidReportIntervalRlian="..rfidReportIntervalRlian.."&rfidBufferMaxCountRlian="..rfidBufferMaxCountRlian
- .."&rfidEnableThrottleRlian="..rfidEnableThrottleRlian.."&rfidOfflineTimeoutRlian="..rfidOfflineTimeoutRlian
- .."&g91State="..g91State.."&enableHeartbeat="..enableHeartbeat.."&heartbeatIp="..heartbeatIp.."&heartbeatTcpPort="..heartbeatTcpPort
- .."&heartbeatInterval="..heartbeatInterval
- elseif rfidType == "dahua" then
- local ddzxIpDahua = nvm.get("ddzxIpDahua") or ""
- local ddzxTcpPortDahua = nvm.get("ddzxTcpPortDahua") or ""
- local rfidBufferMaxCountDahua = nvm.get("rfidBufferMaxCountDahua") or ""
- local rfidReportIntervalDahua = nvm.get("rfidReportIntervalDahua") or ""
- reqUrl = reqUrl.."&ddzxIpDahua="..ddzxIpDahua.."&ddzxTcpPortDahua="..ddzxTcpPortDahua.."&rfidBufferMaxCountDahua="..rfidBufferMaxCountDahua
- .."&rfidReportIntervalDahua="..rfidReportIntervalDahua
- else
- log.error("httpTask.http_heartbeat","invalid rfidType!! rfidType:", rfidType)
- return false
- end
- else
- reqUrl = httpDevopsUrl.."&deviceId="..devId.."&deviceSn="..devSn.."&coreVersion="..coreVersion.."&scriptVersion="..scriptVersion.."&bootNum="..bootNum
- end
- log.info("httpTask.http_heartbeat", "reqUrl:", reqUrl, "start httpTask, httpDevopsInterval:", httpDevopsInterval)
- isHttpRequesting = true
- http.request("GET",reqUrl,nil,nil,nil,nil,cbFnc)
- end
- --[[
- --定时心跳任务
- sys.timerLoopStart(function()
- http_heartbeat()
- end, httpDevopsInterval *1000)
- ]]
- --定时心跳任务
- sys.taskInit(function()
- while true do
- if socket.isReady() then --连上网再开始运行
- log.info("httpTask","send http heartbeat ...")
- http_heartbeat() --等待一段时间发下次心跳
- log.info("httpTask","wait ", httpDevopsInterval, "s ...")
- sys.wait(httpDevopsInterval *1000)
- else --没连上网别忘了延时!不然会陷入while true死循环,导致模块无法运行其他代码
- log.info("httpTask","socket have not ready,wait 1s ...")
- sys.wait(1000) --等待1秒
- end
- end
-
- end)
- --920设备状态实时监测任务
- sys.taskInit(function()
- while true do
- local g91OfflineTime = nvm.get("g91OfflineTime") or 600
- if sys.waitUntil("receive_920_device_info", g91OfflineTime*1000) then
- log.info("httpTask.g91State","920 device online")
- g91State = 1
- else
- log.warn("httpTask.g91State","920 device offline!")
- g91State = 0
- end
- end
-
- end)
|