Hi,
I am trying to use the following code, but the text "The tank is OFF " and " The tank is ON " is not showing on the screen as desired. All serial.print instructions are showing correctly in the serial monitor however. Is anybody able to assist?
#include <SPI.h>
#include <Ethernet.h> // Enable if using Ethernetshield
//#include <UIPEthernet.h> // Enable if using ENC28J60
#include <LiquidCrystal.h>
boolean reading = false;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,0,178);
// fill in your Domain Name Server address here:
//IPAddress myDns(1,1,1,1);
// initialize the library instance:
EthernetClient client;
char server[] = "aveshop.co.uk";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 5000; // delay between updates, in milliseconds
void setup() {
// start serial port:
Serial.begin(9600);
lcd.begin(16, 2);
//lcd.print("Initialising....");
// give the ethernet module time to boot up:
delay(1000);
//lcd.setCursor(0, 0);
//lcd.print(" ");
// start the Ethernet connection using a fixed IP address and DNS server:
Ethernet.begin(mac, ip);
// print the Ethernet board/shield's IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '*') reading = true; //found the *, begin reading the info
if(reading){
Serial.println(c);
switch (c) {
case '0':
//add code here for LCD display when tank off
//lcd.setCursor(0, 0);
//lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("The tank is OFF ");
Serial.println("The screen would show off");
break;
case '1':
//add code here for LCD display when tank on
//lcd.setCursor(0, 0);
//lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print(" The tank is ON ");
Serial.println("The screen would show on");
break;
}
}
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
Serial.println("-------------------------------------------------------------------");
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
httpRequest();
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
// this method makes a HTTP connection to the server:
void httpRequest() {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request:
client.println("GET http://aveshop.co.uk/MySql-scripts/report_tankstate.php HTTP/1.0");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
Serial.println("disconnecting.");
//Enc28J60.init(mac);
client.stop();
}
}
Thanks.