Presentation is loading. Please wait.

Presentation is loading. Please wait.

Putting the I in IoT.

Similar presentations


Presentation on theme: "Putting the I in IoT."— Presentation transcript:

1 Putting the I in IoT

2 Up to Now Electronics Software logic Debugging
Now… getting on the network

3 Remember this? Spark.publish(token, data);
-token is the String identifier for the event -data is the String message value By the way, there are some overloads. Can add TTL, for example.

4 Remember this? Spark.subscribe(token, handler, deviceID)
token is a String identifier for the event handler is the name of the method you want to run when the event is received deviceID is the ID# of the photon you are listening to The handler should take 2 inputs: void handler(const char *event, const char *data) event is the String identifier data is the interesting part - the String that was sent as value

5 2 IDs Device ID: Click “Devices” on Build, then open the arrow for the device you are using to see the ID. Access Token: Click “Settings” on Build to see your Access Token

6 Talk to the Photon “Expose” a function:
Spark.function(token, handler); token is a String identifier for the event handler is the name of the method you want to run when the event is received Handler functions take one input, a String, and give one output, an int telling success or failure. Warning: tokens can only be up to 12 letters long. The input string can be up to 63.

7 Example in setup: Spark.function(“brew”, brewCoffee); then later:
int brewCoffee(String command){ if (command.equals(“coffee”)) // turn on pot… return 1;

8 How to issue the command
Something online is going to issue the command to your Photon to perform its function. POST /v1/devices/<DEVICEID>/<HANDLER> where DEVICEID is the Device ID and HANDLER is the name of the function to call. You can add a parameter that is passed to the function as well

9 curl Useful for debugging -
libraries for sending & receiving internet messages through a variety of protocols. Already on Macs, Windows needs a download. Example from coffee machine: curl \ -d access_token= \ -d "args=coffee"

10 Hear from the Photon You may expose up to 10 variables:
Spark.variable(token, address, type); token is a String identifier of up to 12 characters address is the address of the variable you want to map it to type is the type of the variable which must be either INT, DOUBLE, or STRING Remember how to denote the address of a variable?

11 Example int temp; // the temperature registered by my temp sensor
in setup: Spark.variable(“temperature”, &temp, INT);

12 How to register the value
GET /v1/devices/<DEVICEID>/<TOKEN> curl " " Open a browser to: access_token = <ACCESSTOKEN> You will see the message - “result” is the value of the variable you want.

13 Let’s try it out Make a circuit:
3.3 -> photoresist -> A0 ->1K ohm -> Ground And D7 -> 220 ohm -> LED -> Ground Use my HTML/Javascript and change the token ids You write the Photon code.


Download ppt "Putting the I in IoT."

Similar presentations


Ads by Google