Skip to content

Instantly share code, notes, and snippets.

@ezodude
Created September 5, 2009 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezodude/181245 to your computer and use it in GitHub Desktop.
Save ezodude/181245 to your computer and use it in GitHub Desktop.
/*
Copyright (c) 2009 Abdel A Saleh - asaleh at the-experimenters (dot) com / http://twitter.com/abdels
This work is licensed under the Creative Commons BSD license, http://creativecommons.org/licenses/BSD.
Please include the NewSoftSerial library found here: http://arduiniana.org/libraries/newsoftserial
*/
#include <NewSoftSerial.h>
#define deviceResetPin 4
NewSoftSerial xport(2, 3);
byte incoming;
void setup()
{
xport.begin(9600);
Serial.begin(9600);
pinMode(deviceResetPin, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, 0);
resetDevice();
}
void loop()
{
digitalWrite(13, 0);
//Look for a 'D' before issuing a 'C' using the serial monitor
//Look for a 'C' before issuing a 'G' using the serial monitor
if(xport.available())
{
digitalWrite(13, 1);
Serial.print((char)xport.read());
}
if(Serial.available())
{
incoming = Serial.read();
if(incoming == 'R')
{
Serial.print("Resetting");
digitalWrite(13, 1);
resetDevice();
}
if(incoming == 'C')
{
Serial.print("Connecting");
digitalWrite(13, 1);
xport.print("C76.13.6.175/80\n"); //Delicious.com
}
if(incoming == 'G')
{
Serial.print("Do Get Request");
digitalWrite(13, 1);
// xport.print("GET / HTTP/1.1\n"); //BAD
xport.println("GET / HTTP/1.1"); //GOOD
// OR Use the following as one sequence
// xport.print("GET / HTTP/1.1");//GOOD
// xport.print(13, BYTE); //CR
// xport.print(10, BYTE); //LN
// xport.print("Host: delicious.com\n\n"); //BAD
xport.println("Host: delicious.com\r\n");//GOOD
// OR Use the following as one sequence
// xport.print("Host: delicious.com");//GOOD
// xport.print(13, BYTE); //CR
// xport.print(10, BYTE); //LN
// xport.print(13, BYTE); //CR
// xport.print(10, BYTE); //LN
}
}
}
/*
Take the Lantronix device's reset pin low to reset it
*/
void resetDevice() {
digitalWrite(deviceResetPin, LOW);
delay(50);
digitalWrite(deviceResetPin, HIGH);
// pause to let Lantronix device boot up:
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment