Updating sketch remotely for end user updates

robedney

Member
I've searched for answers about this but haven't been able to find what I'm looking for. I'm about to publish an open source Teensy with Sound Shield project, a bone conduction programmable hearing assist device. It's all done and working well. This is a low cost alternative for the hearing impaired. The initial sketch includes a 7 channel equalizer that permits entering anyone's audiogram (the results of a hearing test). As I'm anticipating many software upgrades, adding various features (noise reduction, compression, etc.) I'd like the end-user to be able to easily download and install a new sketch.

So, my questions are:

Has anyone built a web-based solution for this? Something that downloads the new sketch, reads the teensy plugged in via USB and upgrades???

Or, is there something simpler than using the Arduino IDE, which requires multiple steps (like board selection, port, etc.)?
Many of the folks who can make good use of this device will be older, not technically savvy and even have dexterity issues -- so I'm looking for the cleanest, easiest solution.

Thanks!!!
 
Chrome has a USB API that allows you to communicate with plugged in devices.
You can use the Teensyloader CLI code or other 3rd party flashers such as TyTools as a basis to develop a small app to find the Teensy, identify it, flash it and reboot it - thus, allowing a user to update the device without installing anything on their computer, directly from their browser

I'm sure Firefox and Safari have similar APIs too
 
Thanks, I'd found that article. Unfortunately I'm just not savvy enough to put this all together in a reasonable period of time. I just can't believe that those who build devices with Arduino and particularly Teensy don't have some way to easily allow end users to update. How about a downloadable executable? Does such a thing exist?
 
As mentioned above, one of the easier ways is to use the Teensyloader CLI tool. Then you can distribute the teensyloader EXE, your firmware file, and a batch file that calls the CLI tool with the proper parameters. Voila, it updates. Now, this is complicated by a few things. For one, everyone distributes the source code for the CLI tool but not the compiled executable. Well, I did publish my version in EXE format a couple of years ago: https://drive.google.com/file/d/1-tSnrXEjOte0xtQ9-XpZSLgJ7QP03TrL/view?usp=sharing

And, my version of the source code that compiled that is here: https://github.com/collin80/teensy_loader_cli

So, in theory that EXE could work for you. However, it's not signed so Windows will complain about it. Your users would need to be able to handle this. On Windows the process isn't terrible. Technically my version also works for Linux but I'll bet you don't have a lot of Linux users. I never did get soft reset working on MacOS. So, basically your users need to use Windows.

Here is the contents of the flash.bat file from my GEVCU7 Updater:
teensy_loader_cli.exe --mcu=TEENSY_MICROMOD -s -v -w GEVCU7.hex

So, that more or less shows you how you'd call the CLI tool to write your firmware.
 
I just can't believe that those who build devices with Arduino and particularly Teensy don't have some way to easily allow end users to update. How about a downloadable executable? Does such a thing exist?
The method that I use bypasses the Teensy bootloader entirely and has two components. One is a set of routines that you include in your Teensy sketch. This code is known as FlasherX and you can search for it on the forum. The other component is a custom EXE, for Windows in my case, that communicates with the Teensy, sending the new firmware as either Intel Hex records or as raw binary. The Teensy and the custom EXE must agree on a protocol to confirm that the entire new version has been correctly received and buffered by the Teensy, and when those conditions are met, the Teensy can erase its existing firmware, write the new firmware in its place, and reboot. The reason I use this method is to be able to do updates via UART or Ethernet, usually from within an application that a technician might use to configure the device. It works well for me, and others have used it successfully. One open question is whether it can work on a locked Teensy. For now it is only support for unlocked Teensy.
 
You didn't indicate which type of teensy this is. If it's a 4.1 then it's possible to create applications that can be upgraded by inserting an SD card with the new firmware. This is a variation on the system @joepasquariello outlined, you build the flasherX library into your application and it can then upgrade the system on the fly. You need some way to kick it off the upgrade and a way to get it a copy of the new firmware, that could be USB, serial, SD card, ethernet etc...

One of the down sides to this is that if power fails during an update it's possible for the system to end up with junk firmware. And since the firmware is what does the upgrade you can't recover without falling back to using teensyloader.
It it is also possible to create a basic bootloader system. e.g. I have a system that updates over ethernet, it's a large image and reflashing takes 30 seconds. If the power fails during this time you get corrupt main firmware. On boot the bootloader detects the firmware is invalid and instead runs a separate failsafe application, all this failsafe application does is allow updates to the main application. This way I can pull the power out mid upgrade and still recover the system over the network.
 
Web flasher got me intrigued - so started with something simple that can detect the device - will only list Teensy devices for now

First you request a USB device, then you list (it does that automatically on the first request)
Select USB Serial device from the promt.

This works only in Chrome and Edge
 
I only spent about 40 mins on this with ChatGPT
Had to refresh my memory on NodeJS project structures and how to deploy to Heroku.

I will keep playing around with it, but you can flash the teensy, just need to send the HalfKay command to get it into boot mode, then send the HEX over in chunks as the CLI does.

Will also incorporate a Serial Monitor
 
A Serial Monitor inclusion would be great for reviewing settings, etc. My problem is that I'm more of a designer than programmer, meaning that I can put stuff together, design a product and get it functioning with my limited programming skills -- but when you mention things like NodeJS, Heroku, HalfKay and CLI I'm off to Google :) This is an open source project with a budget measured in pennies. Here's a pick of the working prototype.
sparky_in_hand.jpg
box illustration.png
 
Back
Top