Hardware Reference
In-Depth Information
8
Next, initialize a few array variables
with the network configuration for the
module.
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
IPAddress ip( 192,168,1,20 );
IPAddress server( 208,201,239,101 );
8 Change these to
match your own device
and server.
The last global variables you need
to add are for the Client class, and
a few variables relating to the transac-
tion with the server.
8
// Initialize the Ethernet client library
Client client;
boolean requested; // whether you've made a request
long lastAttemptTime = 0; // last time you connected to the server
int airQuality = 0; // AQI value
boolean meterIsSet = false; // whether the meter is set
8
setup() starts the serial and
Ethernet connections, sets all the LED
pins to be outputs, blinks the reset
LED, and makes an initial attempt to
connect to the server.
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// start the serial library:
Serial.begin(9600);
// set all status LED pins:
pinMode(connectedLED, OUTPUT);
pinMode(successLED, OUTPUT);
pinMode(resetLED, OUTPUT);
pinMode(disconnectedLED, OUTPUT);
pinMode(meterPin, OUTPUT);
// give the Ethernet shield a second to initialize:
delay(1000);
// blink the reset LED:
blink(resetLED, 3);
// attempt to connect:
connectToServer();
}
8
The blink() method called in the
setup blinks the reset LED so you know
the microcontroller's main loop is
about to begin.
void blink(int thisPin, int howManyTimes) {
// Blink the reset LED:
for (int blinks=0; blinks< howManyTimes; blinks++) {
digitalWrite(thisPin, HIGH);
delay(200);
digitalWrite(thisPin, LOW);
delay(200);
}
}
 
Search WWH ::




Custom Search