Académique Documents
Professionnel Documents
Culture Documents
// Peter Haban
//----------------------------------------------
#include <Ethernet.h>
#include <SPI.h>
#include <LiquidCrystal.h>
EthernetClient client;
void setup(){
Ethernet.begin(mac, ip);
Serial.begin(9600);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(2, OUTPUT);
lcd.begin(16, 2);
lcd.print("node1 temp:"); //first line of the LCD to indicate what we are reading from the database
void loop(){
String pageValue = connectAndRead(); //connect to the server and read the output
int i = atoi(inString); //translate what we read from the php script to an integer value
Serial.println(inString);
lcd.setCursor(0, 1);
lcd.print(i); //result from the php script gets displayed in the second line of the LCD
delay(5000);
String connectAndRead(){
Serial.println("connecting...");
if (client.connect(server, 80)) {
Serial.println("connected");
client.print("GET ");
client.println(location);
client.println();
}else{
String readPage(){
//read the page, and capture & return everything between '<' and '>'
stringPos = 0;
while(true){
if (client.available()) {
char c = client.read();
}else if(startRead){
inString[stringPos] = c;
stringPos ++;
}else{
startRead = false;
client.stop();
client.flush();
Serial.println("disconnecting.");
return inString;