Hardware Reference
In-Depth Information
Read a character from the serial buffer in order to remove it.
Execute the Linux command curl with the URL makezine.com and
push the output back to the serial monitor.
The Serial functionality in Example 6-1 is included so that you can tell Galileo
to make a single request, as opposed to just executing it once when the
sketch starts (easy to miss in the serial monitor) or executing it repeatedly
(which wouldn't be very kind to the server, and might get your network tem-
porarily blocked because it looks like a network attack).
system()
The system() function is a special one for Galileo. It tells your Arduino code
to execute a command-line operation in the Linux shell. To learn how it works,
take a closer look at its use in Example 6-1 :
system ( "curl http://makezine.com &> /dev/ttyGS0" );
The system() function itself takes a single parameter, a string. It's the exact
command that you would type on the command line. In this case, we're using
the command curl to fetch the URL http://makezine.com/ . So that we can
see if the command works, the output of that request should be redirected
back to our serial monitor. The &> indicates that standard output (normal text
output) and errors (most error messages) should be redirected to /dev/
ttyGS0 , which is the device that Galileo uses to display information in the
Arduino IDE's serial monitor.
Getting Galileo's IP Address Using
system()
From time to time, you may need to know information about how your Galileo
is connected to the network. Frequently, I want to know a device's IP address
so that if the board is acting like a server, I can connect to it.
The command-line function ifconfig allows you to see information about
your connections. You can try it out on your computer's command line if
you're running Linux or OS X. On Windows, the similarly named ipconfig fills
this role.
To execute ifconfig on the Galileo through Arduino code and see the results
in the serial monitor:
1. Make sure your Galileo is connected to the network via Ethernet, or has
the WiFi module installed and tested.
2. Connect power to the Galileo.
Search WWH ::




Custom Search