Set APN over USB

Hello

Just wondering if there is a way to set the APN via USB e.g. CLI?
I realise there is a way to set this in firmware:
https://docs.particle.io/reference/firmware/electron/#setcredentials-

But is there a way to let a customer set their APN without having to edit, recompile and program the firmware?

This is possible since you can call the respective functions anywhere in code.
You just should make sure to have the module on but not connected/connecting when you do that.
You could then write the creds to EEPROM and use these as startup settings.
But your customer also has to set the keepAlive() accordingly and you’d need to store that too.

I’ve done that successfully.
My workflow is:

  1. check for valid EEPROM data
    a. if not available skip APN setting to revert to Particle settings, or use hardcoded 3rd party settings
    b. if yes, use stored settings
  2. when receiving a command to enter new creds, store provided data in EEPROM and System.reset() to start from 1 again
1 Like

Thanks @ScruffR!

Using this workflow, do you (can you) program the APN into the EEPROM over USB via DFU?

Too many acronyms there!

I’d like customers to be able to set the APN relatively simply without downloading any software ideally, apart from perhaps a CLI tool.

Cheers

That’s possible, but I haven’t done that.
I usually have an EEPROM struct with a magic number and a checksum to check if the values are valid and if that’s not the case revert to a known good state in code.
That way you are even safe in case of EEPROM corruptions and it provides an easy “factory reset” path too - just invalidate the checksum, write that back to EEPROM and on next reboot the defaults will be re-applied.
With the DFU method you only got the first time data in place, but the rest would have to be implemented anyway too.

My method only requires any serial terminal to “inject” the data, unfortunately CLI does not (yet) support serial data entry.
But one easy command to “upload” the settings via USB serial would be a simple text file that is sent to the respective COM port with native OS commands.

1 Like

Most of the time, the Serial/USB port is used for debugging OUTPUT. It is easy to write a command parser to receive commands from the port to do local settings on an Electron. You could even write your code so that once the settings have been completed and verified, the command parser is disabled for security. I use the COMMAND-PARSER library from the IDE to make things super easy. :wink:

2 Likes