Skip to content

Instantly share code, notes, and snippets.

@evanemolo
Created April 20, 2012 01:55
Show Gist options
  • Save evanemolo/2425263 to your computer and use it in GitHub Desktop.
Save evanemolo/2425263 to your computer and use it in GitHub Desktop.
Arduino Textfinder use
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x2A };
char server[] = "twitknit-json-parsing.herokuapp.com";
// Initialize the Ethernet client and TextFinder
EthernetClient client;
TextFinder finder (client);
void setup() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET / HTTP/1.0");
client.println("HOST: twitknit-json-parsing.herokuapp.com");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
//TextFinder code
if (finder.find("<body>") == true) { //find <body> tag
long value = finder.getValue(); //get numeric value
Serial.print(value);
Serial.println(" tweets");
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment