Particle-CLI add command line arguments for flash

I’m trying to flash the firmware with wifi credentials. However I do not want to store them in the actual file i.e in the .ino file. WiFi.setCredentials(<SSID>, <PASSWORD>

I was looking to pass the credentials via command line. I found the below pull request for serial. But I can’t figure out how to to do it via usb i.e. $particle flash --usb <FIRMWARE.bin>

https://github.com/particle-iot/particle-cli/pull/260

Any help would be appreciated.

I just ran the help command for serial wifi:

$ particle help serial wifi

Configure Wi-Fi credentials over serial
Usage: particle serial wifi [options]

Global Options:
  -v, --verbose  Increases how much logging to display                   [count]
  -q, --quiet    Decreases how much logging to display                   [count]

Options:
  --file  Take the credentials from a JSON file instead of prompting for them
                                                                        [string]
  --port  Use this serial port instead of auto-detecting. Useful if there are
          more than 1 connected device                                  [string]

Examples:
  particle serial wifi                      Prompt for Wi-Fi credentials and
                                            send them to a device over serial
  particle serial wifi --file               Read Wi-Fi credentials from
  credentials.json                          credentials.json and send them to a
                                            device over serial

The JSON file for passing Wi-Fi credentials should look like this:
{
  "network": "my_ssid",
  "security": "WPA2_AES",
  "password": "my_password"
}

The security property can be NONE, WEP, WPA2_AES, WPA2_TKIP, WPA2_AES+TKIP,
WPA_AES, WPA_TKIP, WPA_AES+TKIP.
For enterprise Wi-Fi, set security to WPA_802.1x or WPA2_802.1x and provide the
eap, username, outer_identity, client_certificate, private_key and root_ca
properties.
2 Likes

Hi @nrobinson2000,

I was trying to flash my photon via --usb, because --serial does not work (hence the credentials question) (I’m on a MacOs running latest particle-cli and node)

When I flash via serial I get an error message
particle-bed-button-ro $particle flash --verbose --serial photon_1.2.1_firmware.bin

sending file: photon_1.2.1_firmware_1564009861497.bin
Error writing firmware: unknown message
VError: Error writing firmware: unknown message
    at Promise.resolve.then.then.then.then.then.catch.err (/Users/dvadmin/.particle/node_modules/particle-cli/dist/cmd/serial.js:485:13)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
caused by: Error: unknown message
    at ensureError (/Users/dvadmin/.particle/node_modules/particle-cli/dist/lib/utilities.js:670:14)
    at Promise.resolve.then.then.then.then.then.catch.err (/Users/dvadmin/.particle/node_modules/particle-cli/dist/cmd/serial.js:485:24)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

When I do particle serial inspect i get this though:

Platform: 6 - Photon
Modules
  Bootloader module #0 - version 311, main location, 16384 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #1 - version 1213, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #2 - version 204
  System module #2 - version 1213, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #1 - version 1213
      Bootloader module #0 - version 311
  User module #1 - version 6, main location, 131072 bytes max size
    UUID: B2E864396E989D4641C5172EEB75268F600D058BB43CF12EFB0328921EE778EB
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #2 - version 1213

If I could get it to work with --serial, great …but something tells me i won’t be able to

When using particle serial wifi or even just a serial terminal sending w you are not flashing a firmware binary nor would you need to in order to set the WiFi credentials.
When you can successfully run particle serial inspect you can most likely also use particle serial wifi - why not just try it?

1 Like

@ScruffR . I see what you are saying. I thought I could do it in a one step process. Not a 2 step process.

Thanks for you help!