Software apps and online services
There are many ways for Particle Photons to interact with each other. Even more ways for other devices and apps to interact with Photons through the Particle Cloud. To explore these capabilities, I created a useless machine.
My useless machine is made up of two Photons. Photon 1 “falafel_1” has a photo resistor and a green LED. Photon 2 “falafel_2” also has a photo resistor and a green LED. However, Photon 2 also has a servo motor and a second red LED. The servo motor is mounted so that when it is rotated to 90 degrees, it covers both photo resistors.
The way the machine operates is that Photon 1 wants its photo resistor to be covered up. When Photon 1 detects that its photo resistor is uncovered, it triggers an event called “NeedCover” to the Particle Cloud and flashes its green LED. Photon 2 is subscribed to this event. When Photon 2 detects that the event has been triggered, it flashes its green LED and rotates the servo motor to 90 degrees. This covers Photon 1’s photo resistor. However, Photon 2 wants its photo resistor to be uncovered. When it detects that its photo resistor is covered, it will flash its red LED and rotate the servo motor to 0 degrees. Thus the useless cycle begins.
In addition to the firmware for both Photon 1 and Photon 2, I also wrote a simple UWA to interact with both Photons. You can download the entire set of source code here.
To get any of the firmware and software to work together, you need to get the device ID for both Photons and get your Access Token, both of which can be obtained from your particle build window. Select devices and expand each one to record your device IDs. Select settings to view your Access Token. The code section below details where you need to update these values.
The UWA app has the following capabilities.
- Opens a Particle event stream to the event “NeedCover” on Photon 1.
- Reads a Particle variable from Photon 1 that returns the value read from Photon 1’s photo resistor.
- Calls a Particle function on Photon 2 called “position”. Calling this function can rotate the servo motor to 0 or 90 degrees by passing the values “0” or “90” as a parameter and disables the useless function on Photon 2. This function can also re-enable the useless function on Photon 2 with passing the value “Go” as a parameter.
You can see a video of the useless machine and the UWA below.
This project demonstrates the ability of multiple Photons to communicate with each other through the Particle Cloud and the ability of an external application to use the Particle Cloud to receive data from a Photon by way of a Particle event stream or a Particle variable. It also shows how an external application can use the Particle Cloud to call a Particle function on a Photon. Never underestimate the power of a useless machine.