Sunday, September 3, 2017

60: Particle Photon Esoteric Hints 
(must previously have installed particle-cli)

1. When your Photon is not ready to accept a new flash: If (as I do) sometimes purposely load a program that is meant to run without the cloud then you can have a problem when you need to flash new software -- because the Photon is not connected. The following info is in Particle Docs, but not all in one place.

a. To get back to "breathing cyan" so you can flash:

Hold down RESET and SETUP, release RESET and continue to hold down SETUP while the main status LED blinks magenta until it blinks yellow, then release.


b. Then load a sketch that exists as part of the particle-cli package. In Terminal app on Mac OS:

$ particle flash --usb tinker # Photon connected to USB (of course)

It's not that you want to use tinker. It's just harmless software that allows you to then flash your own code.

2. What if you want to set up a Photon for a wifi network that is elsewhere?

a. First, the device must be in "Listening Mode". To do this hold down the SETUP until the RGB LED blinks blue.

b. Of course the Photon must be plugged to a USB port. Here's the command:

$ particle setup --usb
(output back: blah, blah)
Claim code set. Now setting up Wi-Fi
...
Attempting to configure Wi-Fi on /dev/cu.XYZ
? SSID name-of-the-network
? Security Type WPA2 (selected, not typed)
? Cipher Type AES+TKIP (ditto)
? Wi-Fi Password your-pw
Done! Your device should now restart.
! It doesn't look like your Photon has made it to the cloud yet.
? What would you like to do? Check again to see if the Photon has connected
... (took a while)
> It looks like your Photon has made it happily to the cloud!

And so you've made it (with luck).

3. What about where several Photons are running the same program but you need to identify them individually? You could do this messily by using a C++ "#define" statement -- a 1 line source change for each Photon: pretty certain to lead to errors. A better way would be to get the Particle cloud to tell your program the device name that you gave the Photon. It would be nice if Particle provided a call like: "Particle.deviceName()" that returned the name as a char array. The good news is that you can get the name but it is not so straightforward. Here's code that works:

char DevName[20];
...
void getname(const char *topic, const char *data) {
    strcpy(DevName, data);
}

void setup() {
    ...
    Particle.subscribe("spark/device/name", getname);
    Particle.publish("spark/device/name");
    delay(5000); // DevName won't get filled in for several seconds
    ...
}

Note that while Particle lost use of the name "spark" a couple years ago they have never changed all of the sparks to particles. Not nice, Particle!

No comments:

Post a Comment