当前位置:网站首页>Haas506 2.0 development tutorial -hota (only supports versions above 2.2)

Haas506 2.0 development tutorial -hota (only supports versions above 2.2)

2022-06-23 06:38:00 Zhiyunfu

1.hota.py upgrade

Case description

Use HTTP Protocol implementation OTA Air upgrade , Update the development board python Program . You only need to get the corresponding... Of the storage location URL You can update it .( The case uses Alibaba cloud OSS demonstrate , Users can change the storage location as needed )

(1) obtain URL

Upload the latest program to Alibaba cloud OSS. Get the name of the storage location URL.

  1. take main.py and board.json The file is compressed into zip Format file
     Insert picture description here
  2. Alibaba cloud creation Bucket

 Insert picture description here

  1. Upload files zip file

 Insert picture description here

  1. Click on the details - Copy file URL( The time can be extended appropriately , After a timeout URL It will fail )

 Insert picture description here

(2) Function code

Will duplicate url Fill in code
main.py

import utime as time
from modem import net
import hota
import network
import sntp
from modem import info
import system

pyversion="202204281243"
g_connect_status = False

def on_4g_cb(args):
    global g_connect_status
    pdp = args[0]
    netwk_sta = args[1]
    if netwk_sta == 1:
        g_connect_status = True
    else:
        g_connect_status = False

def connect_network():
    global netw,on_4g_cb,g_connect_status
    netw = network.NetWorkClient()
    g_register_network = False
    if netw._stagecode is not None and netw._stagecode == 3 and netw._subcode == 1:
        g_register_network = True
    else:
        g_register_network = False
    if g_register_network:
        netw.on(1,on_4g_cb)
        netw.connect(None)
    else:
        print('network register failed')
    while True:
        if g_connect_status:
            print('network register successed')
            break
        time.sleep_ms(20)

#py The upgrade package contains haas506 Of python Script upgrade package ,.zip File format 
def ota_py_app():
    global ota_flag
    # initialization 
    hot = hota.client()
    # modify url
    #########################################################################
    ota_url = " Fill in the copied url Replace "
    #########################################################################
    ota_flag = 0
    if hot.fotaPy(ota_url) == 0:  #py Firmware download succeeded , Restart the device 
        print('------------------htp.pyfotaPy')
        time.sleep_ms(1000)
        system.reset()
    else:
        print('pyota failed!')


if __name__ == '__main__':
    connect_network()# Connect to the network 
    pacversion = info.getDevFwVersion()
    print('---------------------------pacversion={}'.format(pacversion))
    sntp.settime()#SNTP Right time 
    print("csq:",net.getCsq())
    print('pyversion:{}'.format(pyversion))
    time.sleep(5)
    ota_py_app()
    while True:
        print('httpota test')
        time.sleep(3)

(3) Output log

network register successed
csq: 31
pyversion:202203281800
------------------htp.pyfotaPy

# restart 
# Of the latest program log

2.hota.pac upgrade

Case description

  • The firmware pac If necessary, you can chat privately
  • Specific upgrade steps and py Upgrade similar

(1) obtain URL

Get pac After firmware package , The above method , take pac Package storage oss, Copy url.

(2) Function code

Will duplicate url Fill in code
main.py

import utime as time
from modem import net
import hota
import network
import sntp
from modem import info
import system

pyversion="202204281243"
g_connect_status = False

def on_4g_cb(args):
    global g_connect_status
    pdp = args[0]
    netwk_sta = args[1]
    if netwk_sta == 1:
        g_connect_status = True
    else:
        g_connect_status = False

def connect_network():
    global netw,on_4g_cb,g_connect_status
    netw = network.NetWorkClient()
    g_register_network = False
    if netw._stagecode is not None and netw._stagecode == 3 and netw._subcode == 1:
        g_register_network = True
    else:
        g_register_network = False
    if g_register_network:
        netw.on(1,on_4g_cb)
        netw.connect(None)
    else:
        print('network register failed')
    while True:
        if g_connect_status:
            print('network register successed')
            break
        time.sleep_ms(20)


#pac The upgrade package contains haas506 Of pac Differential upgrade package ,.pack File format 
def ota_pac_app():
    global ota_flag
    # initialization 
    hot = hota.client()
    # fill url
    #########################################################################
    ota_url = " Fill in the copied url Replace "
    #########################################################################
    if hot.fotaSys(ota_url) == 0:  #pac Firmware download succeeded , Restart the device 
        print('------------------htp.pacfotaPy')
        time.sleep_ms(1000)
        system.reset()
    else:
        print('pacota failed!')
   

if __name__ == '__main__':
    connect_network()# Connect to the network 
    pacversion = info.getDevFwVersion()
    print('---------------------------pacversion={}'.format(pacversion))
    sntp.settime()#SNTP Right time 
    print("csq:",net.getCsq())
    print('pyversion:{}'.format(pyversion))
    time.sleep(5)
    ota_pac_app()
    while True:
        print('httpota test')
        time.sleep(3)

(3) Output log

network register successed
csq: 31
pyversion:202203281800
------------------------------------htp.pacfotaPy
# restart 

(4) Check the firmware version

Run the following program , View the current firmware version .

from modem import info

print(" Device firmware version ",info.getDevFwVersion())

3.Class-hota

clientfotaPyfotaSys
initialization py Firmware upgrade pac Firmware upgrade

hota - Firmware upgrade module

  • Module function : be used for py Firmware upgrade , perhaps pac Firmware upgrade

client - Initialize firmware upgrade

  • The functionality : initialization , Create a firmware upgrade

  • The function prototype :

hota.client()

  • Parameter description : nothing

fotaPy - py Firmware upgrade

  • The functionality : py Firmware upgrade

  • The function prototype :

hota.fotaPy(url)

  • Parameter description :
Parameters explain
urlurl Is the firmware address , Support http, I won't support it https

fotaSys - pac Firmware upgrade

  • The functionality : pac Firmware upgrade

  • The function prototype :

hota.fotaSys(url)

  • Parameter description :
Parameters explain
urlurl Is the firmware address , Support http, I won't support it https
原网站

版权声明
本文为[Zhiyunfu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230512037191.html