Hardware Reference
In-Depth Information
The great thing about using ØMQ for networking is that you can do the following:
Run
./sensor with no consoles running
Run any number of
./console (or ./mac_console ) programs
without the sensor running yet
Run as many consoles as you like
Bring down consoles anytime you like
With a little homework and extra effort, you could monitor multiple sensors as well.
That was avoided here, to keep the example as simple as possible.
Sensing Station Program
The sensing station (Raspberry Pi) is started as follows:
$ ./sensor
The station runs quietly until terminated (it can be shut down from a console).
While it runs, it periodically broadcasts (publishes) updates to the consoles with the
current status of SW 1 and LED . This is necessary because a console may be offline when
the last switch or LED change occurs.
Whenever SW 1 changes, a broadcast is immediately sent with its new status sw1:%d ,
where %d is a 1 when the switch is on, and otherwise, a 0 .
The LED is changed only at the command of the console program. When the sensor
program receives a console message of the form led:%d (over the network), the LED is
turned on or off, according to the value of %d ( 1 or 0 ). Once the LED is changed, however, it
is rebroadcasted to all consoles, so that the other consoles can see that this has changed.
Finally, if the console sends stop: to the sensor, the sensor program shuts down and
exits. Pressing ^C in its terminal session will also terminate it.
Console Program
The console program should be compilable for any Linux or Mac OS X platform. If you
use the downloaded makefile, use the target mac_console when building it on Mac OS X:
$ make mac_console
For the Raspberry Pi or any other Linux distribution, you can build the program
simply as follows:
$ make
 
Search WWH ::




Custom Search