boogie / mcumgr-web

MCU Manager for browsers
https://boogie.github.io/mcumgr-web
MIT License
34 stars 16 forks source link

WebUSB, Web Serial & WebHID support #2

Open beriberikix opened 2 years ago

beriberikix commented 2 years ago

First off, this is an awesome project! We're going to try it with a Zephyr-based project.

Have you looked at supporting WebUSB, Web Serial and/or WebHID? That would expand the utility of this library to devices that don't have BT connectivity.

utzig commented 2 years ago

Have you looked at supporting WebUSB, Web Serial and/or WebHID? That would expand the utility of this library to devices that don't have BT connectivity.

Haha, I didn't know "Web Serial" was a thing, I might take a look at that one.

beriberikix commented 2 years ago

Yup, and it works pretty well! CC @reillyeon

boogie commented 2 years ago

That would be awesome to add. I don't have a device I can test it with, but I'm ready to help.

boogie commented 2 years ago

Contact me if you would like to add USB functionality. I'm very interested in implementing it, but I need your help about setting up a development environment for it.

devanlai commented 2 years ago

I decided to finally take a stab at building something with WebSerial. I've cobbled together a proof-of-concept branch for the mcumgr SMP over console transport on my branch here (demo page). I only have an mcuboot device to test with, but listing images and uploading seem to work okay.

I believe I'm handling the mcumgr serial framing correctly, but I'm pretty sure my first stab at the WebSerial portion could use some refinement.

beriberikix commented 2 years ago

So cool! I tested it with a known-good MCUBoot image and device (ESP32, docs here.) Uploading never started. Is there anything I can capture to help troubleshoot?

Screen Shot 2022-02-26 at 5 01 37 PM
beriberikix commented 2 years ago

Nothing noteworthy in chrome://device-log.

Screen Shot 2022-02-26 at 5 10 10 PM
devanlai commented 2 years ago

Hmm, no obvious errors / unexpected exceptions. My guess would be that either the device never responded for some reason, or else the first upload message never got sent for some reason.

beriberikix commented 2 years ago

Actually, this might be user error. What device were you using? Espressif devices are "special."

devanlai commented 2 years ago

I'm testing on a non-mainline device with the mcuboot single-slot serial recovery mode, which uses a subset of the normal mcumgr commands. I'm sure it's possible to enable the mcumgr shell/console transport in normal application builds, I just haven't quite figured out the right configuration yet.

devanlai commented 2 years ago

From some further testing with a frankenstein mashup of the shell sample and the smp_svr sample, I can get an ESP32 to at least respond with MGMT_ERR_ENOTSUP (8) if I change the image status / list command to encode an empty map instead of a null payload (to closer match what the mcumgr cli does), but no luck getting non-error responses to even the echo command, either with the mcumgr cli or with webserial.

I'll have to do some further poking tomorrow and probably switch to some hardware that I can connect to with the debugger to see why it's always failing to handle the commands even though I'm pretty sure the config is correct.

boogie commented 2 years ago

Wow, I really glad about your contribution. I won't be able to test it short term, but tell me if you think it's "ready", and we can merge it.

devanlai commented 2 years ago

I guess I didn't mash things up the right way, but it turns out no modifications to the Zephyr examples were really needed.

The right sequence of commands to build and flash an mcuboot-compatible image for the ESP32 with a multiplexed command shell / mcumgr SMP pipe is:

west build -b esp32 -- -DOVERLAY_CONFIG="overlay-shell.conf"
west sign -t imgtool -- --key path\to\your\mcuboot\signing-key\root-rsa-2048.pem
west flash

That image will respond to echo commands without any modifications. With the tweak to send an empty map instead of an empty payload in the image state command, it responds as expected. I was able to upload an image, mark it for test, manually reset to install it (maybe the mcumgr reset command would have sufficed; I got impatient) and confirm it after it swapped the slots.