Dozingfiretruck 3 лет назад
Родитель
Сommit
2a93f4cfa5
1 измененных файлов с 18 добавлено и 4 удалено
  1. 18 4
      script/libs/libfota.lua

+ 18 - 4
script/libs/libfota.lua

@@ -10,15 +10,24 @@
 local libfota = require("libfota")
 
 -- 功能:获取fota的回调函数
--- 参数:-- result:number类型,0表示成功,1表示连接失败,2表示url错误,3表示服务器断开,4表示接收报文错误
+-- 参数:-- result:number类型,0表示成功,1表示连接失败,2表示url错误,3表示服务器断开,4表示接收报文错误,5表示使用iot平台VERSION需要使用 xxx.yyy形式
 function libfota_cb(result)
     -- fota成功
     if result == 0 then
-        rtos.reboot()   --如果还有其他事情要做就不要立刻reboot
+        rtos.reboot()   --如果还有其他事情要做,就不要立刻reboot
     end
 end
+
+--注意!!!:使用合宙iot平台,必须用luatools量产生成的.bin文件!!! 自建服务器可使用.soc文件!!!
+--注意!!!:使用合宙iot平台,必须用luatools量产生成的.bin文件!!! 自建服务器可使用.soc文件!!!
+--注意!!!:使用合宙iot平台,必须用luatools量产生成的.bin文件!!! 自建服务器可使用.soc文件!!!
+
+--下方示例为合宙iot平台,地址:http://iot.openluat.com 
 libfota.request(libfota_cb,0,0,0,"http://iot.openluat.com/api/site/firmware_upgrade?project_key=" .. _G.PRODUCT_KEY .. "&imei=".. mobile.imei() .. "&device_key=&firmware_name=" .. _G.PROJECT.. "_LuatOS-SoC_" .. rtos.bsp() .. "&version=" .. rtos.version():sub(2) .. "." .. _G.VERSION)
 
+--如使用自建服务器,自行更换url
+libfota.request(libfota_cb,0,0,0,"http://xxxxxx.com")
+
 ]]
 
 local sys = require "sys"
@@ -57,9 +66,14 @@ local function fota_task(cbFnc,storge_location, len, param1,ota_url,ota_port,tim
     local result = libnet.waitLink(taskName, 0, netc)
     local type,host,uri = string.match(ota_url,"(%a-)://(%S-)/(%S+)")
     while retry < 3 and not done do
-        if type ==nil or host ==nil then
+        if type == nil or host == nil then
             ret = 2
             break
+        elseif host == "iot.openluat.com" then
+            if string.match(_G.VERSION,"(%d+).(%d+).(%d+)") then
+                ret = 5
+                break
+            end
         end
         result = libnet.connect(taskName, 30000, netc, host, ota_port) --后续出了http库则直接用http来处理
         tbuff:del()
@@ -202,7 +216,7 @@ fota升级
 @number/string storge_location fota数据存储的起始位置<br>如果是int,则是由芯片平台具体判断<br>如果是string,则存储在文件系统中<br>如果为nil,则由底层决定存储位置
 @number len 数据存储的最大空间
 @userdata param1,如果数据存储在spiflash时,为spi_device
-@string ota_url url
+@string ota_url url 合宙iot平台url拼接参考示例
 @number ota_port 请求端口,默认80
 @number timeout 请求超时时间,单位毫秒,默认20000毫秒
 @return nil