diff --git a/docs/API_reference/en/syslib/fota.md b/docs/API_reference/en/syslib/fota.md index 6c94f2c7a7baec3eb11af13fb433571516fd010c..0a78f322a87b9974d423925ab6ab09ff4b8d88b7 100644 --- a/docs/API_reference/en/syslib/fota.md +++ b/docs/API_reference/en/syslib/fota.md @@ -10,26 +10,36 @@ import fota import utime import log +import checkNet # Sets the log output level log.basicConfig(level=log.INFO) fota_log = log.getLogger("Fota") +PROJECT_NAME = "QuecPython_fota_example" +PROJECT_VERSION = "1.0.0" + +checknet = checkNet.CheckNetwork(PROJECT_NAME, PROJECT_VERSION) + def result(args): print('download status:',args[0],'download process:',args[1]) - + def run(): - fota_obj = fota() # Creates a FOTA object - fota_log.info("httpDownload...") - # Methods of DFOTA upgrades - res = fota_obj.httpDownload(url1="http://www.example.com/fota.bin",callback=result) - # Methods of mini FOTA - #res = fota_obj.httpDownload(url1="http://www.example.com/fota1.bin",url2="http://www.example.com/fota2.bin") - if res != 0: - fota_log.error("httpDownload error") - return - fota_log.info("wait httpDownload update...") - utime.sleep(2) + stagecode, subcode = checknet.wait_network_connected(30) + if stagecode == 3 and subcode == 1: + fota_obj = fota() # Creates a FOTA object + fota_log.info("httpDownload...") + # Methods of DFOTA upgrades + res = fota_obj.httpDownload(url1="http://www.example.com/fota.bin",callback=result) + # Methods of mini FOTA + #res = fota_obj.httpDownload(url1="http://www.example.com/fota1.bin",url2="http://www.example.com/fota2.bin") + if res != 0: + fota_log.error("httpDownload error") + return + fota_log.info("wait httpDownload update...") + utime.sleep(2) + else: + socket_log.info('Network connection failed! stagecode = {}, subcode = {}'.format(stagecode, subcode)) if __name__ == '__main__': fota_log.info("run start...") diff --git a/docs/API_reference/zh/syslib/fota.md b/docs/API_reference/zh/syslib/fota.md index f462f1b3d9e1b5ec65d0d64af7cbd6f6724fa075..dd165b6b6f97c3daf1e7f284e270f7a5e2549e03 100644 --- a/docs/API_reference/zh/syslib/fota.md +++ b/docs/API_reference/zh/syslib/fota.md @@ -10,28 +10,38 @@ import fota import utime import log +import checkNet # 设置日志输出级别 log.basicConfig(level=log.INFO) fota_log = log.getLogger("Fota") +PROJECT_NAME = "QuecPython_fota_example" +PROJECT_VERSION = "1.0.0" + +checknet = checkNet.CheckNetwork(PROJECT_NAME, PROJECT_VERSION) + def result(args): print('download status:',args[0],'download process:',args[1]) - + def run(): - fota_obj = fota() # 创建Fota对象 - fota_log.info("httpDownload...") - #差分升级方式 - res = fota_obj.httpDownload(url1="http://www.example.com/fota.bin",callback=result) - #mini fota方式 - #res = fota_obj.httpDownload(url1="http://www.example.com/fota1.bin",url2="http://www.example.com/fota2.bin") - #差分升级FTP方式 - #res = fota_obj.httpDownload(url1="ftp://user:password@ip:port/fota.bin",callback=result) #其中user,password,ip,port需要填写具体使用的FTP服务器信息 - if res != 0: - fota_log.error("httpDownload error") - return - fota_log.info("wait httpDownload update...") - utime.sleep(2) + stagecode, subcode = checknet.wait_network_connected(30) + if stagecode == 3 and subcode == 1: + fota_obj = fota() # 创建Fota对象 + fota_log.info("httpDownload...") + #差分升级方式 + res = fota_obj.httpDownload(url1="http://www.example.com/fota.bin",callback=result) + #mini fota方式 + #res = fota_obj.httpDownload(url1="http://www.example.com/fota1.bin",url2="http://www.example.com/fota2.bin") + #差分升级FTP方式 + #res = fota_obj.httpDownload(url1="ftp://user:password@ip:port/fota.bin",callback=result) #其中user,password,ip,port需要填写具体使用的FTP服务器信息 + if res != 0: + fota_log.error("httpDownload error") + return + fota_log.info("wait httpDownload update...") + utime.sleep(2) + else: + socket_log.info('Network connection failed! stagecode = {}, subcode = {}'.format(stagecode, subcode)) if __name__ == '__main__': fota_log.info("run start...")