程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Breaking away from Haas studio to debug the old version of haas100 Python light application project

編輯:Python

HaaS The official in the HaaS Studio 2.0 After that, the pair of HaaS100 Support for , except API Significant changes to , The original HaaS100 The project code can not be changed from HaaS Studio 2.0 The above version deployment has been uploaded to the board . It is not recommended for new projects HaaS100, This article is just a record , So as not to waste time in the future . After all, I still have 3 block HaaS100 Development board …

I also need to use... For some reasons HaaS100 Make a temporary thing , So how to deploy the code to the board in this case is a problem .

First, directly HaaS Studio 2.0+ It is impossible to open the version and upload the old project . So I will HaaS Studio Go back to the old version of the project you created at that time , Then from the old version HaaS Studio Create a new project , Copy and paste the original code into the new project , from HaaS Studio There are still a lot of errors when clicking upload on the shortcut toolbar at the bottom .

Then I thought about the old project development , I actually did a few command lines to improve efficiency alias To package and upload the code . So I found out the alias, It solves the problem that the code is packaged and uploaded to HaaS100 The problem of .

First of all, we should analyze HaaS100 Python The general process of light application project code deployment . This process can actually be changed from the old version of HaaS Studio The terminal window sees . It is basically the following process :

  • Activate miniconda Virtual environment for
  • The project files are packaged in upgrade/pyamp.zip
  • adopt .utility/python/transymodem.py The script will pyamp.zip Transfer to the board

Let's complete these steps manually :

  1. Activate miniconda A virtual environment :
    Create a new terminal window , Enter the following command :
source ~/.aliot/miniconda3/bin/activate ~/.aliot/miniconda3/envs/_aos_env ; export PATH="~/.aliot/miniconda3/envs/_aos_env:~/.aliot/miniconda3/envs/_aos_env/bin:$PATH" ; echo "=> set miniconda env finished."
  1. Package files
    I created a python Script pack.py, It only needs python pack.py Project name You can finish packing , The project folder in the script needs to be modified by itself , You can also modify the code yourself , Change the parameter to the absolute path of the project .
    The processing of audio resource files should be modified as appropriate .
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os,sys,time
from zipfile import *
import zipfile
filepath = '~/haas100/upgrade/pyamp.zip'
filepath = os.path.expanduser(filepath)
if os.path.exists(filepath):
os.remove(filepath)
print(' Delete old files ')
project_name = sys.argv[1]
startdir = "~/haas100/solutions/{}".format(project_name)
startdir = os.path.expanduser(startdir)
print(' Package files %s'%startdir)
def packfile():
global startdir
f = zipfile.ZipFile(filepath,'w',zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(startdir):
for filename in filenames:
if (filename == 'main.py' or filename == 'board.json'):
f.write(os.path.join(dirpath, filename), arcname=filename)
if (filename == "connected.wav" or filename == "poweron.wav" or filename == "aliyunconnected.mp3"):
f.write(os.path.join(dirpath, filename), arcname='resource/{}'.format(filename))
f.close()
def zipDir(dirpath,outFullName):
zip = zipfile.ZipFile(outFullName,"w",zipfile.ZIP_DEFLATED)
for path,dirnames,filenames in os.walk(dirpath):
# Remove the target and the path , Only the files and folders under the target folder are compressed 
fpath = path.replace(dirpath,'')
for filename in filenames:
if (filename == 'main.py' or filename == 'board.json' or filename == "connected.wav" or filename == "poweron.wav" or filename == "aliyunconnected.mp3"):
zip.write(os.path.join(path,filename),os.path.join(fpath,filename))
zip.close()
def TimeStampToTime(timestamp):
timeStruct = time.localtime(timestamp)
return time.strftime('%Y-%m-%d %H:%M:%S',timeStruct)
def get_FileSize(filePath):
# filePath = filePath.encode('UTF-8')
fsize = os.path.getsize(filePath)
print('fsize:%d'%fsize)
fsize = fsize/float(1024)
return round(fsize,2)
def get_FileCreateTime(filePath):
# filePath = filePath.encode('UTF-8')
t = os.path.getctime(filePath)
return TimeStampToTime(t)
# Basic information of output file 
packfile()
print(' File path :',filepath)
print(" file size :%d KB"%get_FileSize(filepath),end=' ')
print(" Creation time :",get_FileCreateTime(filepath))

Running effect :

3. Deployment upload pyamp.zip file .
Here we need to call Old project Under folder .utility/python/transymodem.py file . Please follow your own path Old project The folder can be modified by itself , The serial port should also be modified to the serial port on your own device . For this example macOS Recognized serial port name .

python ~/workspace/aos-works/.utility/python/transymodem.py -d /dev/cu.usbserial-1410 -b 1500000 /Users/simonliu/haas100/upgrade/pyamp.zip

Just reset the board when you see the prompt .

After successful upload , A new version of HaaS Studio Serial port tool View , Or directly from the command line :

python -m serial.tools.miniterm /dev/cu.usbserial-1410 1500000

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved