Feed Status: Online/Offline

Status
Not open for further replies.

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
I am currently working on another project that has to due with audio feeds and i would like to know if anyone knows how to pull the data either threw a script or a url to show if my feed is online or offline.

I can get the listener count with this url
http://api.broadcastify.com/listeners/feed/10746

but what about the connection status.

Thanks
Mike
 

ProScan

Software Provider
Premium Subscriber
Joined
Jul 2, 2006
Messages
7,409
Location
Ontario, Calif.

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
I want to scrape the data from the text and pipe it to something else.

Basically i am taking an Arduino Uno with an Ethernet shield and getting the feed count (that part works) Next part is to get the status of the feed either online or offline and finally show the data on a LCD 2x16 display,

Hopefully this makes sense.

Mike
 

ProScan

Software Provider
Premium Subscriber
Joined
Jul 2, 2006
Messages
7,409
Location
Ontario, Calif.
I want to scrape the data from the text and pipe it to something else.

Basically i am taking an Arduino Uno with an Ethernet shield and getting the feed count (that part works) Next part is to get the status of the feed either online or offline and finally show the data on a LCD 2x16 display,

Hopefully this makes sense.

Mike

Would scraping this work for you?

<td class="online">Online</td>
 

blantonl

Founder and CEO
Staff member
Super Moderator
Joined
Dec 9, 2000
Messages
11,095
Location
San Antonio, Whitefish, New Orleans
Try using some of these non-published or not-well-known HTTP calls that we use internally

do an HTTP POST to

Code:
http://www.broadcastify.com/listeners/feed/10746
http://www.broadcastify.com/status/feed/10746
http://www.broadcastify.com/alert/feed/10746
 

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
Ok that worked, Now i just need to attach a LCD and get it to display the listener count and the online status. Current code is below.

This is what i am using
ArduinoUno_R3_Front.jpg


with this Ethernet shield
$_12.JPG





#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char serverName[] = "www.broadcastify.com";
String location = "/listeners/feed/10746 HTTP/1.0";
EthernetClient client;
void setup() {
Serial.begin(9600);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(true);
}
delay(1000);
Serial.println("Making Connection");
if (client.connect(serverName, 80)) {
Serial.println("Connected");
client.println("POST http://api.broadcastify.com/status/feed/10746 HTTP/1.0");
client.println();
}
else {
Serial.println("Connection Failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting");
client.stop();
while(true);
}
}

Untitled.jpg
 

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
Here is the updated code with LCD support. Almost done with actually LCD showing the data of connection status and # of users listening to the feed.

#include <LiquidCrystal.h> // ADDDED
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x04
};
// fill in an available IP address on your network here,
// for manual configuration:
//IPAddress ip(192, 168, 1, 177);

// fill in your Domain Name Server address here:
// IPAddress myDns(71,250,0,12);

// initialize the library instance:
EthernetClient client;
char server[] = "api.broadcastify.com";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
//const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds, 10 seconds
// the "L" is needed to use long type numbers
const unsigned long postingInterval = 5000; // delay between updates, in milliseconds, 5 seconds
String result;
String listeners_string;
int listeners;
char status = 0;
boolean last = 0;
boolean updating = 1;
boolean connection_status = 0;

// NEW CODE
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 );
// NEW CODE


void setup() {

// NEW CODE
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Feed Status v1.0");
lcd.setCursor(0,1);
lcd.print(" Richk107");
delay(3000);

lcd.setCursor(0,1);
lcd.print(" Mike Xeno");
delay(3000);

delay (5000);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print(" LOADING");
lcd.setCursor (0, 1);
lcd.print(" STANDBY");
delay (7000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Status: ");
lcd.setCursor(0,1);
lcd.print("Users: ");
// NEW CODE



Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection using a fixed IP address and DNS server:
// Ethernet.begin(mac, ip, myDns);
// Remove the next four lines if you wish to hardcode the IP and DNS entries.
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(true);
}
// print the Ethernet board/shield's IP address:


Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
delay(1000);
}

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) {

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();

}
}

// this method makes a HTTP connection to the server:
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();

// if there's a successful connection:
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();

// note the time that the connection was made:
lastConnectionTime = millis();
connection_status = 1;
status = 1;
updating = 0;
}
else {
// if you couldn't make a connection:
Serial.println("connection failed, retrying");
connection_status = 0;
updating = 1;
}
}
 

SCPD

QRT
Joined
Feb 24, 2001
Messages
0
Location
Virginia
All the code is complete and fully operational now. Latest code is pasted below the picture

rflcd.jpg

#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;
}
}
 

ve2vag

Member
Feed Provider
Joined
Nov 24, 2011
Messages
35
Location
Quebec Canada
Try using some of these non-published or not-well-known HTTP calls that we use internally

do an HTTP POST to

Code:
http://www.broadcastify.com/listeners/feed/10746
http://www.broadcastify.com/status/feed/10746
http://www.broadcastify.com/alert/feed/10746

Except for the "listeners" one, are these http POST commands still valid, especially the "status" one ?

I would like to embed audio player to display the stats of my feed in another language; display "En ligne" instead of Online, "Hors ligne" instead of Offline, etc. Guess I could scrape the class <td class="online">Online</td> and have our webpage display the french expression, but would there be an easier way ?
 
Status
Not open for further replies.
Top