Building Arduino Projects for the Internet of Things

(Steven Felgate) #1
CHAPTER 2 ■ INTERNET CONNECTIVITY

Internet Connectivity (Wireless)


The second section of the code, which is provided in Listing 2-12 , defines the functions
that are going to be used for displaying connection information.
Since Arduino is already connected to the wireless network, the
printConnectionInformation() function is called. It prints the wireless connection
information.


Listing 2-12. Function to Display Connection Information


void printConnectionInformation()
{
// Initialize a new process
Process wifiCheck;


// Run Command


wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");


// Print Connection Information
while (wifiCheck.available() > 0)
{
char c = wifiCheck.read();
Serial.print(c);
}


Serial.println("-----------------------------------------------");
Serial.println("");
}


Standard Functions


Finally, the code in third and last section, provided in Listing 2-13 , implements Arduino’s
standard setup() and loop() functions. For this project, all you are doing is printing
the Internet connection information and there is no processing thereafter, so the loop()
function will remain empty.
One main difference in this code versus the Arduino Uno code is that you need to
initialize the bridge using Bridge.begin(). This basically lets you access the Arduino Yún
Internet connection.


Listing 2-13. Code for Standard Arduino Functions


void setup()
{
// Initialize serial port
Serial.begin(9600);


// Do nothing until serial monitor is opened
while (!Serial);

Free download pdf