February 20, 2015

Project DONE....

Finished wiring the LCD and completed the code. Everything is now 100% working. Now i can see my connection status and how many listeners are listening to my feed via broadcastify.







  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#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() {

  
 delay(2500);
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.22 ");
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 (client.available()) {
char c = client.read();
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 (millis() - lastConnectionTime > postingInterval) {
lcd.setCursor(15, 1);
lcd.print(listeners_string);
lcd.setCursor(15, 0);
lcd.print(connection_status);
Serial.print("Feed status: ");
if (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...");
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;
}
}

No comments:

Post a Comment