WiFi Shield + iPhone

I have been searching the net, but have had know no. I am trying to use my iPhone to control an arduino uno with an Arduino WiFi shield thru my home secured router to open and close my garage. I have the sketch from the Arduino website and can connect to my router, but I am having issues getting my iPhone to control the Arduino thru my router. I am trying to use the Ardumote software on my iPhone. the problem is the sketch is for an Ethernet shield and not a WiFi shield. I am new to code and could use some help in converting the sketch to use WiFi. Is it possible or am I wasting my time. Please let me know. Oh, the reason I need to use WiFi, is it will be difficult to run a cable from my router to the garage.

V/r
Dan

I have been searching the net, but have had know no.

All the words are spelled right, but that order makes no sense.

I have the sketch from the Arduino website and can connect to my router

But, I'm not going to show it to you.

I am trying to use the Ardumote software on my iPhone

But, I'm not going to provide a link.

the problem is the sketch is for an Ethernet shield and not a WiFi shield.

So, you needed to make some changes, but you're not going to tell us about them.

Well, good luck.

I apologize; Like I said, the WiFi sketch I got of the Ardumote website. I got it to connect to my router and it sends back information on the connection status. The Aurdmote sketch is for Ethernet. I am trying to figure out how to change it to function using WiFi, but I am new to code and basically reading and try to modify the sketch to function using WiFi. Here is the sketch that connects to my WiFi, but I am not able to get my iPhone to talk to the WiFi shield. Let me know what exactly you need from me, I am more than willing. I just need help figuring this out.

sketch:

/* Ardumote Example code for Arduino IDE 1.0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  • This example code allows an iPhone, iPod, or iPad to control an arduino + ethernet shield (UDP capable) using the Ardumote App;

  • Ardumote can be downloaded from the Apple App Store here:

  • This code is based on the UDP examples provided on Arduino’s website under “Ethernet”

  • By using this code, you take responsibility for any damage it may incur to your software or hardware. Use at your own risk!

  • This code is in the public domain - feel free to modify or distribute it.

  • This code has been tested on the Wiznet 5100 based Ethernet Shield from Arduino. Modifications may be needed for other shields.

  • Please read directions at www.SamratAmin.com/Ardumote.html

  • S. Amin 12/2011

*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
/////////// ARDUMOTE Directions //////////////////////////

On the Ardumote App, create 2 objects:

  1. Press and hold the “+” button and create a TOGGLE button. Press and hold on the newly created toggle and press “Set Params”. Enter your ethernet shield’s IP address, Port # and set the Message to “P10”. This will send a “P10H” when the switch is active, and a “P10L” when it is not active.

  2. Create a slider in the same way. Press and hold, enter the same network info. For the message, set it to “PWM”. This will send a message
    of “PWMXXX” where XXX represents our 3 digit slider value (0-255).

Thats it!! Now, set your ethernet shield’s network parameters below, upload the code to the arduino, and try it out!

** NOTE: Make sure your iDevice is on the same WiFi network and the selected port is open

*////////////////////////////////////////////////////////////

#include<SPI.h>

#include <WiFi.h>

#include <Ethernet.h>

char ssid = “XXXXXXXXXXX”; // your network SSID (name)
char pass = “XXXXXXXXXXX”; // your network password
//char packBuff[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
int status = WL_IDLE_STATUS; // the Wifi radio’s status

////////// NETWORK INFO ////////////////

byte mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //Set your Ethernet Shield’s MAC address here - make sure you replace the ZZs with your shield’s values!
byte ip = { 192,168,1,1 }; // Set your shield’s desired IP address here - check your network for configuration details
//byte gateway = { 192,168,1,1 }; //if you need to set a gateway IP
//byte subnet = { 255,255,255,0 }; // Change this to your subnet address

unsigned int localPort = 7777; // local port to listen on (set this the same as Port # on Ardumote Params Screen)

