## 2026-1-29 修复STM32升级异常问题 可以进行正常升级 升级包只升级APP ## 2026-1-29 ## 2024-12-21 ymodem.lua 249行 if not sd:len() then break end 修复STM32升级异常问题 ## 2024-3-26 增加远程修改设备光控状态功能 方便修改设备工作状态 function Light_control_handoff() local Light_control1 = string.char(0xAA,0x03,0x01) local Light_control2 = string.char(0xAA,0x03,0x00) while true do if result.lcm == 0 then uart.write(1,Light_control1) elseif result.lcm == 1 then uart.write(1,Light_control2) end return end log.info("Light control handoff begin!!!!") end elseif cnf.cmd == "Light_control_handoff" then -- 光控模式切换 Light_control_handoff() --光控模式切换 if not mqttc:publish(pub, upres("Light_control_handoff", "The light control mode was successfully switched!!"), serverconf.qos) then break end ## 2024-2-23 修改串口通讯心跳逻辑 调整上报数据频率为5S一次 心跳间隔为1分钟 离线后开机间隔间隔为两分半 sys.taskInit( function() sys.wait(100) local uart_flag_count = 0 local uart_32 = string.char(0xCC,0XDD) while true do if uart_flag == 1 then uart_flag = 0 uart_flag_count = uart_flag_count + 1 if uart_flag_count > 5 then uart_flag_count = 0 uart.write(1,uart_32) log.info("uart_flag back!!!!") end end sys.wait(50) end end ) ## 2024-1-30 新增远程升级分类操作升级后可更新flash内数据 --参数更新升级 function update_stm32_parameters() local update32 = string.char(0xCC,0xAA) while true do uart.write(1,update32) sys.wait(500) end log.info("update_stm32_parameters begin!!!!") end elseif cnf.cmd == "update_stm32_Parameter" then -- stm32 升级 开始 if not mqttc:publish(pub, upres("update_stm32_Parameter", "stm32 update will start!!"), serverconf.qos) then break end update_stm32_parameters() sys.wait(200) stm8_update_sw = 1 update_stm32() --STM32远程升级 ## 2024-1-25 新增串口通讯心跳相关代码 --串口通讯交互心跳标志位 local uart_flag = 0 --串口通讯心跳交互 sys.taskInit( function() sys.wait(100) local uart_32 = string.char(0xCC,0XDD) while true do if uart_flag == 1 then uart_flag = 0 uart.write(1,uart_32) log.info("uart_flag back!!!!") end sys.wait(50) end end ) if flowCount[1] == 64 then --串口通讯心跳检测 uart_flag = 1 end ## 2023-12-18 修改串口通讯解析内容,消除主板温度不能负值参数 idx, result.bt = pack.unpack(conf, "0 and result_crc.kcnt<9000) then result.kcnt = result_crc.kcnt end 修改高压计数字段平台上报判断条件为 if tonumber(data.ct) > 5000 then data.ct = "0" end ## 2023-10-23 修改高压计数上报部分的代码 消除了上报数值不能超过25的异常问题 之前原因为浮点数为作为判断条件导致无法出现超过25的数值 由 data.ct = string.format(result.kcnt) -- 电击次数 if data.ct > "255" then data.ct = "0" end 改为 data.ct = string.format(result.kcnt) -- 电击次数 if tonumber(data.ct) > 255 then data.ct = "0" end ## 2023-9-28 修改自清虫部分代码,有下位机进行控制 -- 清虫任务: sys.taskInit(function() sys.wait(20 * 1000) if not VERSION:find("ZQC") then log.error("not zqc devices!!!") return end if zqcflag == 0 then log.info("first") local cle_cnt = 0 local dat_freq = string.char(0xAA,0x07) while true do log.info("second") cle_cnt = cle_cnt + 1 log.info("自清虫模式设置成功") uart.write(1,dat_freq) sys.wait(500) --uart.write(1,data) if cle_cnt == 2 then break end end log.info("自清虫模式设置结束") end end) ## 2023-9-14 更改设备主题用于区分迭代前后不同版本设备 新主题为/yfkj/scd-2.0/sub/ /yfkj/scd-2.0/pub/ 新增if result.ver:find("SCD-") then 判断不同版本程序 修改STN32远程升级判断条件及路径为 判断条件:SCD_STM32_UPDATE 路径:update/scd bin/rtthread.rbl 修改平台下发命令预警信息上报为组合信息 ## 2023-8-25 增加平台交互预警信息平台下发设置后会有预警消息 elseif cnf.cmd == "paramconf" then -- 参数配置 -- Set_paramconf(packet.payload) -- sys.wait(1000) -- if not mqttc:publish(pub, upData(), serverconf.qos) then break end -- 下发设备时控配置 if cnf.ext.ts ~= nil and cnf.ext.ts ~= '' and cnf.ext.st ~= nil and cnf.ext.st ~= '' and cnf.ext.et ~= nil and cnf.ext.et ~= '' then log.warn("Set TimControl successful !!!!!!") setsw(1) SetTimControl(tonumber(cnf.ext.ts),tonumber(cnf.ext.st),tonumber(cnf.ext.et)) if not mqttc:publish(pub, upres("SCD-TimControl", "TimControl is"..cnf.ext.st..cnf.ext.et), serverconf.qos) then break end sys.wait(100) end -- 下发配置设备自清虫间隔 if cnf.ext.clt ~= nil and cnf.ext.clt ~= '' then log.warn("Set Cleartime successful !!!!!!") SetCleartime(tonumber(cnf.ext.clt)) if not mqttc:publish(pub, upres("SCD-Cleartime", "Cleartime is"..cnf.ext.clt), serverconf.qos) then break end sys.wait(100) end -- 下发配置设备数据上传时间间隔 if cnf.ext.dattim ~= nil and cnf.ext.dattim ~= '' then log.warn("Set Dattim successful !!!!!!") setDattim(tonumber(cnf.ext.dattim)) if not mqttc:publish(pub, upres("SCD-Dattim","Dattim is"..cnf.ext.dattim), serverconf.qos) then break end sys.wait(100) end -- 下发配置设备开关机 if cnf.ext.ds ~= nil and cnf.ext.ds ~= '' then log.warn("Set switch successful !!!!!!") setsw(tonumber(cnf.ext.ds)) if not mqttc:publish(pub, upres("SCD-switch","switch is"..cnf.ext.ds), serverconf.qos) then break end sys.wait(100) end -- 下发配置光控工作时长 if cnf.ext.tt ~= nil and cnf.ext.tt ~= '' then log.warn("Set Timer successful !!!!!!") setTimer(tonumber(cnf.ext.tt)) if not mqttc:publish(pub, upres("SCD-Timer", "Timer is"..cnf.ext.tt), serverconf.qos) then break end sys.wait(100) end --配置杀虫灯版本号 if cnf.ext.vt ~= nil and cnf.ext.vt ~= '' and type(cnf.ext.vt)=="string" then nvm.set("version",cnf.ext.vt) sys.restart(cnf.ext.vt) if not mqttc:publish(pub, upres("SCD-version", "version is"..cnf.ext.vt), serverconf.qos) then break end sys.wait(100) end ## 2023-8-18 增加STM32远程升级成功上报功能 ymodem.lua local s = upwarn("update_stm32", "stm32 system update is ok!!") --平台上报升级成功消息 sys.publish("NET_SENT_RDY_", s) 增加升级失败重新升级 ## 2023-7-11 增加autoGPS.lua 更新lib库为820版本 修改GPS自动切换相关的代码 local function test1Cb(tag) log.info("testGps.test1Cb",tag) printGps() end local function test2Cb(tag) log.info("testGps.test2Cb",tag) printGps() end local function test3Cb(tag) log.info("testGps.test3Cb",tag) printGps() end --测试代码开关,取值1,2 local testIdx = 1 local function test(idx) --第1种测试代码 if idx==1 then --执行完下面三行代码后,GPS就会一直开启,永远不会关闭 --因为gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb}),这个开启,没有调用gps.close关闭 gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb}) --10秒内,如果gps定位成功,会立即调用test2Cb,然后自动关闭这个“GPS应用” --10秒时间到,没有定位成功,会立即调用test2Cb,然后自动关闭这个“GPS应用” gps.open(gps.TIMERORSUC,{tag="TEST2",val=10,cb=test2Cb}) --300秒时间到,会立即调用test3Cb,然后自动关闭这个“GPS应用” gps.open(gps.TIMER,{tag="TEST3",val=300,cb=test3Cb}) --第2种测试代码 elseif idx==2 then --执行完下面三行代码打开GPS后,5分钟之后GPS会关闭 gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb}) sys.timerStart(gps.close,300000,gps.DEFAULT,{tag="TEST1"}) gps.open(gps.TIMERORSUC,{tag="TEST2",val=10,cb=test2Cb}) gps.open(gps.TIMER,{tag="TEST3",val=60,cb=test3Cb}) end end -------------------------------------------------------------------- local function nmeaCb(nmeaItem) log.info("testGps.nmeaCb",nmeaItem) end -- GPS+LBS定位任务 sys.subscribe("AUTOGPS_READY",function(gpsLib,agpsLib,kind,baudrate) gps=gpsLib agps=agpsLib log.info("testGps.AUTOGPS_READY",baudrate,kind) gps.setUart(uartId,baudrate,8,uart.PAR_NONE,uart.STOP_1) -- 设置串口通信参数,波特率为自适应 --gps.setAerialMode(1,1,0,0) -- 设置GPS+BD定位(此接口目前仅针对Air530或者Air800有效) gps.setNmeaMode(2,nmeaCb) -- gps.lua和外部程序都处理NEMA数据 test(testIdx) sys.timerLoopStart(printGps,2000) end) sys.taskInit( function() while true do gps_status = 0 locat_cnt = 0 sys.wait(8 * 1000) -- 等待socket连接完毕 while true do if tonumber(manual_location.type) == 0 then -- 判断是否手动定位 若手动定位直接关闭GPS if socket.isReady() and gps_status ~=1 and gps_status ~= 2 then log.warn("================ LBS Location successful ===============") lbsLoc.request(getLocCb) sys.wait(1000) end if gps.isFix() == false then log.info("================ GPS Location failed ===============") printGps() elseif gps.isFix() == true then gps_cont = gps_cont + 1 local location = gps.getLocation() gps_loc_lat = location.lat gps_loc_lng = location.lng printGps() if gps_cont >= 3 then -- 获取3次gps定位数据的最后一次 nvm.set("lat_gps",gps_loc_lat) nvm.set("lng_gps",gps_loc_lng) gps.closeAll() end gps_status = 1 log.info("================ GPS Location successful ===============") end sys.wait(1000) log.info("GPS open status is:", gps.isOpen()) log.info("GPS location status is:", gps.isFix()) else gps_status = 0 gps.closeAll() sys.wait(2000) end sys.wait(1000) locat_cnt = locat_cnt + 1 if locat_cnt >= 1800 then -- 每隔30分钟判断一下定位,若失败,则break if (gps_loc_lng == "0" and gps_loc_lat == "0") and (lbs_loc_lat == "0" and lbs_loc_lng == "0") then break else locat_cnt = 0 log.warn("location normal !!!") end end end end end ) ## 2023-5-31 PROJECT = "SCD_4G_MODULE" VERSION = "4.0.02-3-4G-uart" 新增迭代版本单片机远程升级功能 增加update32.lua ymodem.lua 文件 通讯频率9600 传输字节128 及升级相关代码 --下发主板升级命令 function update_stm32() local update_cnt = 0 local up_date_32 = string.char(0xAA,0xA0) while true do update_cnt = update_cnt + 1 uart.write(1,up_date_32) sys.wait(500) if update_cnt == 2 then break end end log.info("update_stm32 begin!!!!") end --下发BootLoader交互命令 function BootLoader_stm32() local boot_count = 0 local BootLoader_32 = string.char(0x31) while true do boot_count = boot_count + 1 uart.write(1,BootLoader_32) sys.wait(200) if boot_count == 2 then break end end log.info("BootLoader begin!!!!") end elseif cnf.cmd == "update_stm32" then if not mqttc:publish(pub, upres("update_stm32", "stm32 update will start!!"), serverconf.qos) then break end stm8_update_sw = 1 update_stm32() --STM32远程升级 --BootLoader交互信息下发 sys.taskInit( function() sys.wait(500) while true do if BootLoader_flag == 1 then BootLoader_flag = 0 log.info("BootLoader_flag",BootLoader_flag) BootLoader_stm32() log.info("stm32 SerialDownload !!!") end if upgrade_again = 1 then log.info("update_stm32 system will upgrade again !!!") update32.run() end sys.wait(500) end end ) if s:find("update") then updateflag = 1 if update32.updateok == 0 then s = upwarn("device_stm32", "system will update") sys.publish("NET_SENT_RDY_", s) else s = upwarn("device_stm32", "system is updating......") sys.publish("NET_SENT_RDY_", s) end log.info("update_stm32 system will update !!!") update32.run() end 新增STM32单片机通讯代码 ----------DCSCD--U-V1.0版本 elseif #conf == nil or #conf == 0 or conf:len() == 62 then log.info("getParam len,value:", string.toHex(conf, " ")) -- 将返回的数据填充到result表 result.ver = string.sub(conf, 47,59) -- 软件版本-DC-SCD-U-V1.0 idx, result.iSave = pack.unpack(conf, "b", idx) -- eeprom标志位 if result.iSave ~= 0xAA then return end -- 判断chuankou上传数据格式是否正确 idx, result_crc.ds = pack.unpack(conf, ">b", idx) -- 设备状态 if(result_crc.ds==0 or result_crc.ds==1) then result.ds = result_crc.ds end idx, result_crc.tt = pack.unpack(conf, "b", idx) -- 光控时长小时 if(result_crc.tt>=0 and result_crc.tt<8) then result.tt = result_crc.tt end idx, result_crc.ws = pack.unpack(conf, "b", idx) -- 工作状态 if(result_crc.ws==0 or result_crc.ws==1 or result_crc.ws==2) then result.ws = result_crc.ws end idx, result_crc.lps = pack.unpack(conf, "b", idx) -- 光控状态 if(result_crc.lps==0 or result_crc.lps==1) then result.lps = result_crc.lps end idx, result_crc.rps = pack.unpack(conf, "b", idx) -- 雨控状态 if(result_crc.rps==0 or result_crc.rps==1) then result.rps = result_crc.rps if(result_crc.rps==1 and rps_y==0) then rps_x = 1 elseif(result_crc.rps==0) then rps_y = 0 end end idx, result_crc.tps = pack.unpack(conf, "b", idx) -- 温控状态 if(result_crc.tps==0 or result_crc.tps==1 or result_crc.tps==2) then result.tps = result_crc.tps end idx, result_crc.dps = pack.unpack(conf, "b", idx) -- 倾倒保护 if(result_crc.dps==0 or result_crc.dps==1) then result.dps = result_crc.dps end idx, result_crc.vps = pack.unpack(conf, "b", idx) -- 电压状态 if(result_crc.vps==0 or result_crc.vps==1 or result_crc.vps==2) then result.vps = result_crc.vps end idx, paramconf.battype = pack.unpack(conf, "b", idx) -- 电池类型 idx, result.Lamp = pack.unpack(conf, 'b', idx) -- 灯管故障检测 idx, result.Infrared = pack.unpack(conf, 'b', idx) -- 红外传感器 idx, result.kcnt = pack.unpack(conf, "b", idx) -- 电击击杀检测 --if(result_crc.kcnt>0 and result_crc.kcnt<255) then result.kcnt = result_crc.kcnt end idx, result.cleartim = pack.unpack(conf, 'b', idx) -- 清虫时间间隔 idx, result.cycle_on = pack.unpack(conf, 'b', idx) -- 放电前频率 idx, result.cycle_off = pack.unpack(conf, 'b', idx) --放电结束频率 idx, result_crc.cv = pack.unpack(conf, "0 and result_crc.cv<30000) then result.cv = result_crc.cv if result.cv < 500 then result.cv = 0 end end idx, result_crc.bv = pack.unpack(conf, "0 and result_crc.bv<30000) then result.bv = result_crc.bv end idx, result.bt = pack.unpack(conf, "b", idx) -- 设备状态 if(result_crc.ds==0 or result_crc.ds==1) then result.ds = result_crc.ds end idx, result_crc.tt = pack.unpack(conf, "b", idx) -- 光控时长小时 if(result_crc.tt>=0 and result_crc.tt<8) then result.tt = result_crc.tt end idx, result_crc.ws = pack.unpack(conf, "b", idx) -- 工作状态 if(result_crc.ws==0 or result_crc.ws==1 or result_crc.ws==2) then result.ws = result_crc.ws end idx, result_crc.lps = pack.unpack(conf, "b", idx) -- 光控状态 if(result_crc.lps==0 or result_crc.lps==1) then result.lps = result_crc.lps end idx, result_crc.rps = pack.unpack(conf, "b", idx) -- 雨控状态 if(result_crc.rps==0 or result_crc.rps==1) then result.rps = result_crc.rps end idx, result_crc.tps = pack.unpack(conf, "b", idx) -- 温控状态 if(result_crc.tps==0 or result_crc.tps==1 or result_crc.tps==2) then result.tps = result_crc.tps end idx, result_crc.dps = pack.unpack(conf, "b", idx) -- 倾倒保护 if(result_crc.dps==0 or result_crc.dps==1) then result.dps = result_crc.dps end idx, result_crc.vps = pack.unpack(conf, "b", idx) -- 电压状态 if(result_crc.vps==0 or result_crc.vps==1) then result.vps = result_crc.vps end idx, result.cv = pack.unpack(conf, ">I", idx) -- 充电电压 if(result_crc.cv>0 and result_crc.cv<30000) then result.cv = result_crc.cv end idx, result_crc.bv = pack.unpack(conf, ">I", idx) -- 电池电压 if(result_crc.bv>0 and result_crc.bv<30000) then result.bv = result_crc.bv end idx, result.bt = pack.unpack(conf, ">I", idx) -- 主板温度 --if(result_crc.bt>-40 and result_crc.bt<100) then result.bt = result_crc.bt end ------------------------------------------------------------------------------------------------------------- 功能升级 添加反向订阅平台端天气接口功能,避免MQTT对接温湿度为默认值 --//--------反向获取平台温湿度接口传回MQTT function Setsensor_value(dat_sensor) local cmds,result,err = json.decode(dat_sensor) if not result then return end if cmds.ext.new_hum~=nil and cmds.ext.new_hum~="" then if tonumber(cmds.ext.new_hum)>=0 and tonumber(cmds.ext.new_hum)<=100 then hum = tonumber(cmds.ext.new_hum) end end if cmds.ext.new_tem~=nil and cmds.ext.new_tem~="" then if tonumber(cmds.ext.new_tem) < 100 then temp = tonumber(cmds.ext.new_tem) end end log.warn(">>>>>>>>>sensor data get is:>>>>>>>>>>",hum,temp) end elseif result and cnf.cmd=="sensor" then Setsensor_value(packet.payload) elseif result and cnf.cmd=="sensor" then Setsensor_value(packet.payload) -------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------- --==== 版本1:物联网(不带光控) === PROJECT = "SCD_4G_MODULE" VERSION = "3.3.19-4G" bug 修复 448行 在scd.lua 的448行添加 if st1==nil or st1=="" or et1 ==nil or et1 == "" then return end 消除定时时间设置为空的参数传递错误 - 2021 08 18 bug修复 scd文件 353行 上传数据信息 将 data.ds = string.format(result.ws or 1) -- 设备是否开机 更改为 data.ds = string.format(result.ds or 1) -- 设备是否开机 bug修复 远程升级函数调用重复 将lib库中的update.lua 文件删除 版本 3.3.18 2021 08 15 bug 修复 scd 文件 1234行 mqtt2线程守护线程 将if thirdserverconf.ip == "" then 更改为if thirdserverconf == nil or thirdserverconf.ip == "" then