During the last studio you should have configured the Photon to control an RGB LED. Today we will extend this work to include the use of Particle’s Cloud-based services.
The objectives of today’s Studio are:
Please take your role seriously. When you get your role, review the responsibilities and make sure you follow through on them.
Groups of three will be allowed if:
In groups of three the Manager must also take on the responsibilities of the Spokesperson.
As in the previous studios, all group members will need to be in a GitHub group (and repository)
The link for this studio is: https://classroom.github.com/g/iA-K169k
Today the Recorder, Technician, and the Spokesperson will want to be able to work with the repository (i.e., it should be on at least two computers). The Technician will be working with the Photon (C++).
The Recorder should update
process/Roles.md to record everyone’s roles for this studio (use full names). In addition, the Recorder should take notes about the interaction of the overall session. Be sure to pull/merge/commit/push at the end of the day!
Today you will be doing the bulk of recording answers to questions. Read the questions in
process/Debrief.md to the group and the group should come to a consensus for each. Be sure to enter the responses. Be sure to pull/merge/commit/push at the end of the day!
The Technician will be programming the Photon and using the cloud functions. Consequently their computer will need to be logged into the account for the Photon being used for testing. (Particle Desktop will need to be logged in)
You will be managing the code for today’s studio. Download the repository, but don’t open it in Particle Dev. Instead open Particle Dev, close any open windows/projects. Create each mini-project listed below in the designated folder within the repository directory. Be sure to pull/merge/commit/push at the end of the day!
rgbFade()from last studio. It will be needed at the end of this studio.
The Technician should create a new sketch named
cloudConnectedLamp in your repo folder.
Create a sketch that:
booleanvariable to keep track of whether the light is on/off. The light should be on initially.
setLampPower(boolean value). When called with
truethe light should turn on to the current color. When called with
falsethe lamp should turn off. This function should have no impact on the current color, which is only relevant when the light is on.
setLampPower()to test that it works as expected.
Test your work before proceeding.
Review the documentation on Particle’s “Particle Functions” as a group.
A well defined “type signature” is often used to ensure that APIs can call functions (especially callbacks). Review the concept of a “type signature” with your group.
setLampPower() so that it matches the signature required for Photon functions and returns the lamp’s on/off state value to the caller. Be sure that the
boolean variable you defined earlier is always consistent with the state of the lamp. The Photon will handle strings in a somewhat intuitive way (i.e., comparisons with
== work as expected in most cases), but it may be helpful to review the String Class.
Test your work before proceeding (perhaps use the
switch described in Studio: Embedded 2 ).
Now update your
setup() to actually use
setLampPower() as a Particle function. Reprogram your device.
Particle menu in Particle Dev and select
Show cloud functions. You may have to try this twice or wait until the device has reconnected for a few seconds, but it should show the name of the function you’ve just configured and allow you to call it. The new pane should look something like the one below:
Test your work (Note: The arguments must be strings, so there’s no need to include quotes in the data entered in Particle Dev). Enter a parameter and click the button to the left of the function name.
Whoever is the owner of the account on Particle.io for the current Photon should also log into console.particle.io then:
Review the documentation on Particle’s “Particle Variables” as a group.
Update your sketch so the
boolean variable indicating the lamp’s current power state (off/on) is a Particle variable.
Test your work. Both Particle Dev and Particle’s Cloud console have means to see the value of cloud variables. Verify that you can get the correct variable in several scenarios:
Particle’s Variables have some limitations. The most significant is that they require a client to “poll” (See: Polling).
Create a new cloud-accessible function that can be used to set a new current color. Name it
setCurrColor both in your sketch and as the name of the function from the cloud (the console and Call Function panel). The return value can just be 0 (or you can return an
int that represents the new, current color).
Commit your work to GitHub:
Complete any unfinished work and commit it to your repo by 11:59pm Sunday, Oct. 21st.