Generation of micropython image with frozen modules

This commit is contained in:
Lukas Schuller
2019-02-25 06:54:45 +01:00
committed by Lukas Schuller
parent 2bf3839d4b
commit 19178e0700
4 changed files with 140 additions and 9 deletions

View File

@@ -118,7 +118,7 @@ async def update_app(mqtt, name):
version_sub.unsubscribe()
if current_app != name or current_version != latest:
mqtt.log('installed: {} v{}, want {} v{}'.format(
mqtt.log('Current: {} v{}, want {} v{}'.format(
current_app, current_version, name, latest))
try:
# if the wrong app is installed, we remove it and reboot to
@@ -134,6 +134,9 @@ async def update_app(mqtt, name):
app_size = await sub.wait_for_value()
sub.unsubscribe()
mqtt.log('Installed {} v{}, {}b'.format(name, latest, app_size))
install_dependencies(mqtt)
return True
except Exception as e:
mqtt.log('Update error:', e)
@@ -142,6 +145,37 @@ async def update_app(mqtt, name):
return False
def install_dependencies(mqtt):
import app
try:
deps = app.DEPENDENCIES
mqtt.log('Installing {} dependencies'.format(len(deps)))
for d in deps:
gc.collect()
if len(d) == 1: # upip package
mqtt.log(' - upip package {}'.format(d))
import upip
upip.install(d)
elif len(d) == 2: # file path, source URL
path, url = d
mqtt.log(' - dependency {} from {}'.format(path, url))
gc.collect()
import upip
f = upip.url_open(url)
buf = bytearray(128)
view = memoryview(buf)
with open(path, 'wb') as outfile:
while True:
n_read = f.readinto(buf)
if n_read == 0:
break
outfile.write(view[:n_read])
gc.collect()
except Exception as e:
mqtt.log('Error installing dependencies: ', e)
def deepsleep(duration_ms):
utime.sleep_ms(200)
# configure RTC.ALARM0 to be able to wake the device