Pages: [1]   Go Down
Author Topic: Arduino Ethernet Shield Program to Arduino WiFi Shield Program  (Read 486 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to take this code, that works great, and runs great on the Ethernet Shield.  Make it so it will run on the WiFi Shield.  Then I can go cordless with it.  What are the key things I need to change one the program?  If I know it all I would not be asking people on here.  So any cool input, would help out.   







/*
  Snail Mail Push Alerts by Matt Richardson
  Adapted from the Arduino WebClient example by David A. Mellis
  
  This sketch is part of a project which sends a push alert to your
  iPhone when your snail mail is delivered.
  This sketch requests a URL when a mailbox has been opened.
  The URL is a PHP script based on the ProwlPHP class.
  
  December 31, 2010
 */

#include <SPI.h>
#include <Ethernet.h>

#define switchPin 7  // Snap action switch which closes when the mailbox door is opened.

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,0,1,1 }; // local Arduino IP
byte server[] = { 1,1,1,1 }; // IP of your web server

Client client(server, 80);

void setup() {
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  delay(1000);
  pinMode(switchPin, INPUT);
}

void loop()
{
  if (digitalRead(switchPin) == HIGH) // if mailbox is opened:
  {
      Serial.println("Mailbox door opened");
    if (client.connect()) { //connect to server
      Serial.println("connected to server");
      // Make a HTTP request:
      client.println("GET /path/to/example.php"); //location of ProwlPHP script
      client.println();
    }
    else {
      Serial.println("connection failed");
    }
    delay(1000);
    Serial.print("Response from server: ");
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  
    // if the server's disconnected, stop the client:
    if (!client.connected()) {
      Serial.println("disconnecting from server");
      client.stop();
    }
    while (digitalRead(switchPin) == HIGH)
    {
      // hold here until mailbox is closed again.
    }
    Serial.println("Mailbox door closed");
    delay(500);
  }
}
« Last Edit: January 14, 2012, 02:17:30 pm by Tricky12 » Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What do if have to change in the code?

You probably need to start with the IP addresses.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: