Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

CHAPTER 8 ■ IOT PATTERNS: WEB APPS


Standard Functions


The code in the last section is provided in Listing 8-9. It implements Arduino’s standard
setup() and loop() functions.
The setup() function initializes the serial port and connects to the Internet.
The loop() function calls readSensorData() for reading temperature data and then
publishes the data to the server using HTTP by calling transmitSensorData() at regular
intervals.


Listing 8-9. Code for Standard Arduino Functions


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


//Connect Arduino to internet
connectToInternet();
}


void loop()
{
// Read sensor data
readSensorData();


// Transmit sensor data
transmitSensorData();


// Delay
delay(6000);
}


Your Arduino code is now complete.

The Final Product


To test the application, make sure your MySQL and PHP servers are up and running with
the code deployed.
Also verify and upload the Arduino code as discussed in Chapter 1. Once the code
has been uploaded, open the Serial Monitor window. You will start seeing log messages
similar to ones shown in Figure  8-9.

Free download pdf