当前位置:网站首页>Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
2022-07-05 21:09:00 【Zhiyunfu】
haas506 2.0 Development tutorial -ota - pac Firmware upgrade
ota - pac Firmware upgrade
Case description
- This case is used to upgrade the firmware version of the development board , for example : take haas506 - 2.0 Version upgrade to 2.2 edition .
- The case passed Alibaba cloud OTA upgrade , Upload < .bin > Format file , Realize remote hardware update .
- Be careful : Before upgrading, you need to confirm that the memory of the development board is sufficient .
1. Determine the development board memory
1、 View the development board memory
Open device manager , find USB port 0 Corresponding COM mouth ,

Open the serial port with the serial port tool , Input instruction ’ AT+FSLSTPART ’ , Check the memory size
1、 The number displayed is byte size , For example, remaining space 924500 Convert to memory size 924500/1024 → 902.83 KB 2、 The remaining space should be larger than the hardware upgrade package , Otherwise, the upgrade will fail

- If memory is insufficient, use instructions ’ AT+FSLSTFILE=“/data/pyamp” ' Check internal files ;
- Select extra files to use instructions ’
AT+FSDELFILE=“ File path ” ' Delete . for example ( AT+FSDELFILE=“/data/pyamp/abc.zip”)
Be careful : Please be careful when deleting content , Delete what can be deleted .

2. Internet of things platform development
Readers who use the Internet of things platform for the first time , You need to use the Internet of things platform function after opening the instance . You can also use free public instances for development , stay Alibaba cloud Internet of things platform in , In the upper left corner, choose ‘ East China 2- Shanghai ’, Click on ‘ Public examples ’, It can be opened .
1、 Platform product creation can refer to haas506 2.0 Development tutorial -aliyunIoT
3、 Device side development
- Readers who use the development board for the first time can follow haas5062.0 Development tutorial - Introduction Build development environment .
- Copy the following code to Visual Studio Code, Copy the product certificate to the corresponding location of the code .

main.py
# coding=utf-8
from driver import GPIO
import network
import ujson
import utime as time
import modem
from modem import info as infos
import modem
from aliyunIoT import Device
import ota
import kv
# Define the download and installation path of the upgrade package , among url,hash_type and hash It will be saved through server push
info = {
'url': '',
'store_path': '/data/pyamp/app.zip',
'install_path': '/data/pyamp/',
'length': 0,
'hash_type': '',
'hash': ''
}
# ota Message push receiving function
def on_trigger(data):
global info
# Save the information pushed by the server ota Information
info['url'] = data['url']
info['length'] = data['length']
info['module_name'] = data['module_name']
info['version'] = data['version']
info['hash'] = data['hash']
info['hash_type'] = data['hash_type']
# Start ota Package download
dl_data = {
}
dl_data['url'] = info['url']
dl_data['store_path'] = info['store_path']
ota.download(dl_data)
# ota Upgrade package download result callback function
def on_download(data):
global info
if data >= 0:
print('Ota download succeed')
# Start ota Packet verification
param = {
}
param['length'] = info['length']
param['store_path'] = info['store_path']
param['hash_type'] = info['hash_type']
param['hash'] = info['hash']
ota.verify(param)
# ota Upgrade package verification result callback function
def on_verify(data):
global info
print(data)
if data >= 0 :
print('Ota verify succeed')
print('Start Upgrade')
# Start ota upgrade
param = {
}
param['length'] = info['length']
param['store_path'] = info['store_path']
param['install_path'] = info['install_path']
ota.upgrade(param)
# ota Upgrade package result callback function
def on_upgrade(data):
if data >= 0 :
print('Ota succeed')
#ota After upgrading Restart the device
reboot()
# When iot Triggered when the device is connected to the Internet of things platform 'connect' event
def on_connect(data):
global module_name,default_ver,productKey,deviceName,deviceSecret,on_trigger,on_download,on_verify,on_upgrade
print('***** connect lp succeed****')
data_handle = {
}
data_handle['device_handle'] = device.getDeviceHandle()
# initialization ota service
ota.init(data_handle)
# ota Callback function registration
ota.on(1,on_trigger)
ota.on(2,on_download)
ota.on(3,on_verify)
ota.on(4,on_upgrade)
# When the connection is disconnected , Trigger 'disconnect' event
def on_disconnect():
print('linkkit is disconnected')
# When iot When setting the cloud distribution properties , Trigger 'props' event
def on_props(request):
print('clound req data is {}'.format(request))
# When iot Cloud call device service when , Trigger 'service' event
def on_service(id,request):
print('clound req id is {} , req is {}'.format(id,request))
# When the device follows iot When an error is encountered during platform communication , Trigger 'error' event
def on_error(err):
print('err msg is {} '.format(err))
# Callback function of network connection
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
# network connections
def connect_network():
global net,on_4g_cb,g_connect_status
#NetWorkClient This class is a singleton class , Realize the functions related to network management , Include initialization , Connected to the Internet , Status information, etc .
net = network.NetWorkClient()
g_register_network = False
if net._stagecode is not None and net._stagecode == 3 and net._subcode == 1:
g_register_network = True
else:
g_register_network = False
if g_register_network:
# Register the callback function of network connection on(self,id,func); 1 For connection ,func Callback function ;return 0 success
net.on(1,on_4g_cb)
net.connect(None)
net.connect({
'username' : '' ,
'password' : '',
'profileidx' :1,
'ipType' : 0,
'apn' :"CMNET",
'authType' : 1
})
else:
print('network reg failed')
while True:
if g_connect_status:
print('network connect success')
break
time.sleep_ms(20)
# Dynamically register callback functions
def on_dynreg_cb(data):
global deviceSecret,device_dyn_resigter_succed
deviceSecret = data
device_dyn_resigter_succed = True
# Connect to the Internet of things platform
def dyn_register_device(productKey,productSecret,deviceName):
global on_dynreg_cb,device,deviceSecret,device_dyn_resigter_succed
key = '_amp_customer_devicesecret'
deviceSecretdict = kv.get(key)
print("deviceSecretdict:",deviceSecretdict)
if isinstance(deviceSecretdict,str):
deviceSecret = deviceSecretdict
if deviceSecretdict is None or deviceSecret is None:
key_info = {
'productKey': productKey ,
'productSecret': productSecret ,
'deviceName': deviceName
}
# Dynamically register a device , Acquiring equipment deviceSecret
# Below if Prevent multiple registrations , If you have registered once , Restart the device and re register will get stuck ,
if not device_dyn_resigter_succed:
device.register(key_info,on_dynreg_cb)
if __name__ == '__main__':
ICCID=None
g_connect_status = False
net = None
device = None
deviceSecret = None
deviceName = None
# change productKey and productSecret
##############################
productKey = "a1laDtv9VrO"
productSecret = "bPbyllJ80mRX5PPy"
##############################
device_dyn_resigter_succed = False
# Define the module and version number to be upgraded
module_name = 'default'
default_ver = 'app-1.0.1'
# Connect to the network
connect_network()
# Acquiring equipment IMEI As deviceName Dynamic registration
deviceName = infos.getDevImei()
# Acquiring equipment ICCID
ICCID=modem.sim.getIccid()
# Initialize the Internet of things platform Device class , obtain device example
device = Device()
if deviceName is not None and len(deviceName) > 0 :
# Dynamically register a device
dyn_register_device(productKey,productSecret,deviceName)
else:
print("can not dynamic reg")
while deviceSecret is None:
time.sleep(0.2)
print('dynamic reg success:' + deviceSecret)
key_info = {
'region' : 'cn-shanghai' ,
'productKey': productKey ,
'deviceName': deviceName ,
'deviceSecret': deviceSecret ,
'keepaliveSec': 60,
}
# Print device information
print(key_info)
#device.ON_CONNECT Is the event ,on_connect It's an event handler / Callback function
device.on(device.ON_CONNECT,on_connect)
device.on(device.ON_DISCONNECT,on_disconnect)
device.on(device.ON_PROPS,on_props)
device.on(device.ON_SERVICE,on_service)
device.on(device.ON_ERROR,on_error)
device.connect(key_info)
for num in range(1, 5):
report_info = {
"device_handle": device.getDeviceHandle(),
"product_key": productKey,
"device_name": deviceName,
"module_name": 'default',
"version": default_ver
}
ret = ota.report(report_info)
time.sleep(1)
sys_version=infos.getDevFwVersion()
while True:
# print(' wait for Ota Upgrade package .....')
print('app_version:{} ;sys_version:{}'.format(default_ver,sys_version))
time.sleep_ms(1000)
board.json
{
"name": "haas506",
"version": "1.0.0",
"io": {
"cloud_led":{
"type":"GPIO",
"port": 1,
"dir": "output",
"pull":"pulldown"
},
"serial1":{
"type":"UART",
"port":0,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
},
"serial2":{
"type":"UART",
"port":1,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
},
"serial3":{
"type":"UART",
"port":2,
"dataWidth":8,
"baudRate":115200,
"stopBits":1,
"flowControl":"disable",
"parity":"none"
}
},
"debugLevel": "ERROR"
}
debugging , Confirm that the development board is successfully connected

4.ota - Hardware upgrade
1、 Platform side found Monitoring operation and maintenance →OTA upgrade → Add upgrade package , Fill in data , Click ok 
- No modules can be added

2、 Click on verification → Select the device that needs to be upgraded .
3、 Click on see , Wait for the upgrade to complete

4、 The development board will restart after the upgrade , The serial port tool will print the corresponding log, Version changed to 2.03
边栏推荐
- Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
- wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
- Golang (1) | from environmental preparation to quick start
- Introduction of ArcGIS grid resampling method
- 基于flask写一个接口
- Selenium finds the contents of B or P Tags
- Generics of TS
- leetcode:1139. The largest square bounded by 1
- Which securities company is better and which platform is safer for stock account opening
- ODPS 下一个map / reduce 准备
猜你喜欢

ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图
![[case] Application of positioning - Taobao rotation map](/img/2d/c834ce95a2c8e53a20e67fa2e99439.png)
[case] Application of positioning - Taobao rotation map

How to send samples when applying for BS 476-7 display? Is it the same as the display??

请查收.NET MAUI 的最新学习资源

The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application

2022-07-03-CKA-粉丝反馈最新情况

XML modeling

Using webassembly to operate excel on the browser side

【案例】元素的显示与隐藏的运用--元素遮罩

校招期间 准备面试算法岗位 该怎么做?
随机推荐
Viewrootimpl and windowmanagerservice notes
Modifiers of attributes of TS public, private, protect
ODPs next map / reduce preparation
CLion配置visual studio(msvc)和JOM多核编译
学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
示波器探头对信号源阻抗的影响
Learning robots have no way to start? Let me show you the current hot research directions of robots
Open source SPL eliminates tens of thousands of database intermediate tables
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
驱动壳美国测试UL 2043 符合要求有哪些?
水泥胶黏剂BS 476-4 不燃性测试
EN 438-7 laminated sheet products for building covering decoration - CE certification
Introduction to TS, constructor and its this, inheritance, abstract class and interface
leetcode:1755. 最接近目标值的子序列和
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
【日常训练】729. 我的日程安排表 I
AITM2-0002 12s或60s垂直燃烧试验
Aitm2-0002 12s or 60s vertical combustion test
序列联配Sequence Alignment