Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created February 17, 2010 13:41
Show Gist options
  • Save willbailey/306613 to your computer and use it in GitHub Desktop.
Save willbailey/306613 to your computer and use it in GitHub Desktop.
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <TinyXML.h>
#include <WString.h>
byte mac[] = { 0xAC, 0xCC, 0xAC, 0xBB, 0xAA, 0xAB };
byte ip[] = { 10, 0, 1, 109 };
byte gateway[] = { 10, 0, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
TinyXML xml;
uint8_t buffer[150];
uint16_t buflen = 150;
// google IP
byte server[] = {38,102,136,138};
Client client(server, 80);
String tempF = String("/temp_f");
String weather = String("/weather");
void setup() {
xml.init((uint8_t*)&buffer,buflen,&XML_callback);
Ethernet.begin(mac, ip);
Serial.begin(9600);
backlightOn();
clearLCD();
boxCursor(false);
Serial.print("Checking Weather");
delay(1000);
clearLCD();
if (client.connect()){
clearLCD();
client.println("GET /auto/wui/geo/WXCurrentObXML/index.xml?query=JFK HTTP/1.0");
client.println();
} else {
Serial.print("failed");
}
}
void loop() {
int bytesAvailable = client.available();
if (bytesAvailable) {
for (int i=0; i<bytesAvailable; i++) {
char c = client.read();
xml.processChar(c);
}
}
if (!client.connected()) {
client.stop();
}
}
boolean inCurrentConditions = false;
boolean inTempF = false;
boolean inConditions = false;
void XML_callback( uint8_t statusflags, char* tagName, uint16_t tagNameLen, char* data, uint16_t dataLen )
{
if (tempF.equals(tagName)) {
goTo(16);
for (int i = 0; i < dataLen; i++) {
Serial.print(data[i]);
delay(50);
}
}
if (weather.equals(tagName)) {
goTo(0);
for (int i = 0; i < dataLen; i++) {
Serial.print(data[i]);
delay(50);
}
}
}
void typeLine(char line[], int length){
for (int i=0; i < length; i++){
goTo(i);
Serial.print(line[i]);
delay(50);
}
}
void boxCursor(boolean onOff) {
serCommand();
onOff ? Serial.print(0x0D, BYTE) : Serial.print(0x0C, BYTE);
}
void underlineCursor(boolean onOff) {
serCommand();
onOff ? Serial.print(0x0E, BYTE) : Serial.print(0x0C, BYTE);
}
// Scrolls the display left by the number of characters passed in, and waits a given
// number of milliseconds between each step
void scrollLeft(int num, int wait) {
for(int i=0;i<num;i++) {
serCommand();
Serial.print(0x18, BYTE);
delay(wait);
}
}
// Scrolls the display right by the number of characters passed in, and waits a given
// number of milliseconds between each step
void scrollRight(int num, int wait) {
for(int i=0;i<num;i++) {
serCommand();
Serial.print(0x1C, BYTE);
delay(wait);
}
}
// Starts the cursor at the beginning of the first line (convienence method for goTo(0))
void selectLineOne() { //puts the cursor at line 0 char 0.
serCommand(); //command flag
Serial.print(128, BYTE); //position
}
// Starts the cursor at the beginning of the second line (convienence method for goTo(16))
void selectLineTwo() { //puts the cursor at line 0 char 0.
serCommand(); //command flag
Serial.print(192, BYTE); //position
}
// Sets the cursor to the given position
// line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
void goTo(int position) {
if (position < 16) {
serCommand(); //command flag
Serial.print((position+128), BYTE);
} else if (position < 32) {
serCommand(); //command flag
Serial.print((position+48+128), BYTE);
} else {
goTo(0);
}
}
// Resets the display, undoing any scroll and removing all text
void clearLCD() {
serCommand();
Serial.print(0x01, BYTE);
}
// Turns the backlight on
void backlightOn() {
serCommand();
Serial.print(157, BYTE);
}
// Turns the backlight off
void backlightOff() {
serCommand();
Serial.print(128, BYTE);
}
// Initiates a function command to the display
void serCommand() {
Serial.print(0xFE, BYTE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment