February 28, 2015

Scanner Audio Feed Probe- Arduino

Finished fixing the code. Big thank you to Richard Kot for helping me along the way.

The picture to the left is the wiring directions i whipped up. Every ethernet card is different so see what pins you have available and just change them in the INT section (RS/E/D4/D5/D6/D7) of the code.

The new code is posted below.








  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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.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, 0x16};
EthernetClient client;
char server[] = "api.broadcastify.com";
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 10L * 1000L;
String result;
String listeners_string;
int listeners;
char status = 0;
boolean last = 0;
boolean updating = 1;
boolean connection_status = 0;
int lcdColumns = 16;
int lcdRows = 2;     
  
void setup() {
lcd.begin(lcdColumns, lcdRows); 
delay(1000);
Serial.println("Requesting DHCP address");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(true);
Serial.print(".");
  }
splash_screen();
  }
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("Offline"))
  {
result="";
status = 0;
  } 
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) {
Serial.print("Feed status: ");
lcd.clear();
lcd.setCursor(0, 0);    
lcd.print("Status: ");
if (updating) {
}
if (connection_status){
if (status ==1 ) {
Serial.println("Online");
Serial.print("Listeners: ");  
Serial.println(listeners_string);
lcd.setCursor(8, 0);    
lcd.print("Online");
lcd.setCursor(0, 1);    
lcd.print("Listeners: ");
lcd.setCursor(11, 1);    
lcd.print(listeners_string);      
}
else {
Serial.println("Offline");
lcd.setCursor(8, 0);    
lcd.print("Offline");
lcd.setCursor(0, 1);    
lcd.print("               ");
}
}
httpRequest();
}
}
void splash_screen() {
lcd.clear();
lcd.setCursor(0, 0);    
lcd.print("Feed Status v1.3");
Serial.println("Feed Status v1.3");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);    
lcd.print("My IP address: ");
lcd.setCursor(0, 1);    
lcd.print(Ethernet.localIP()); 
delay(2000);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);  
lcd.print("SCANNER AUDIO   ");
lcd.setCursor (0, 1);
lcd.print("FEED PROBE v1.5  ");
delay(6000);
lcd.clear(); 
}
void httpRequest() {
client.stop();
if (client.connect(server, 80)) {
Serial.println("connecting...");
client.println("POST /status/feed/10746 HTTP/1.1");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
connection_status = 1;
status = 1;
updating = 0;
  }
else {
Serial.println("connection failed, retrying");
lcd.setCursor(0, 1);    
lcd.print("Retrying...");
delay (5000);
connection_status = 0;
updating = 1;
client.stop();
}
}

No comments:

Post a Comment