It’s time to bring the last several studios together:
To summarize:
Today’s studio focuses on connecting the two pieces together.
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.
process/Roles.md
)README.md
process/SessionNotes.md
):
process/Debrief.md
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/_EBKMzPP
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 the UI. 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 and open it in Particle Dev. Be sure to pull/merge/commit/push at the end of the day!
cloudConnectedLamp.ino
// TODO: Add the following as a global variable
const String topic = "cse222Lights/thisLamp/color";
int publishState() {
// Goal: Publish a valid JSON string containing the state of the light:
// Ex: "{"powered":true, "r":255, "g":255, "b":255}"
// Note that each property has double quotes!
// TODO: Adjust variables to match your light's state variables
// (NOTE: Be careful building the string. C++ String operations often behave in
// counterintuitive ways when working with string literals (like "hi"))
String data = "{";
if(power) {
data += "\"powered\":true";
} else {
data += "\"powered\":false";
}
data += ", ";
data += "\"r\":";
data += currentR;
data += ", ";
data += "\"g\":";
data += currentG;
data += ", ";
data += "\"b\":";
data += currentB;
data += "}";
Serial.println("Publishing:");
Serial.println(data);
Particle.publish(topic, data, 60, PRIVATE);
return 0;
}
Complete README.md
Q1
Often times it’s necessary to “get” the initial state of a device without waiting for an event. For example, your User Interface will need to get the devices state when the UI first starts. Update your Photon code with a cloud function that will force the state to be published (by just calling the publishState()
function above).
The callback used for Particle.function()
needs to have parameter (a String
), but the parameter doesn’t have to be used if calling the function itself is sufficient. You may update the code above to include a parameter and then pass an empty string when calling it explicitly:
int publishState(String arg) {
...
}
...
void someFunction() {
...
publishState("");
}
...
void setup() {
...
Particle.function("publishState",publishState);
}
There are other valid approaches too.
The provided UI in ui/
has been simplified to remove the time based features.
ui/mainLightUI.js
. It provides code for the UI and has a few notes (search for NOTE
) where changes were made to the code from Studio 4/4B.ui/light.js
. It is based on the light
object from Studio 4, but now represents an actual light.Note the TODO
at the top of light.js
. It specifies two variable values need to be provided:
myParticleAccessToken
: This represents an OAuth access token. Anything that has this token can access features associated with your account. We will temporarily hardcode this (This is a bad practice and shouldn’t be done in real apps. The token will eventually expire and anyone with the token will be able to access the devices/services that the token has access to!)
myDeviceId
: This is the unique ID of a device your code will interact with.
Parts of the light
have been completed for you:
setPowered()
provides an example of calling a Particle function.setup()
will subscribe to the event stream for your.Complete README.md
Q2
You still need to complete the items marked TODO
. When done:
Target Color
over 5s and the Current Color
should be shown updating (5x).Complete README.md
Q3
Commit your work to GitHub:
Complete any unfinished work and commit it to your repo by 11:59pm Sunday, Oct. 27th.