// Maurice Ribble // 4-3-2008 // http://www.glacialwanderer.com/hobbyrobotics // The flow of data is Arduino -> Xport -> PHP -> text file // Once the connection is established by Arduino to the PHP page // the PHP page can also send data back to Arduino // This code demonstrates a simple yet flexible way to let Arduino // talk to a webserver. While there are versions of xport that // have a webserver built in they are more expensive and require you // to setup your internet connection to allow you to run a server. // With this method you can just use a cheap hosted website. // I use dreamhost and am very satisfied with their service, but there are // many other options (any host that support PHP should work fine). // With Dreamhost I needed to sign up for a dedicated IP address and I // had port 80 with connections no more frequent than once per minute or // I had problems with their firewall blocking my connection attempts. // If you want to send data back and forth frequently just connect once // and just keep using that connection. This will avoid issues with // web hosting firewalls. // Xport Settings (everything default except) // Channel 1 -- CoonnectMode : D4 -- This changes serial responce to single char mode // Channel 1 -- Port 80 // I also changed my IP address to a static IP, but you could leave this alone #define XPORT_SERIAL_RX_PIN 3 #define XPORT_SERIAL_TX_PIN 2 #define XPORT_RESET_PIN 4 // These are web server specific values #define PHP_PAGE_LOCATION "/arduino/xPortTest.php" #define WEB_HOST "HOST: yourdomain.com\n\n" #define IP_AND_PORT "C111.111.111.111/80\n" #include AFSoftSerial xPortSerial = AFSoftSerial(XPORT_SERIAL_RX_PIN, XPORT_SERIAL_TX_PIN); void setup() { // start serial port at 9600 bps: Serial.begin(9600); xPortSerial.begin(9600); } void loop() { xportReset(); xportConnect(); httpRequest(); // Delay for 1 minute to aviod triggering my host's firewall delay(60000); } void xportReset() { pinMode(XPORT_RESET_PIN, OUTPUT); digitalWrite(XPORT_RESET_PIN, LOW); delay(100); digitalWrite(XPORT_RESET_PIN, HIGH); delay(3000); } void xportConnect() { byte theByte = 0; while (theByte != 'C') { xPortSerial.print(IP_AND_PORT); while(!xPortSerial.available()) {} // Just loop until available theByte = xPortSerial.read(); Serial.print(theByte); Serial.print(" "); } } void httpRequest() { byte theByte; xPortSerial.print("GET "); xPortSerial.print(PHP_PAGE_LOCATION); // value0 = 123 and value1 = 456 // You should change these to be your sensor values or whatever you want to send // (see php code if you want to add more values or change the names value0/value1 xPortSerial.print("?value0=123&value1=456"); xPortSerial.print(" HTTP/1.1\n"); xPortSerial.print(WEB_HOST); while(!xPortSerial.available()) {} // Just loop until available theByte = xPortSerial.read(); if (theByte != 0) Serial.println("Passed."); else Serial.println("Failed."); }