How to set photon wifi credentials without user intervention (USB only)?

Hi,
in my current setup, I need to change the WiFi credentials of >5 photons reliably at the same time and without user interaction, but they are all attached to the USB at that point.

I tried serial communication but I have no luck getting it reliably to work. For example, when the firmware is in the process of (unsuccessfully) acquiring the network, serialEvent() is called not regularly and even crashes…

The most fail-safe way IMO would be to bypass any firmware code all together and write the new credentials directly to memory via the dfu-util. However, I have not found a way to do that.

Any ideas?
Thanks

I have not tested this, but I’m thinking something along the lines of:

Option 1:
Clear the Wi-Fi credentials if necessary. I think this would probably require flashing some code to the Photon with a WiFi.clearCredentials() call. Tell the Photon to reboot. Now it will go into listening mode.
Connect via USB serial to the Photon, just control the serial interface directly to issue the w command and then send all of the other characters necessary to set the WiFi credentials.

Option 2:
Connect briefly by serial to the USB serial port at 14400 baud. This will force the Photon into DFU mode.
Flash a user firmware load that has the WiFi credentials hardcoded in it and set using Wifi.setCredentials() using CLI or dfu-util directly.
Wait for it to set the credentials.
Connect briefly by serial to the USB serial port at 14400 baud. This will force the Photon into DFU mode.
Flash normal firmware using CLI or dfu-util directly.

Thank you. The clearCredentials) by firmware upload is a good idea. I already got it to work.
Here is my recipe

  1. Issue serial connection to force Photon in dfu mode (very reliable), e.g.

    stty -d /dev/tty.usbmodem1411 14400; sleep 1

  2. Upload simplest firmware which clears the credentials.

    dfu-util -d 0x2B04:0xD006 -a 0 -s 0x80A0000:leave -D photon-reset.dfu

  3. Wait a few seconds for firmware to run

  4. Again issue serial connection to force Photon in dfu mode

  5. Upload production firmware

    dfu-util -d 0x2B04:0xD006 -a 0 -s 0x80A0000:leave -D photon-prod.dfu

  6. Wait a few seconds for firmware to run

  7. Send new wifi credentials via serial connection

1 Like

If you are using a local build, there is a simpler way w/o the need to upload a special reset version.
in

system/src/system_update.cpp::system_lineCodingBitRateHandler(uint32_t bitrate)

you can easily introduce your own action in response to a specific serial baud rate.
I just added

if (bitrate == 38400) {
    network.connect_cancel(true);
    network.clear_credentials();
    System.reset();
}

After the reset, the system is in listening mode and you can send the new credentials over serial.