Building Arduino Projects for the Internet of Things

(Steven Felgate) #1
CHAPTER 2 ■ INTERNET CONNECTIVITY

// Print WiFi Shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("[INFO] IP Address: ");
Serial.println(ip);


// Print MAC address
byte mac[6];
WiFi.macAddress(mac);
Serial.print("[INFO] MAC Address: ");
Serial.print(mac[5], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);
}


Standard Functions


Finally, the code in the third and last section, as provided in Listing 2-10 , implements
Arduino’s standard setup() and loop() functions. For this project, all you are doing is
connecting Arduino to the Internet and there is no processing thereafter, so the loop()
function will remain empty.


Listing 2-10. Code for Standard Arduino Functions


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


// Connect Arduino to Internet
connectToInternet();
}


void loop()
{
// Do nothing
}


Your Arduino code is now complete.
Free download pdf