Go Down

Topic: Using an arduino uno and a wishield from asynclabs (Read 956 times) previous topic - next topic

Emmet

I have two arduino uno's with a wishield attached to each one is there any way to send a signal from a switch on one board to the other board across the internet so as to turn something on like an LED.I am hoping this is possible.I am new to using both arduino and the wishield and any help would be much appreciated.

Emmet

robtillaart

Quote
.I am hoping this is possible

Perfectly possible, there are many ways,

- you could send low level UDP packets from one to the other
- you could setup a TCP connection and send commands over it.
  more specific
  - build a webserver on one UNO and let the other connect to it. advantage it can be tested from any PC.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Emmet

Quote
build a webserver on one UNO and let the other connect to it. advantage it can be tested from any PC.

I have got the simple server example code from asynclabs which builds a webserver with a button on it to turn on the led on a specific ip address.

So how is it now a let the second UNO connect to that webserver so I dont have to push the button on the webpage but now I do it from a switch or button from the second UNO board.

Also if you have any code that is doing something like this it would be much appreciated.

Thank you
Emmet

robtillaart

DOn't know your webserver sketch but you probably need to implement a HTTP POST command.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Emmet

#4
Jul 14, 2011, 11:36 am Last Edit: Jul 14, 2011, 11:48 am by Emmet Reason: 1
Here is a copy of my code below of the UNO serving up a webpage with a button to turn on the led.

Code: [Select]

#include <WiServer.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2


#define LED 8


// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,3}; // 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 = {"********"}; // 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_INFRA;

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)
{
 Serial.println("SendMyPage_URL=");
 Serial.println(URL);
 Serial.println("SendMyPage_URL");
 
 if (strcmp(URL, "/") == 0)       // Check if the requested URL matches "/"
 {
   Serial.println("!!!!!  Default request.  !!!!!!");
   
   Links ();
   return true;          // URL was recognized
 }  
 else if (strcmp(URL, "/0?0=LED") == 0)
 {
   Serial.println("LED");
   
   WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
   
   digitalWrite(LED,HIGH);           //Turn on the LED          
   delay(10000);  
   digitalWrite(LED,LOW);           //Turn off the LED
   delay(5000);
   
   WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
   return true;        // URL was recognized
 }
 return false;           // URL not found
}

void Links ()
{
  WiServer.print("<html>");
  WiServer.print("<title>LED Switch</title>");
  WiServer.print("<center>Press button to turn on LED.</center>");
  WiServer.print("<html><center><br /><form method=\"get\" action=\"0\">Toggle Switch:<input type=\"submit\" name=\"0\" value=\"LED\"></input></form></center><br />");
  WiServer.print("<center>By Emmet Fealy</center><br />");
  WiServer.print("</html>");  
}

void setup()
{
 // Initialize WiServer and have it use the sendMyPage function to serve pages
 WiServer.init(sendMyPage);
 
 pinMode(LED, OUTPUT);
 digitalWrite(LED,LOW);          //Turn LED off
 
 // 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);
}


What way do you think I will be able to get the other arduino connected to this page too?

Also in this code what happens is I press the button on the webpage and it redirects to a new page so to turn on the LED once and then is refreshed back to the original page.This works perfectly sometimes and other times it will turn on the LED twice   
before returning to the original page. I dont kno why this is happening.

Thank you for your help,
Emmet

Go Up