Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement firmware update functionality #153

Merged
merged 8 commits into from
Feb 19, 2018
Merged

Implement firmware update functionality #153

merged 8 commits into from
Feb 19, 2018

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented Jan 3, 2018

Add ability to perform firmware updates on the device.
Works either by passing an URL with md5sum for the firmware image,
or alternatively by passing a local filename.
In case of the input is a local filename, its md5sum will be calculated automatically,
and the update will be delivered by the built-in web server.

mirobo update_firmware http://10.10.10.150/v11_003094.pkg <md5sum>

or

mirobo update_firmware v11_003094.pkg

The install_sound functionality is also extended to use the builtin web-server class, so installing sound packages is as simple as calling mirobo install_sound <soundfile.pkg>.

For more details & archive of firmware updates see https://github.com/dgiese/dustcloud .

Thanks for exploring the device in-depth goes to the dustcloud project,
which also describes how to build own, custom firmwares.

click.echo("Using %s (md5: %s)" % (file, md5))
else:
pass
#Updater()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block comment should start with '# '

miio/updater.py Outdated

if __name__ == "__main__":
import netifaces
ifaces_without_lo = [x for x in netifaces.interfaces() if not x.startswith("lo")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (85 > 79 characters)

@coveralls
Copy link

coveralls commented Jan 3, 2018

Coverage Status

Coverage decreased (-1.9%) to 65.824% when pulling 791768f on add_updater into a365e17 on master.

miio/updater.py Outdated
self.server.timeout = 10

with open(file, 'rb') as f:
self.payload = f.read()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be memory inefficient

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't matter here, as the file needs to be read at some point for sending it to the client. The code is however incomplete, there is currently no way to tell interface/IP to use for the url (e.g. when one has multiple network interfaces as I do). I will have to look more into it in a week when I'll be able to test it on the device.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point i mean is you should read file by chunks and feed data to hash, reading hundreds megabytes to memory at once is a bad idea.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean, but at some the file has to be read (again) for sending over the wire to the device. I'll look into that though, thanks :-)

@CODeRUS
Copy link

CODeRUS commented Jan 6, 2018

btw, why own server? why handle_request so bad?

@rytilahti
Copy link
Owner Author

@CODeRUS I wanted to have it so that one can simply point it to any file (and not to expose the contents over HTTP), although I think changing to the source directory and launching the server there would be fine too.

Thanks for exploring the device in-depth goes to the dustcloud project,
which also describes how to build own, custom firmwares.
miio/updater.py Outdated
ifaces_without_lo = [x for x in netifaces.interfaces() if not x.startswith("lo")]
# print(ifaces_without_lo)
logging.basicConfig(level=logging.DEBUG)
upd = Updater("/tmp/test")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'Updater'

@@ -522,7 +522,13 @@ def error(self) -> int:
@property
def is_installing(self) -> bool:
"""True if install is in progress."""
return self.sid != 0 and self.progress < 100 and self.error == 0
return self.state == SoundInstallState.Downloading or \
self.state == SoundInstallState.Installing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

try:
state = vac.update_state()
progress = vac.update_progress()
except: # we may not get our messages through during upload

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment

if update_state == UpdateState.Downloading:
click.echo("Update progress: %s" % vac.update_progress())

@cli.command()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

@@ -480,6 +504,67 @@ def configure_wifi(vac: miio.Vacuum, ssid: str, password: str,
click.echo("Configuring wifi to SSID: %s" % ssid)
click.echo(vac.configure_wifi(ssid, password, uid, timezone))

@cli.command()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

@@ -522,7 +522,13 @@ def error(self) -> int:
@property
def is_installing(self) -> bool:
"""True if install is in progress."""
return self.sid != 0 and self.progress < 100 and self.error == 0
return self.state == SoundInstallState.Downloading or \
self.state == SoundInstallState.Installing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

try:
state = vac.update_state()
progress = vac.update_progress()
except: # we may not get our messages through during upload

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least two spaces before inline comment

if update_state == UpdateState.Downloading:
click.echo("Update progress: %s" % vac.update_progress())

@cli.command()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

@@ -480,6 +504,67 @@ def configure_wifi(vac: miio.Vacuum, ssid: str, password: str,
click.echo("Configuring wifi to SSID: %s" % ssid)
click.echo(vac.configure_wifi(ssid, password, uid, timezone))

@cli.command()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

@rytilahti rytilahti changed the title WIP: Implement firmware update functionality Implement firmware update functionality Feb 17, 2018
@rytilahti
Copy link
Owner Author

I think this is pretty much done and ready to be tested now. The code could be made cleaner, but that can be done later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants