Want to control an Arduino over the web

I've got the communication on my local network up and running with my Arduino USB and Ethernet shield.
Now i want to control it over the web, but i have little, to no knowledge of how i should approach the project.
I've read somewhere that i need to get a domain with a static IP address. Is this the only way or is there another way for me to solve this problem?
If my only option is to get a domain with static IP address does anyone here know of a decent provider?

Thanks!

-Rindis

I don't think you need a static IP, you just need to know your IP to connect to. If you need to know it always, you could make a small app to find your IP and upload it somewhere (your FTP space maybe?) so you can read it from anywhere on the net, and have that run as a service at home. I used this method for a game server I wrote some time ago. I wonder if you can do the same with the arduino itself and cut out the PC altogether?

Yeah. My plan is to have my Arduino board with the Ethernet shield, connected to my router at my home, acting as a web server. This way i can connect to it from my school to check the temperature or if I remembered to turn of the coffee maker... You get the idea :slight_smile:

Got any suggestions as how to solve this problem?

-Rindis

Ok, i've solved the problem and got my arduino up and running as a web server. My setup at the moment is just controlling a LED with the arduino board and ethernet shield. I've had some friends of mine all over the country try and turn my LED on and off with great success. But no another problem occurred. The WiZnet chip on the ethernet shield gets hot very quickly and i dont know if there is something wrong with my code that does it. So i need some help from you guys to help me see if there is something wrong with the code :slight_smile:

/*

  • Web Server
  • A simple web server that shows the value of the analog input pins.
    */

#include <Ethernet.h>
#include <WString.h>

byte mac[] = { 0x00, 0x23, 0x8b, 0x3f, 0xb0, 0xa0 };
byte ip[] = {192, 168, 1, 4};
byte gateway[] = {192, 168, 1, 1};
byte subnet[] = {255, 255, 255, 0};
String readString = String(35);

const int ledPin = 4;

Server server(80);

void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(ledPin, OUTPUT);
server.begin();
Serial.begin(9600);
}

void loop()
{
Client client = server.available();
if (client)
{
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.print(c);
if(readString.length() < 35)
{
readString.append(c);
//Serial.println(readString);
}
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank)
{
// send a standard http response header //
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
/////////////////////////////////////////
client.println("");
client.println("");
client.println("");
client.println("");

if(readString.contains("LED=ON"))
{
Serial.println("PÅ!");
digitalWrite(ledPin, HIGH);
}
if(readString.contains("LED=OFF"))
{
Serial.println("AV!");
digitalWrite(ledPin, LOW);
}
readString = 0;

}
if (c == '\n')
{
// we're starting a new line
current_line_is_blank = true;
}
else if (c != '\r')
{
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}

How are you solving the dynamic IP issue?

And as to the heating, the only code that executes in the loop usually is:

Client client = server.available();

Is that right? If that is happening thousands of times a second I don't know if it would heat up the chip or not. You could add:

Client client = server.available();
delay(100); // Check 10 times a second

That might help or do nothing. Can't hurt to test it! Oh, and a heat sink might be an obvious solution too.

The rest of the code only runs intermittently when data is being moved about as far as I can see, so that can't cause excessive heating (that you might be able to avoid).

I have a domain forwarded to my routers IP. Then i did some port forwarding on my router.

I've have been testing with some serial prints and it seems like the program runs in the while loop when there is nothing happening on the web server.

Putting a delay in the while loop will cause a longer reaction time from when i push "ON" 'til the LED turns on.

Thanks for reply!

-Rindis

Well yes but who notices 1/10th of a second?

I plan to do a similar type thing with the Ethernet shield but going at it in the opposite direction.
I will have a dynamic web site (django) that user logs into and can see the current status of the arduino and also send commands. The Ethernet shield will send a POST/GET to the server every second or so (every 10 seconds might be plenty). The shield will send all it's current status on the web request and the server will send back the latest commands from the user.
Still busy getting the hardware stuff working so haven't even plugged in the Ethernet shield yet.

That sounds interesting and is actually what I've been thinking on doing these last days. However I have pretty much no knowledge on how to program the HTML code on the Arduino.
Will your solution require the web site to act as the 'server' and the arduino as a 'client'? Or do you plan to have the web site run on the arduino and set it up as a web server?

-Rindis

I plan to have the arduino act as the client and the web site as the server. I think it's much easier for the arduino to make requests through my firewall at home than to try and setup some type of static IP or sandbox or whatever would be needed for the arduino to act as a web server. This also makes it easy to develop a web site that can handle communicating with many arduinos at the same time and everything is in one central location.
You can easily create a development web server on your home computer and worry about getting web hosting once things are ready to deploy.
I use Sun's VirtualBox to run a Linux VM on my desktop that is configured as a web server (actually haven't setup to run django yet).

Hm, when you find a domain provider that let's you have a personal static ip address for you web page let me know.
I've asked a few providers and they told me that this was not possible since many domains share the same ip. And since the arduino client needs a ip address to connect to that setup seems impossible.

-Rindis

My netgear router has a setup for use with the dynamic DNS services like www.dyndns.org that would handle the ip address issue.You might check your router to see if it has this feature. You might also check with these providers to see what needs to be sent to keep your ip address updated. Looks like a hostname, username, and password need to be sent the dynamic ip provider for upadting.
Below is the link to the info page: