create local network

Discussion about any of the included sketches (i.e. WebServer), or user-generated applications.

create local network

Postby stephanschulz » Thu Aug 06, 2009 7:10 am

hello all.

i would like my arduino to communicate with an iPhone. (not through serial)
when using the wiShield can it create a local network that an iPhone could connect to. or does the wiShield always need a wifi router in order to talk to other devices?

thanks,
stephan.
stephanschulz
 
Posts: 19
Joined: Thu Aug 06, 2009 7:00 am

Re: create local network

Postby GregEigsti » Thu Aug 06, 2009 9:12 am

This is fairly simply done! Here is what I just did to get the adhoc network scenario working:

1) Follow the WebServer sample sketch instructions to build the sample WebServer
2) Before building and uploading the sketch to the Arduino/WiShield make the following change to the WebServer sketch file (the one with the setup() and loop() functions in it) - to enable adhoc mode on the WiShield:

Change this line:
Code: Select all
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

To this:
Code: Select all
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;

3) Build the modified WebServer sample and upload to the Arduino/WiShield
4) Remember the IP address of the WiShield; you will need this later (by default it is 192.168.1.2)
Note: I never modify the sample scripts as I like to keep them pristine; I always copy them to a new location before modifying.

Now on the iPhone

1) Go to Settings -> Wi-Fi and choose the ASYNCLABS network. This network name comes from the following line in the sample sketch:
Code: Select all
const prog_char ssid[] PROGMEM = {"ASYNCLABS"};

2) After you have selected the ASYNCLABS WiFi network touch the little white/blue arrow at the right of the ASYNCLABS entry in the Wi-Fi Networks page. This will allow you to configure the iPhone's usage of this adhoc WiFi network.
3) Select the Static button to allow you to set the IP address and Subnet mask
4) Change the IP address to: 192.168.1.1 and the Subnet Mask to: 255.255.255.0 - then back out of the net settings
5) Go to Safari and surf to 192.168.1.2 (or whatever address your WiShield is using) and see the WiShield sample WebServer page in all of its glory!

I noticed that the iPhone would stay connected to the ASYNCLABS adhoc network for random amounts of time and then default back to my home's "real" WiFi network. Not sure if this is a problem with the WiShield's adhoc mode or the iPhone. I suppose that once this is working you could do the same on your computer to see if it held onto ASYNCLABS any better...

These steps can be easily adapted to any of the other WiShield sample sketches. If you don't already have a WiFi network in place adhoc is a fine way to go; however if you do have a WiFi network in place I'd recommend not using adhoc and just put the Arduino/WiShield onto the network as any other device. This way you can access the Arduino/WiShield from any device on the network and not just those on the adhoc network.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1075
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: create local network

Postby hank7725 » Wed Sep 16, 2009 10:30 pm

Hi All,

I have been able to get the SimpleServer to serve up a web page on my infrastructure network, but can't seem to get the adhoc to work. I am especially interested in the iPhone instructions above, which I have followed to a tee. My iphone recognizes the adhoc network, and I can change the IP address to Static and the IP address that is in my Sketch. But when I go to Safari and enter the IP address, nothing happens. Also when I select the adhoc network on the iphone, it clicks over to 3G.

I am kind of newbie, so I am sure it is something obvious I am overlooking, but some help would be much appreciated...

Thanks,
Hank
hank7725
 
Posts: 2
Joined: Wed Sep 16, 2009 10:21 pm

Re: create local network

Postby stephanschulz » Thu Sep 17, 2009 6:01 am

i have only done this with an ipod touch and it worked fine. all i did was follow these instruction.

i know this does not help you much.

good luck.
stephanschulz
 
Posts: 19
Joined: Thu Aug 06, 2009 7:00 am

Re: create local network

Postby hank7725 » Thu Sep 17, 2009 11:05 am

Actually, it helps me a lot. It pretty much confirms my suspicion that I have something funky going on in my, non-Wishield, end of things.

Thank you for taking the time to respond.

Hank
hank7725
 
Posts: 2
Joined: Wed Sep 16, 2009 10:21 pm

Re: create local network

Postby sketchdre » Wed Oct 21, 2009 2:45 am

Hi guys,

I'm having problems connecting to the WiShield with my iPod Touch.
It worked when I first got the WiShield, I uploaded the Webserver example and followed the steps on this page, although I also had to add 192.168.1.1 to the "Router" in the Wifi Settings on the iPod, not sure why. Nethertheless it worked.

But what happens now is that even the Webserver sketch doesn't work. The iPod has connection to the WiShield, it recognises it, but doesn't open the web page, it just says "Connecting..." on the screen and that's it, nothing happens.
I tried changing the IP addresses, resetting the WiShield, etc, etc, but nothing helped so far.
And I don't have a Wifi router to try to load the web page on the computer.

I just don't get why everything worked at first, but not anymore...
I read somewhere that some new versions of iPod have problems with Wifi, but I don't remember that I did any upgrades recently...
And I'm running Arduino Duemilanove with Atmega 168, but I don't think it should be a problem for such a small sketch.
Hope someone can point me in the right direction.
Thanks!
sketchdre
 
Posts: 7
Joined: Wed Oct 21, 2009 2:21 am

Re: create local network

Postby GregEigsti » Wed Oct 21, 2009 11:15 am

Please post your sketch - makes it a lot easier for others to help.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1075
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: create local network

Postby sketchdre » Thu Oct 22, 2009 12:06 pm

Hi,
I'm using the Webserver sketch for the moment, but doesn't really matter which sketch I'm using, the iPod just doesn't load the page.
Code: Select all
/*
* Web Server
*
* A simple web server example using the WiShield 1.0
*/

#include <WiShield.h>

#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"};      // max 32 bytes

unsigned char security_type = 0;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};   // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {   0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00,   // Key 1
                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00,   // Key 2
                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00   // Key 3
                        };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

void setup()
{
   WiFi.init();
}

// This is the webpage that is served up by the webserver
const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><h1>Hello World!! I am WiShield</h1><form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"LED1\"></input></form></center>"};

void loop()
{
   WiFi.run();
}

In the Wifi Settings of the iPod, I enter the IP address (192.168.1.1) and Subnet Mask (255.255.255.0) in "Static" as instructed in this topic. Maybe I have to fill in other fields??

I got it working again after my previous post, but I have no idea how. I was clearing cache on the iPod, re-entering IP adresses, etc., and eventually it worked.
But once I unplugged the Arduino from the computer and connected it again the next day, the same thing happened. The iPod just doesn't load the page and says "loading..." or "connecting..." on the screen.
Could it be something with the Adhoc mode?
sketchdre
 
Posts: 7
Joined: Wed Oct 21, 2009 2:21 am

Re: create local network

Postby sketchdre » Mon Oct 26, 2009 3:05 am

I guess I've figured out how to fix the problem of my iPod not reconnecting to the WiShield after it's been unplugged from the computer.

What I did is:
- in the Wifi settings of the iPod go into "Asynclabs" network tab and click "Forget this network" (IP address and Subnet Mask will be erased but they will reappear once we connect manually)
- go back and under "Choose network" click "Other"
- type the name of your network (i.e. "Asynclabs" + security settings if you have any) and click "Join"
iPod should now reconnect with the WiShield network and load the webpage in Safari.

Don't know whether it's only my problem and why this happens, but for now this is the only way how I can reestablish a connection between iPod Touch and WiShield.
sketchdre
 
Posts: 7
Joined: Wed Oct 21, 2009 2:21 am

Re: create local network

Postby iphoneczar » Fri Jan 22, 2010 9:29 am

The ad hoc instructions worked perfectly for my 3GS iPhone. However, I'm using the WiServer rather than WebServer mode (don't forget to comment/uncomment the appropriate defines in apps-conf.h in the wishield library. I've attached my sketch for reference. I run the sketch, wait for the red light to indicate that the WiShield is up. Then go into iPhone settings, select the SSID (ayefon.com) in my case. Then edit the settings to use static IP. I set the IP of the iPhone to any IP on the subnet (in my case 192.168.1.x) OTHER than the IP used by the wishield. Netmask is 255.255.255.0
Then save those settings. Re-enter settings and check to make sure they "stuck". Then I just go to browser and hit 192.168.1.152/on or 192.168.1.152/off to turn my LED (connected between pin 7 and gnd) on and off. I LOVE this shield. It's going to open up a whole raft of possibilities for cool iPhone apps.

-dB
http://www.ayefon.com
Code: Select all
/*
* A simple sketch that uses WiServer to serve a web page
*/


#include <WiServer.h>

#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2
  int ledPin =  7;    // LED connected to digital pin 7

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,152};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"AYEFON.COM"};      // max 32 bytes

unsigned char security_type = 0;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"1234567"};   // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 1
              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 2
              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   // Key 3
            };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
//unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------


// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
 
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/on") == 0) {
        digitalWrite(ledPin, HIGH);   // set the LED on
        // Use WiServer's print and println functions to write out t\he page content
        WiServer.print("<html><body><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />");
        WiServer.print("<table width=\"320\"><tr><td>");
        WiServer.print("<a href=\"off\">Hello I'm on! Turn me off.</a></td></tr>");
        WiServer.print("</table></body></html>");
       
        // URL was recognized
        return true;
    }
    if (strcmp(URL, "/off") == 0) {
        digitalWrite(ledPin, LOW);   // set the LED off
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html><body><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />");
        WiServer.print("<table width=\"320\"><tr><td>");
        WiServer.print("<a href=\"on\">Goodbye I'm off! Turn me on.</a></td></tr>");
        WiServer.print("</table></bdy></html>");
       
        // URL was recognized
        return true;
    }
    // URL not found
    Serial.println("error");
        WiServer.print("<html>");
        WiServer.print("No such page!");
        WiServer.print("</html>");
    return false;
}


void setup() {

    // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
 
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

void loop(){

  // Run WiServer
  WiServer.server_task();

  delay(10);
}
iphoneczar
 
Posts: 1
Joined: Fri Jan 22, 2010 9:11 am

Next

Return to Sketches and Applications

Who is online

Users browsing this forum: No registered users and 1 guest

cron