IPAddress iPhoneIP(192, 168, 1, 1); //Set the iPhone/iPod/iPad’s IP address to send messages back to Ardumote…
unsigned int iPhonePort = 7777; //Set the Port # of the message table you configured in Ardumote (default is 7777)…

///////////////////////////////////////////

///////// Pin Assignments /////////////////

int LED_Pin = 10; //Set LED_Pin to Pin 10 - Place an LED on Pin 10 of your ethernet shield for testing this code

///////////////////////////////////////////

///////////////// UDP Variables //////////////////

// the next two variables are set when a packet is received
//byte remoteIp[4]; // holds received packet’s originating IP
//unsigned int remotePort; // holds received packet’s originating port

// buffers for receiving and sending data
char packBuff[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

/////////////////////////////////////////////////

EthernetUDP Udp;

void setup() {

//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
// don’t continue:
while(true);
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);
}

// More info on Ethernet on Arduino’s website: http://arduino.cc/en/Reference/EthernetBegin
// start the Ethernet and UDP:
//WiFi.begin(mac,ip); // If you don’t need to set your default gateway or subnet manually, use this
// Ethernet.begin(mac,ip,gateway,subnet); // Use this line instead if you’ve manually set all the parameters

Udp.begin(localPort); //Setup UDP socket on port defined earlier

Serial.begin(9600); //Start Serial Communications with PC

pinMode(LED_Pin,OUTPUT); //Designate pin 6 as Output Pin

}

void loop()
{

int pwmVal; // Integer that will hold our PWM values for later use

// if there’s data available, read a packet
int packetSize = Udp.parsePacket(); // note that this includes the UDP header
if(packetSize)
{
packetSize = packetSize - 8; // subtract the 8 byte header
Serial.print("Packet size: ");
Serial.println(packetSize);

// read the packet into packetBuffer and get the senders IP addr and port number
Udp.read(packBuff,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Message: ");
Serial.println(packBuff);

/* PWM - If we move a slider on Ardumote, it sends in a 3 digit value attached to the message of the slider.

For example, if your message is set to be “PWM” and your slider is halfway set (slider value is 127),
then your actual sent message will be received as “PWM127”. Therefore, to set the Pin’s PWM value, you simply
extract the last 3 digits of your message and use that as your PWM value (see below):

*/

// Assuming our packBuff’s contents at index values 3-5 are our PWM values, you can convert them to an int using this:

pwmVal = (packBuff[3] - ‘0’)*100 + (packBuff[4] - ‘0’)*10 + (packBuff[5] - ‘0’); //Get PWMXXX message, and use XXX to set an int between 0 and 255.

//////////////////////// Pin 10 (LED_Pin) /////////////////////////////////////

if (packBuff[0] = ‘P’ && packBuff[1]==‘W’ && packBuff[2]==‘M’) // Wait for “PWMXXX” and use XXX as value for PWM
{

analogWrite(LED_Pin,pwmVal); //Set LED_Pin to PWM Value

Serial.println(“PWM on Pin 10”); //Write notification

}

else if (packBuff[0] = ‘P’ && packBuff[1]==‘10’ && packBuff[2]==‘H’) // If we get the message “P10H”, then set LED_Pin (10) HIGH
{

digitalWrite(LED_Pin,HIGH); //Turn on LED_Pin

Serial.println(“LED ON”); //Write notification

Udp.beginPacket(iPhoneIP,iPhonePort);
Udp.write(“LED 10 is ON”); // Send Message back to iPhone
Udp.endPacket();

}

else if (packBuff[0] = ‘P’ && packBuff[1]==‘10’ && packBuff[2]==‘L’) // If we get the message “P10L”, then set LED_Pin (10) LOW
{

digitalWrite(LED_Pin,LOW); //Turn off LED_Pin

Serial.println(“LED OFF”); //Write notification

Udp.beginPacket(iPhoneIP, iPhonePort);
Udp.write(“LED 10 is OFF”); // Send Message back to iPhone
Udp.endPacket();

}

}

delay(20);
}