Skip to content

Commit 27e9284

Browse files
committed
Add example on how to update
1 parent fb937e4 commit 27e9284

File tree

6 files changed

+61
-3
lines changed

6 files changed

+61
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
secrets.py
File renamed without changes.

main/ota_updater.py renamed to app/ota_updater.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _check_for_new_version(self):
108108
return (current_version, latest_version)
109109

110110
def _create_new_version_file(self, latest_version):
111-
os.mkdir(self.modulepath(self.new_version_dir))
111+
self.mkdir(self.modulepath(self.new_version_dir))
112112
with open(self.modulepath(self.new_version_dir + '/.version'), 'w') as versionfile:
113113
versionfile.write(latest_version)
114114
versionfile.close()
@@ -134,15 +134,17 @@ def _download_new_version(self, version):
134134
def _download_all_files(self, version, sub_dir=''):
135135
root_url = self.github_repo + '/contents/' + self.github_src_dir + self.main_dir + sub_dir
136136
gc.collect()
137+
print('fileListUrl', root_url + '?ref=refs/tags/' + version)
137138
file_list = self.http_client.get(root_url + '?ref=refs/tags/' + version)
138139
for file in file_list.json():
140+
print('test', file)
139141
path = self.modulepath(self.new_version_dir + '/' + file['path'].replace(self.main_dir + '/', '').replace(self.github_src_dir, ''))
140142
if file['type'] == 'file':
141143
download_url = file['download_url']
142144
self._download_file(download_url.replace('refs/tags/', ''), path)
143145
elif file['type'] == 'dir':
144146
print('Creating dir', path)
145-
os.mkdir(path)
147+
self.mkdir(path)
146148
self._download_all_files(version, sub_dir + '/' + file['name'])
147149

148150
file_list.close()
@@ -223,9 +225,17 @@ def _mk_dirs(self, path:str):
223225

224226
pathToCreate = ''
225227
for x in paths:
226-
os.mkdir(pathToCreate + x)
228+
self.mkdir(pathToCreate + x)
227229
pathToCreate = pathToCreate + x + '/'
228230

231+
# different micropython versions act differently when directory already exists
232+
def mkdir(self, path:str):
233+
try:
234+
os.mkdir(path)
235+
except OSError as exc:
236+
if exc.args[0] == 17:
237+
pass
238+
229239

230240
def modulepath(self, path):
231241
return self.module + '/' + path if self.module else path

app/start.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('Version 1 installed using USB')

main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
def connectToWifiAndUpdate():
4+
import network, gc, app.secrets as secrets
5+
from app.ota_updater import OTAUpdater
6+
7+
sta_if = network.WLAN(network.STA_IF)
8+
if not sta_if.isconnected():
9+
print('connecting to network...')
10+
sta_if.active(True)
11+
sta_if.connect(secrets.WIFI_SSID, secrets.WIFI_PASSWORD)
12+
while not sta_if.isconnected():
13+
pass
14+
print('network config:', sta_if.ifconfig())
15+
otaUpdater = OTAUpdater('https://github.com/rdehuyss/micropython-ota-updater', main_dir='app', secrets_file="secrets.py")
16+
otaUpdater.install_update_if_available()
17+
del(otaUpdater)
18+
gc.collect()
19+
20+
def startApp():
21+
import app.start
22+
23+
24+
connectToWifiAndUpdate()
25+
startApp()

pymakr.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"address": "/dev/ttyUSB0",
3+
"username": "micro",
4+
"password": "python",
5+
"sync_folder": "",
6+
"open_on_start": true,
7+
"safe_boot_on_upload": false,
8+
"py_ignore": [
9+
"pymakr.conf",
10+
".vscode",
11+
".gitignore",
12+
".git",
13+
"project.pymakr",
14+
"env",
15+
"venv",
16+
"M5Stack_MicroPython",
17+
"__pycache__",
18+
"py"
19+
],
20+
"fast_upload": false
21+
}

0 commit comments

Comments
 (0)