当前位置:网站首页>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
边栏推荐
- Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture
- Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
- Monorepo management methodology and dependency security
- Learning notes of SAS programming and data mining business case 19
- EasyExcel的读写操作
- 判断横竖屏的最佳实现
- Which securities company is better and which platform is safer for stock account opening
- MySQL deep paging optimization with tens of millions of data, and online failure is rejected!
- LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
- ViewRootImpl和WindowManagerService笔记
猜你喜欢

Add ICO icon to clion MinGW compiled EXE file

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

显示屏DIN 4102-1 Class B1防火测试要求

浅聊我和一些编程语言的缘分

Which is the best online collaboration product? Microsoft loop, notion, flowus

haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)

基于flask写一个接口

XML建模

秋招将临 如何准备算法面试、回答算法面试题

Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
随机推荐
SYSTEMd resolved enable debug log
模式-“里氏替换原则”
R语言【数据管理】
Prior knowledge of machine learning in probability theory (Part 1)
LeetCode: Distinct Subsequences [115]
Talk about my fate with some programming languages
Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
int GetMonth( ) const throw( );后面的throw( )什么意思?
PostGIS installation geographic information extension
Binary search
bazel是否有学习的必要
Pytoch practice -- MNIST dataset handwritten digit recognition
Test of incombustibility of cement adhesives BS 476-4
CLion配置visual studio(msvc)和JOM多核编译
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
Sequence alignment
What are the requirements of UL 2043 test for drive housing in the United States?
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
ts 之 属性的修饰符public、private、protect
ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图