httpTask.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. module(...,package.seeall)
  2. require"http"
  3. require"nvm"
  4. require "funlib"
  5. local rfidType = nvm.get("rfidType")
  6. local devId = nvm.get("devId")
  7. local devSn = nvm.get("devSn")
  8. local moduleImei = nvm.get("moduleImei")
  9. local httpDevopsUrl = nvm.get("httpDevopsUrl")
  10. local httpDevopsInterval = nvm.get("httpDevopsInterval")
  11. local isHttpRequesting = false
  12. --920设备状态 0:offline 1:online
  13. local g91State = 0
  14. local function cbFnc(result,prompt,head,body)
  15. isHttpRequesting = false
  16. log.info("httpTask.cbFnc","result:",result,"prompt:",prompt)
  17. --[[
  18. if result and head then
  19. for k,v in pairs(head) do
  20. log.info("httpTask.cbFnc",k..": "..v)
  21. end
  22. end
  23. ]]
  24. if result and body then
  25. log.info("httpTask.cbFnc","bodyLen="..body:len(), body)
  26. local res_config = json.decode(body)
  27. if not res_config then
  28. log.error("httpTask.cbFnc","json decode error!")
  29. return false
  30. end
  31. if not res_config.success then
  32. log.error("httpTask.cbFnc",res_config.message)
  33. return false
  34. end
  35. if not res_config.data then
  36. log.error("httpTask.cbFnc","res_config.data empty!")
  37. return false
  38. end
  39. if res_config.data.deviceId ~= devId then
  40. log.error("httpTask.cbFnc","res_config.data.deviceId ~= devId!")
  41. return false
  42. end
  43. local isReboot = false
  44. if res_config.data.httpDevopsUrl ~= "" and res_config.data.httpDevopsUrl ~= nvm.get("httpDevopsUrl") then
  45. if not nvm.set("httpDevopsUrl", res_config.data.httpDevopsUrl) then
  46. log.error("httpTask.cbFnc","nvm set httpDevopsUrl failed!")
  47. return false
  48. end
  49. isReboot = true
  50. end
  51. if res_config.data.errorLogReportUrl ~= "" and res_config.data.errorLogReportUrl ~= nvm.get("errorLogReportUrl") then
  52. if not nvm.set("errorLogReportUrl", res_config.data.errorLogReportUrl) then
  53. log.error("httpTask.cbFnc","nvm set errorLogReportUrl failed!")
  54. return false
  55. end
  56. isReboot = true
  57. end
  58. local _errorLogReportInterval = tonumber(res_config.data.errorLogReportInterval)
  59. if type(_errorLogReportInterval) == "number" and _errorLogReportInterval >= 30 and _errorLogReportInterval ~= nvm.get("errorLogReportInterval") then
  60. if not nvm.set("errorLogReportInterval", _errorLogReportInterval) then
  61. log.error("httpTask.cbFnc","nvm set errorLogReportInterval failed!")
  62. return false
  63. end
  64. isReboot = true
  65. end
  66. local _httpDevopsInterval = tonumber(res_config.data.httpDevopsInterval)
  67. if type(_httpDevopsInterval) == "number" and _httpDevopsInterval >= 30 and _httpDevopsInterval ~= nvm.get("httpDevopsInterval") then
  68. if not nvm.set("httpDevopsInterval", _httpDevopsInterval) then
  69. log.error("httpTask.cbFnc","nvm set httpDevopsInterval failed!")
  70. return false
  71. end
  72. isReboot = true
  73. end
  74. local _httpEnableParamsReport = tonumber(res_config.data.httpEnableParamsReport)
  75. if type(_httpEnableParamsReport) == "number" and _httpEnableParamsReport ~= nvm.get("httpEnableParamsReport") then
  76. if not nvm.set("httpEnableParamsReport", _httpEnableParamsReport) then
  77. log.error("httpTask.cbFnc","nvm set httpEnableParamsReport failed!")
  78. return false
  79. end
  80. isReboot = true
  81. end
  82. local _devRebootTime = res_config.data.devRebootTime
  83. if _devRebootTime ~= "" and _devRebootTime ~= nvm.get("devRebootTime") then
  84. if not string.find(_devRebootTime, "(%d%d:%d%d:%d%d)") then
  85. log.error("httpTask.cbFnc","devRebootTime format error!",_devRebootTime)
  86. else
  87. if not nvm.set("devRebootTime", _devRebootTime) then
  88. log.error("httpTask.cbFnc","nvm set devRebootTime failed!")
  89. return false
  90. end
  91. isReboot = true
  92. end
  93. end
  94. local _isRebootDevice = tonumber(res_config.data.isRebootDevice)
  95. if _isRebootDevice == 1 then
  96. log.info("httpTask.cbFnc","receive device reboot command")
  97. isReboot = true
  98. end
  99. local _isRestoreDevice = tonumber(res_config.data.isRestoreDevice)
  100. if _isRestoreDevice == 1 then
  101. log.info("httpTask.cbFnc","receive device restore command")
  102. nvm.restore()
  103. isReboot = true
  104. end
  105. local _isStartOta = tonumber(res_config.data.isStartOta)
  106. if _isStartOta == 1 then
  107. log.info("httpTask.cbFnc","receive device start ota command, publish message: device_command_ota_start")
  108. sys.publish("device_command_ota_start")
  109. return
  110. end
  111. local _otaCheckInterval = tonumber(res_config.data.otaCheckInterval)
  112. if type(_otaCheckInterval) == "number" and _otaCheckInterval >= 30 and _otaCheckInterval ~= nvm.get("otaCheckInterval") then
  113. if not nvm.set("otaCheckInterval", _otaCheckInterval) then
  114. log.error("httpTask.cbFnc","nvm set otaCheckInterval failed!")
  115. return false
  116. end
  117. isReboot = true
  118. end
  119. local _rfidRssiFilterVal = tonumber(res_config.data.rfidRssiFilterVal)
  120. if type(_rfidRssiFilterVal) == "number" and _rfidRssiFilterVal > 0 and _rfidRssiFilterVal ~= nvm.get("rfidRssiFilterVal") then
  121. if not nvm.set("rfidRssiFilterVal", _rfidRssiFilterVal) then
  122. log.error("httpTask.cbFnc","nvm set rfidRssiFilterVal failed!")
  123. return false
  124. end
  125. isReboot = true
  126. end
  127. local enableUploadRfid24 = tonumber(res_config.data.enableUploadRfid24)
  128. if type(enableUploadRfid24) == "number" and (enableUploadRfid24 == 0 or enableUploadRfid24 == 1) and enableUploadRfid24 ~= nvm.get("enableUploadRfid24") then
  129. if not nvm.set("enableUploadRfid24", enableUploadRfid24) then
  130. log.error("httpTask.cbFnc","nvm set enableUploadRfid24 failed!")
  131. return false
  132. end
  133. isReboot = true
  134. end
  135. if rfidType == "tiandiren" then
  136. if res_config.data.ddzxIp ~= "" and res_config.data.ddzxIp ~= nvm.get("ddzxIp") then
  137. if not nvm.set("ddzxIp", res_config.data.ddzxIp) then
  138. log.error("httpTask.cbFnc","nvm set ddzxIp failed!")
  139. return false
  140. end
  141. isReboot = true
  142. end
  143. local _ddzxTcpPort = res_config.data.ddzxTcpPort
  144. if _ddzxTcpPort ~= "" and _ddzxTcpPort ~= nvm.get("ddzxTcpPort") then
  145. if not nvm.set("ddzxTcpPort", _ddzxTcpPort) then
  146. log.error("httpTask.cbFnc","nvm set ddzxTcpPort failed!")
  147. return false
  148. end
  149. isReboot = true
  150. end
  151. local _ddzxWaitRecvMsgMaxTime = tonumber(res_config.data.ddzxWaitRecvMsgMaxTime)
  152. if type(_ddzxWaitRecvMsgMaxTime) == "number" and _ddzxWaitRecvMsgMaxTime > 0 and _ddzxWaitRecvMsgMaxTime ~= nvm.get("ddzxWaitRecvMsgMaxTime") then
  153. if not nvm.set("ddzxWaitRecvMsgMaxTime", _ddzxWaitRecvMsgMaxTime) then
  154. log.error("httpTask.cbFnc","nvm set ddzxWaitRecvMsgMaxTime failed!")
  155. return false
  156. end
  157. isReboot = true
  158. end
  159. local _rfidOfflineTimeout = tonumber(res_config.data.rfidOfflineTimeout)
  160. if type(_rfidOfflineTimeout) == "number" and _rfidOfflineTimeout > 0 and _rfidOfflineTimeout ~= nvm.get("rfidOfflineTimeout") then
  161. if not nvm.set("rfidOfflineTimeout", _rfidOfflineTimeout) then
  162. log.error("httpTask.cbFnc","nvm set rfidOfflineTimeout failed!")
  163. return false
  164. end
  165. isReboot = true
  166. end
  167. local _rfidMinDiffTime = tonumber(res_config.data.rfidMinDiffTime)
  168. if type(_rfidMinDiffTime) == "number" and _rfidMinDiffTime > 0 and _rfidMinDiffTime ~= nvm.get("rfidMinDiffTime") then
  169. if not nvm.set("rfidMinDiffTime", _rfidMinDiffTime) then
  170. log.error("httpTask.cbFnc","nvm set rfidMinDiffTime failed!")
  171. return false
  172. end
  173. isReboot = true
  174. end
  175. local _enableFilterTdrRfid = tonumber(res_config.data.enableFilterTdrRfid)
  176. if type(_enableFilterTdrRfid) == "number" and (_enableFilterTdrRfid == 0 or _enableFilterTdrRfid == 1) and _enableFilterTdrRfid ~= nvm.get("enableFilterTdrRfid") then
  177. if not nvm.set("enableFilterTdrRfid", _enableFilterTdrRfid) then
  178. log.error("httpTask.cbFnc","nvm set enableFilterTdrRfid failed!")
  179. return false
  180. end
  181. isReboot = true
  182. end
  183. local _onlyDevTypeVal = res_config.data.onlyDevTypeVal
  184. if _onlyDevTypeVal ~= nvm.get("onlyDevTypeVal") then
  185. if not nvm.set("onlyDevTypeVal", _onlyDevTypeVal) then
  186. log.error("httpTask.cbFnc","nvm set onlyDevTypeVal failed!")
  187. return false
  188. end
  189. isReboot = true
  190. end
  191. local _msgQueueMaxLen = tonumber(res_config.data.msgQueueMaxLen)
  192. if type(_msgQueueMaxLen) == "number" and _msgQueueMaxLen > 0 and _msgQueueMaxLen ~= nvm.get("msgQueueMaxLen") then
  193. if not nvm.set("msgQueueMaxLen", _msgQueueMaxLen) then
  194. log.error("httpTask.cbFnc","nvm set msgQueueMaxLen failed!")
  195. return false
  196. end
  197. isReboot = true
  198. end
  199. elseif rfidType == "renlian" then
  200. if (res_config.data.enableHeartbeat == 0 or res_config.data.enableHeartbeat == 1) and res_config.data.enableHeartbeat ~= nvm.get("enableHeartbeat") then
  201. if not nvm.set("enableHeartbeat", res_config.data.enableHeartbeat) then
  202. log.error("httpTask.cbFnc","nvm set enableHeartbeat failed!")
  203. return false
  204. end
  205. isReboot = true
  206. end
  207. if funlib.ipFormatVerify(res_config.data.heartbeatIp) and res_config.data.heartbeatIp ~= nvm.get("heartbeatIp") then
  208. if not nvm.set("heartbeatIp", res_config.data.heartbeatIp) then
  209. log.error("httpTask.cbFnc","nvm set heartbeatIp failed!")
  210. return false
  211. end
  212. isReboot = true
  213. end
  214. local heartbeatTcpPort = res_config.data.heartbeatTcpPort or ""
  215. if heartbeatTcpPort ~= "" and heartbeatTcpPort ~= nvm.get("heartbeatTcpPort") then
  216. if not nvm.set("heartbeatTcpPort", heartbeatTcpPort) then
  217. log.error("httpTask.cbFnc","nvm set heartbeatTcpPort failed!")
  218. return false
  219. end
  220. isReboot = true
  221. end
  222. local heartbeatInterval = res_config.data.heartbeatInterval or 0
  223. if heartbeatInterval >= 10 and heartbeatInterval ~= nvm.get("heartbeatInterval") then
  224. if not nvm.set("heartbeatInterval", heartbeatInterval) then
  225. log.error("httpTask.cbFnc","nvm set heartbeatInterval failed!")
  226. return false
  227. end
  228. isReboot = true
  229. end
  230. if res_config.data.dataIp ~= "" and res_config.data.dataIp ~= nvm.get("dataIp") then
  231. if not nvm.set("dataIp", res_config.data.dataIp) then
  232. log.error("httpTask.cbFnc","nvm set dataIp failed!")
  233. return false
  234. end
  235. isReboot = true
  236. end
  237. local _dataTcpPort = res_config.data.dataTcpPort
  238. if _dataTcpPort ~= "" and _dataTcpPort ~= nvm.get("dataTcpPort") then
  239. if not nvm.set("dataTcpPort", _dataTcpPort) then
  240. log.error("httpTask.cbFnc","nvm set dataTcpPort failed!")
  241. return false
  242. end
  243. isReboot = true
  244. end
  245. local _dataUdpPort = res_config.data.dataUdpPort
  246. if _dataUdpPort ~= "" and _dataUdpPort ~= nvm.get("dataUdpPort") then
  247. if not nvm.set("dataUdpPort", _dataUdpPort) then
  248. log.error("httpTask.cbFnc","nvm set dataUdpPort failed!")
  249. return false
  250. end
  251. isReboot = true
  252. end
  253. local _rfidEnableThrottleRlian = tonumber(res_config.data.rfidEnableThrottleRlian)
  254. if _rfidEnableThrottleRlian >=0 and _rfidEnableThrottleRlian ~= nvm.get("rfidEnableThrottleRlian") then
  255. if not nvm.set("rfidEnableThrottleRlian", _rfidEnableThrottleRlian) then
  256. log.error("httpTask.cbFnc","nvm set rfidEnableThrottleRlian failed!")
  257. return false
  258. end
  259. isReboot = true
  260. end
  261. local _rfidReportIntervalRlian = tonumber(res_config.data.rfidReportIntervalRlian)
  262. if type(_rfidReportIntervalRlian) == "number" and _rfidReportIntervalRlian >0 and _rfidReportIntervalRlian ~= nvm.get("rfidReportIntervalRlian") then
  263. if not nvm.set("rfidReportIntervalRlian", _rfidReportIntervalRlian) then
  264. log.error("httpTask.cbFnc","nvm set rfidReportIntervalRlian failed!")
  265. return false
  266. end
  267. isReboot = true
  268. end
  269. local _rfidBufferMaxCountRlian = tonumber(res_config.data.rfidBufferMaxCountRlian)
  270. if type(_rfidBufferMaxCountRlian) == "number" and _rfidBufferMaxCountRlian >0 and _rfidBufferMaxCountRlian ~= nvm.get("rfidBufferMaxCountRlian") then
  271. if not nvm.set("rfidBufferMaxCountRlian", _rfidBufferMaxCountRlian) then
  272. log.error("httpTask.cbFnc","nvm set rfidBufferMaxCountRlian failed!")
  273. return false
  274. end
  275. isReboot = true
  276. end
  277. local _rfidOfflineTimeoutRlian = tonumber(res_config.data.rfidOfflineTimeoutRlian)
  278. if type(_rfidOfflineTimeoutRlian) == "number" and _rfidOfflineTimeoutRlian >0 and _rfidOfflineTimeoutRlian ~= nvm.get("rfidOfflineTimeoutRlian") then
  279. if not nvm.set("rfidOfflineTimeoutRlian", _rfidOfflineTimeoutRlian) then
  280. log.error("httpTask.cbFnc","nvm set rfidOfflineTimeoutRlian failed!")
  281. return false
  282. end
  283. isReboot = true
  284. end
  285. elseif rfidType == "dahua" then
  286. if res_config.data.ddzxIpDahua ~= "" and res_config.data.ddzxIpDahua ~= nvm.get("ddzxIpDahua") then
  287. if not nvm.set("ddzxIpDahua", res_config.data.ddzxIpDahua) then
  288. log.error("httpTask.cbFnc","nvm set ddzxIpDahua failed!")
  289. return false
  290. end
  291. isReboot = true
  292. end
  293. local _ddzxTcpPortDahua = res_config.data.ddzxTcpPortDahua
  294. if _ddzxTcpPortDahua ~= "" and _ddzxTcpPortDahua ~= nvm.get("ddzxTcpPortDahua") then
  295. if not nvm.set("ddzxTcpPortDahua", _ddzxTcpPortDahua) then
  296. log.error("httpTask.cbFnc","nvm set ddzxTcpPortDahua failed!")
  297. return false
  298. end
  299. isReboot = true
  300. end
  301. local _rfidBufferMaxCountDahua = tonumber(res_config.data.rfidBufferMaxCountDahua)
  302. if type(_rfidBufferMaxCountDahua) == "number" and _rfidBufferMaxCountDahua > 0 and _rfidBufferMaxCountDahua ~= nvm.get("rfidBufferMaxCountDahua") then
  303. if not nvm.set("rfidBufferMaxCountDahua", _rfidBufferMaxCountDahua) then
  304. log.error("httpTask.cbFnc","nvm set rfidBufferMaxCountDahua failed!")
  305. return false
  306. end
  307. isReboot = true
  308. end
  309. local _rfidReportIntervalDahua = tonumber(res_config.data.rfidReportIntervalDahua)
  310. if type(_rfidReportIntervalDahua) == "number" and _rfidReportIntervalDahua > 0 and _rfidReportIntervalDahua ~= nvm.get("rfidReportIntervalDahua") then
  311. if not nvm.set("rfidReportIntervalDahua", _rfidReportIntervalDahua) then
  312. log.error("httpTask.cbFnc","nvm set rfidReportIntervalDahua failed!")
  313. return false
  314. end
  315. isReboot = true
  316. end
  317. else
  318. log.error("httpTask.cbFnc","invalid rfidType!! rfidType:", rfidType)
  319. return false
  320. end
  321. if isReboot then
  322. log.info("httpTask.cbFnc","config updated, need reboot now ...")
  323. sys.restart("config.lua updated")
  324. return
  325. end
  326. end
  327. end
  328. local function http_heartbeat()
  329. local coreVersion = rtos.get_version() or ""
  330. local scriptVersion = _G.VERSION or ""
  331. local simIccid = nvm.get("simIccid") or ""
  332. local simImsi = nvm.get("simImsi") or ""
  333. local httpDevopsInterval = nvm.get("httpDevopsInterval") or ""
  334. local devRebootTime = nvm.get("devRebootTime") or ""
  335. local otaUrl = nvm.get("otaUrl") or ""
  336. local otaCheckInterval = nvm.get("otaCheckInterval") or ""
  337. local errorLogReportUrl = nvm.get("errorLogReportUrl") or ""
  338. local errorLogReportInterval = nvm.get("errorLogReportInterval") or ""
  339. local bootNum = nvm.get("bootNum") or ""
  340. local devModel = nvm.get("devModel") or ""
  341. local rfidRssiFilterVal = nvm.get("rfidRssiFilterVal") or ""
  342. local httpEnableParamsReport = nvm.get("httpEnableParamsReport") or 0
  343. local enableUploadRfid24 = nvm.get("enableUploadRfid24") or 1
  344. moduleImei = misc.getImei() or ""
  345. if not coreVersion then
  346. log.error("httpTask.http_heartbeat","coreVersion not existed!!")
  347. return false
  348. end
  349. if not scriptVersion then
  350. log.error("httpTask.http_heartbeat","scriptVersion not existed!!")
  351. return false
  352. end
  353. if not simIccid then
  354. log.error("httpTask.http_heartbeat","simIccid not existed!!")
  355. return false
  356. end
  357. if not simImsi then
  358. log.error("httpTask.http_heartbeat","simImsi not existed!!")
  359. return false
  360. end
  361. if not devId then
  362. log.error("httpTask.http_heartbeat","devId not existed!!")
  363. return false
  364. end
  365. if not devSn then
  366. log.error("httpTask.http_heartbeat","devSn not existed!!")
  367. return false
  368. end
  369. if not moduleImei then
  370. log.error("httpTask.http_heartbeat","moduleImei not existed!!")
  371. return false
  372. end
  373. if not httpDevopsUrl then
  374. log.error("httpTask.http_heartbeat","httpDevopsUrl not existed!!")
  375. return false
  376. end
  377. local ramUsed = _G.collectgarbage("count")
  378. local freeFlash = rtos.get_fs_free_size()
  379. local netRssi = net.getRssi()
  380. local reqUrl = ""
  381. if httpEnableParamsReport == 1 then
  382. reqUrl = httpDevopsUrl.."&deviceId="..devId.."&deviceImei="..moduleImei.."&deviceSn="..devSn.."&coreVersion="..coreVersion
  383. .."&scriptVersion="..scriptVersion.."&simIccid="..simIccid.."&simImsi="..simImsi
  384. .."&httpDevopsInterval="..httpDevopsInterval.."&devRebootTime="..devRebootTime
  385. .."&otaUrl="..otaUrl.."&otaCheckInterval="..otaCheckInterval.."&errorLogReportUrl="..errorLogReportUrl
  386. .."&errorLogReportInterval="..errorLogReportInterval.."&bootNum="..bootNum.."&devModel="..devModel
  387. .."&ramUsed="..ramUsed.."&freeFlash="..freeFlash.."&netRssi="..netRssi.."&rfidRssiFilterVal="..rfidRssiFilterVal
  388. .."&enableUploadRfid24="..enableUploadRfid24
  389. if rfidType == "tiandiren" then
  390. local ddzxIp = nvm.get("ddzxIp") or ""
  391. local ddzxTcpPort = nvm.get("ddzxTcpPort") or ""
  392. local ddzxWaitRecvMsgMaxTime = nvm.get("ddzxWaitRecvMsgMaxTime") or ""
  393. local rfidOfflineTimeout = nvm.get("rfidOfflineTimeout") or ""
  394. local rfidMinDiffTime = nvm.get("rfidMinDiffTime") or ""
  395. local msgQueueMaxLen = nvm.get("msgQueueMaxLen") or ""
  396. local enableFilterTdrRfid = nvm.get("enableFilterTdrRfid") or 1
  397. local onlyDevTypeVal = nvm.get("onlyDevTypeVal") or ""
  398. reqUrl = reqUrl.."&ddzxIp="..ddzxIp.."&ddzxTcpPort="..ddzxTcpPort.."&ddzxWaitRecvMsgMaxTime="..ddzxWaitRecvMsgMaxTime
  399. .."&rfidOfflineTimeout="..rfidOfflineTimeout.."&msgQueueMaxLen="..msgQueueMaxLen
  400. .."&rfidMinDiffTime="..rfidMinDiffTime.."&enableFilterTdrRfid="..enableFilterTdrRfid.."&onlyDevTypeVal="..onlyDevTypeVal
  401. elseif rfidType == "renlian" then
  402. local enableHeartbeat = nvm.get("enableHeartbeat") or 0
  403. local dataIp = nvm.get("dataIp") or ""
  404. local dataTcpPort = nvm.get("dataTcpPort") or ""
  405. local dataUdpPort = nvm.get("dataUdpPort") or ""
  406. local heartbeatIp = nvm.get("heartbeatIp") or ""
  407. local heartbeatTcpPort = nvm.get("heartbeatTcpPort") or ""
  408. local heartbeatUdpPort = nvm.get("heartbeatUdpPort") or ""
  409. local heartbeatInterval = nvm.get("heartbeatInterval") or 0
  410. local rfidReportIntervalRlian = nvm.get("rfidReportIntervalRlian") or ""
  411. local rfidBufferMaxCountRlian = nvm.get("rfidBufferMaxCountRlian") or ""
  412. local rfidEnableThrottleRlian = nvm.get("rfidEnableThrottleRlian")
  413. local rfidOfflineTimeoutRlian = nvm.get("rfidOfflineTimeoutRlian") or ""
  414. reqUrl = reqUrl.."&dataIp="..dataIp.."&dataTcpPort="..dataTcpPort.."&dataUdpPort="..dataUdpPort
  415. .."&rfidReportIntervalRlian="..rfidReportIntervalRlian.."&rfidBufferMaxCountRlian="..rfidBufferMaxCountRlian
  416. .."&rfidEnableThrottleRlian="..rfidEnableThrottleRlian.."&rfidOfflineTimeoutRlian="..rfidOfflineTimeoutRlian
  417. .."&g91State="..g91State.."&enableHeartbeat="..enableHeartbeat.."&heartbeatIp="..heartbeatIp.."&heartbeatTcpPort="..heartbeatTcpPort
  418. .."&heartbeatInterval="..heartbeatInterval
  419. elseif rfidType == "dahua" then
  420. local ddzxIpDahua = nvm.get("ddzxIpDahua") or ""
  421. local ddzxTcpPortDahua = nvm.get("ddzxTcpPortDahua") or ""
  422. local rfidBufferMaxCountDahua = nvm.get("rfidBufferMaxCountDahua") or ""
  423. local rfidReportIntervalDahua = nvm.get("rfidReportIntervalDahua") or ""
  424. reqUrl = reqUrl.."&ddzxIpDahua="..ddzxIpDahua.."&ddzxTcpPortDahua="..ddzxTcpPortDahua.."&rfidBufferMaxCountDahua="..rfidBufferMaxCountDahua
  425. .."&rfidReportIntervalDahua="..rfidReportIntervalDahua
  426. else
  427. log.error("httpTask.http_heartbeat","invalid rfidType!! rfidType:", rfidType)
  428. return false
  429. end
  430. else
  431. reqUrl = httpDevopsUrl.."&deviceId="..devId.."&deviceSn="..devSn.."&coreVersion="..coreVersion.."&scriptVersion="..scriptVersion.."&bootNum="..bootNum
  432. end
  433. log.info("httpTask.http_heartbeat", "reqUrl:", reqUrl, "start httpTask, httpDevopsInterval:", httpDevopsInterval)
  434. isHttpRequesting = true
  435. http.request("GET",reqUrl,nil,nil,nil,nil,cbFnc)
  436. end
  437. --[[
  438. --定时心跳任务
  439. sys.timerLoopStart(function()
  440. http_heartbeat()
  441. end, httpDevopsInterval *1000)
  442. ]]
  443. --定时心跳任务
  444. sys.taskInit(function()
  445. while true do
  446. if socket.isReady() then --连上网再开始运行
  447. log.info("httpTask","send http heartbeat ...")
  448. http_heartbeat() --等待一段时间发下次心跳
  449. log.info("httpTask","wait ", httpDevopsInterval, "s ...")
  450. sys.wait(httpDevopsInterval *1000)
  451. else --没连上网别忘了延时!不然会陷入while true死循环,导致模块无法运行其他代码
  452. log.info("httpTask","socket have not ready,wait 1s ...")
  453. sys.wait(1000) --等待1秒
  454. end
  455. end
  456. end)
  457. --920设备状态实时监测任务
  458. sys.taskInit(function()
  459. while true do
  460. local g91OfflineTime = nvm.get("g91OfflineTime") or 600
  461. if sys.waitUntil("receive_920_device_info", g91OfflineTime*1000) then
  462. log.info("httpTask.g91State","920 device online")
  463. g91State = 1
  464. else
  465. log.warn("httpTask.g91State","920 device offline!")
  466. g91State = 0
  467. end
  468. end
  469. end)