All the code is complete and fully operational now. Latest code is pasted below the picture
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
int RS = 9;
int E = 8;
int D4 = 7;
int D5 = 6;
int D6 = 5;
int D7 = 4;
LiquidCrystal lcd(RS, E, D4, D5, D6, D7 );
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x04};
EthernetClient client;
char server[] = "api.broadcastify.com";
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 5000;
String result;
String listeners_string;
int listeners;
char status = 0;
boolean last = 0;
boolean updating = 1;
boolean connection_status = 0;
void setup() {
//Serial.begin(9600);
//while (!Serial) {
//; // wait for serial port to connect. Needed for Leonardo only
//}
delay(1000);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(true);
}
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
delay(1000);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SCANNER AUDIO ");
lcd.setCursor (0, 1);
lcd.print("FEED PROBE v1.2 ");
delay(6000);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print("Local Connection");
lcd.setCursor (0, 1);
lcd.print(Ethernet.localIP());
delay (5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Server Link ");
lcd.setCursor(0, 1);
lcd.print("Connections ");
}
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
// Serial.write(c);
result = result + c;
if(result.endsWith("online\">"))
{
result="";
updating = 0;
}
if(result.endsWith("Online"))
{
result="";
status = 1;
}
if(result.endsWith("listeners\">"))
{
result="";
last = 1;
}
if (last == 1) {
if(result.endsWith("</span>")) {
listeners_string = result.substring(0, (result.length() - 7));
last = 0;
result="";
}
}
}
else {
}
// if delay value (postingInterval) has passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval) {
lcd.setCursor(12, 1);
lcd.print(listeners_string);
lcd.setCursor(12, 0);
lcd.print(connection_status);
Serial.print("Feed status: ");
if (updating) {
// Serial.println("Updating");
}
if (connection_status){
if (status ==1 ) {
Serial.println("Online");
Serial.print("Listeners: ");
Serial.println(listeners_string);
}
else
Serial.println("Offline");
}
httpRequest();
}
}
void httpRequest() {
client.stop();
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP POST request - A GET will not return the needed information, must be a POST
client.println("POST /status/feed/10746 HTTP/1.1");
client.println("Host: broadcastify.com");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
connection_status = 1;
status = 1;
updating = 0;
}
else {
Serial.println("connection failed, retrying");
connection_status = 0;
updating = 1;
}
}