Page 123 - Programming the Photon Getting Started With the Internet of Things
P. 123

Device ID=55ff74062678501139071667
        Access Token=cb8b348000e9d0ea9e354990bbd39ccbfb57b30


             Note  that  we  have  everything  we  need  and  the  program  is  running  on  the  Photon
        waiting for the led command to be sent. We can now send a command to it to turn the

        LED  on  using  curl  in  the  command  line.  To  test  this,  we  can  send  the  following
        command:


        curl https://api.spark.io/v1/devices/<deviceid>/led -d access_token=<access
        token> -d params=on


             This command shows us how to use curl to send an HTTP request to control the LED.
        Before you do this, however, you need to change the device ID and access token with your
        token ID, which we discovered earlier. You can paste this command into the command
        line using curl as shown in Figure 6.5.







































        Figure 6.5 Sending an HTTP command using curl.


             If  everything  went  well,  the  LED  connected  to  your  Photon  board  should  light  up
        almost  instantly,  and  you  will  see  a  response  from  your  Photon  device  containing  the

        information that it was successful by returning a value of 1. To turn the LED off again,
        you can issue the same command that we sent earlier, but change the value from ON to
        OFF and press ENTER. You should see the LED turn off.




        Web User Interface


        Controlling your devices through the command-line tool is an excellent way to test out
   118   119   120   121   122   123   124   125   126   127   128