Page 116 - Programming the Photon Getting Started With the Internet of Things
P. 116
6
The Internet of Things
Now we have learned the basics of programming the Photon board using various
electronic components as well as using both analog and digital devices, we are now going
to learn how to control those devices over the Particle cloud. The Internet of Things is
gaining in importance with ever-increasing access to the Internet and networks. The
Photon allows you to connect the board to the Internet using the built-in Wi-Fi chip, and
this opens up endless possibilities with the board.
In this chapter we are going look at controlling things over the Internet as well as take
readings from temperature devices to display on the Web. For this, we will be looking
closely at using Particle functions, which is an important part of the Photon cloud.
Functions
Usually programming devices to access the Internet can be complex and time consuming.
Luckily the Photon uses a pretty simple method of using functions within the program that
either push or pull to the Web using a unique identifier for your Photon device. This first
example we will look at creates a simple program to turn a light-emitting diode (LED) on
or off using the Internet. This will help you understand how the Photon cloud system
works, as well as introducing functions into your programming code.
A function command is quite simple—it associates itself with your Particle device and
allows you to command it to do something. Whenever it receives a particular command, it
then runs the script in your program. Sending commands to the Photon board actually
requires you to send a Hypertext Transfer Protocol (HTTP) post request to the device. An
easy way to test this is to use a simple command-line tool called curl. If you are using a
Mac computer or a Linux device, chances are this tool is already installed in the operating
system. Unfortunately, if you are using a Windows device, you will need to install it
manually by following the next steps.
Open up your default Web browser and go to http://curl.haxx.se/download. Scroll
down the page and find the Windows sections for downloads. Download the ZIP file and
extract the contents to a new folder on your computer. Open up the command prompt by
clicking Start and do a search for “cmd.” This should open up the command prompt as
shown in Figure 6.1.