mcumgr-web icon indicating copy to clipboard operation
mcumgr-web copied to clipboard

WebUSB, Web Serial & WebHID support

Open beriberikix opened this issue 3 years ago • 13 comments

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.

beriberikix avatar Jan 13 '22 18:01 beriberikix

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.

utzig avatar Jan 13 '22 18:01 utzig

Yup, and it works pretty well! CC @reillyeon

beriberikix avatar Jan 13 '22 18:01 beriberikix

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

boogie avatar Jan 13 '22 20:01 boogie

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.

boogie avatar Jan 15 '22 15:01 boogie

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.

devanlai avatar Feb 26 '22 23:02 devanlai

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 avatar Feb 27 '22 01:02 beriberikix

Nothing noteworthy in chrome://device-log. Screen Shot 2022-02-26 at 5 10 10 PM

beriberikix avatar Feb 27 '22 01:02 beriberikix

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.

devanlai avatar Feb 27 '22 01:02 devanlai

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

beriberikix avatar Feb 27 '22 02:02 beriberikix

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 avatar Feb 27 '22 03:02 devanlai

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.

devanlai avatar Feb 27 '22 03:02 devanlai

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.

boogie avatar Feb 27 '22 10:02 boogie

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.

devanlai avatar Feb 27 '22 18:02 devanlai