当前位置:网站首页>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
边栏推荐
- Which is the best online collaboration product? Microsoft loop, notion, flowus
- Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture
- 面试官:并发编程实战会吗?(线程控制操作详解)
- MYSQL IFNULL使用功能
- hdu2377Bus Pass(构建更复杂的图+spfa)
- CLion配置visual studio(msvc)和JOM多核编译
- shell编程100例
- Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
- ODPs next map / reduce preparation
- Determine the best implementation of horizontal and vertical screens
猜你喜欢
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
leetcode:1139. 最大的以 1 为边界的正方形
XML建模
ArcGIS栅格重采样方法介绍
EN 438-7 laminated sheet products for building covering decoration - CE certification
五层网络协议
Golang(1)|从环境准备到快速上手
Pytoch practice -- MNIST dataset handwritten digit recognition
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
秋招将临 如何准备算法面试、回答算法面试题
随机推荐
Introduction to TS, constructor and its this, inheritance, abstract class and interface
驱动壳美国测试UL 2043 符合要求有哪些?
Write an interface based on flask
Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
Introduction of ArcGIS grid resampling method
int GetMonth( ) const throw( );后面的throw( )什么意思?
【日常训练--腾讯精选50】89. 格雷编码(看题解才会的)
面试官:并发编程实战会吗?(线程控制操作详解)
The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application
终端安全能力验证环境搭建和渗透测试记录
Mode - "Richter replacement principle"
vant 源码解析 event.ts 事件处理 全局函数 addEventListener详解
JS common method encapsulation
Determine the best implementation of horizontal and vertical screens
Simple getting started example of Web Service
Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
Clion-MinGW编译后的exe文件添加ico图标
EN 438-7 laminated sheet products for building covering decoration - CE certification
R language [data management]
Web Service简单入门示例