Pages: 1 [2] 3   Go Down
Author Topic: Set/Change IP Address Web Form - Ethernet Shield  (Read 7352 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had to change the Ethernet.cpp file b/c I noticed gateway was being set as IP then changing last octet only and subnet was statically set here as well.

Before:
//uint8_t gateway[4];
  //gateway[0] = ip[0];
  //gateway[1] = ip[1];
  //gateway[2] = ip[2];
  //gateway[3] = 1;

//uint8_t subnet[] = {
    //255, 255, 255, 0   };


After:
Code:
#include "w5100.h"
#include "Ethernet.h"

uint8_t EthernetClass::_state[MAX_SOCK_NUM] = {
  0, 0, 0, 0 };
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
  0, 0, 0, 0 };

void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway)
{
  begin(mac, ip, gateway);
}

void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway, uint8_t *subnet)
{
  W5100.init();
  W5100.setMACAddress(mac);
  W5100.setIPAddress(ip);
  W5100.setGatewayIp(gateway);
  W5100.setSubnetMask(subnet);
}

EthernetClass Ethernet;
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Jo3ri,
Fun an Arduino "basic" sketch smiley
Logged

Rob Tillaart

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

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@robtillaart

I know  smiley But it really helps to write down this kinds of things. Otherwise I get lost in my own coding  smiley-confuse
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Update:  1st through 3rd IP octet is not saving correctly. Working on a fix.

  
« Last Edit: March 23, 2011, 02:17:31 pm by techadmin » Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Meanwhile I found out your working on a different Arduino version (mine is 0.22) also I have the new Arduino Ethernet Shield. But the Idea remains the same.

FYI: I thanks to your sketch, I managed to use EEPROM for storing mac, ip, gw, sub and type (static, dhcp or unknown) and showing this info in the webpage.

The sketch starts with setting the pre-sets the first time and writes a knowing bit. The next time it runs, the sketch doesn't use pre-sets, but reads EEPROM: when type is stored as static, it takes static otherwise it takes dhcp.

Now I need to work on the GET forms in html. I haven't found out how to do that yet, but I'll get there.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using 022?  Sounds like good progress.
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, then it must be a different Ethernet Shield.  smiley

Now you're sending HTML in a different way then I do, I use:

Client.print("<HTML><body>some text or other HTML code</body></HTML>");

Now I was hoping to get help out of your sketch for the forms part, but I can't  smiley-confuse

I'll have to figure it out myself  smiley-sad
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I started with client.print as well and used all of the SRAM doing so.

My sketch is using the Flash library which easily puts all that html into program memory,  dramatically improving performance.
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Aha, I See. Well I found a way to do the same, but I'm using the avr/pgmspace.h library. This way I can put every thing in The Flash Memory with PROGMEM and I let it flow through a buffer of let's say 100 bytes (SRAM).

This should mean I could use your HTML code for the forms. Could you filter them out and post them? Especially t he part where you get the info out of the forms.

Thanks.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the basic form, you will see from my code that these are simply wrapped in

Code:
client << F("       ") << "\n";

You can accomplish the same with Progmem, not sure which is more memory efficient.  I struggled freeing memory for a while and this worked best for me, at least it seemed the easier method.  I will be interested to see your take on this as well.

When the form is posted, a get string is created such as this:

http://172.31.1.50/?i1=172&i2=31&i3=4&i4=50&s1=255&s2=255&s3=255&s4=0&g1=172&g2=31&g3=1&g4=1&END=END

That string is saved to inString initially then to stringOne:
Code:
String stringOne = inString;

For substring processing I am using indexOf to find the number between all of the & and = symbols.

Code:
//////////////     CHANGE IP ADDRESS FORM /////////////////////////////////////////////////////

<BR><BR><B>Change IP Address:</B>

<form name=\"changeipaddress\" action=\"\" method=\"get\">
<TABLE width=\"325\">
<tr>     
<td>IP Address:</td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i1\" value=\"172\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i2\" value=\"31\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i3\" value=\"1\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"i4\" value=\"50\"></td>     
</tr>

<tr>
<td>Subnet Mask:</td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s1\" value=\"255\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s2\" value=\"255\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s3\" value=\"255\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"s4\" value=\"0\"></td>     
</tr>

<tr>
<td>Gateway:</td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g1\" value=\"172\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g2\" value=\"31\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g3\" value=\"1\"></td>     
<td><input type=\"text\" size=\"3\" maxlength=\"3\" name=\"g4\" value=\"1\"></td>     
<td><input type=\"hidden\" size=\"3\" maxlength=\"3\" name=\"END\" value=\"END\"></td>     
</tr>
         //notice the hidden form element placed in order to create a final "&" character in the get string

<tr>
<td align=\"center\" colspan=\"5\"><input type=\"submit\" value=\"Update Network Configuration\"></td>
</tr>     

<tr>
<td align=\"center\" colspan=\"5\">*After changing IP address<BR>change url in browser</td>
</tr>     
</TABLE>     
</form>
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For any followers, this project is in collaboration with this one: http://arduino.cc/forum/index.php/topic,55044.0.html

If your sending your project to someone with no development experience, maybe your dad, or a potential client you've built a prototype for, or your using your Arduino in multiple locations (and not all have DHCP servers), then you just want to be able use the product out of the box on a network, like a home router, plug and play, this will be the solution.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The revised web form code is now working properly (for me at least), see attachments.


* Capture1 - Network Settings Web Form.JPG (46.58 KB, 795x505 - viewed 31 times.)

* Capture2 - Network Settings Web Form.JPG (43.61 KB, 794x479 - viewed 30 times.)
* Network_Settings_Form.pde (20.99 KB - downloaded 33 times.)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The revised web form code is now working properly (for me at least), see attachments.

To bad it doesn't work on my Uno and latest ethershield (microSD reader).
Can't ping the IP adres.

If I Disabling these settings I can ping the arduino but can't access the webpages:

  //EEPROM address to  array
//  byte mac[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//  byte ip[4] = { ipAaddress_READ, ipBaddress_READ, ipCaddress_READ, ipDaddress_READ };
//  byte gateway[4] = { gwAaddress_READ, gwBaddress_READ, gwCaddress_READ, gwDaddress_READ };   
// byte subnet[4] = { subnetAaddress_READ, subnetBaddress_READ, subnetCaddress_READ, subnetDaddress_READ };   
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
byte mac[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Do you have multiple Arduino's with the same MAC address? if so change them asap as they should be unique,

just a thought.
Logged

Rob Tillaart

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
byte mac[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Do you have multiple Arduino's with the same MAC address? if so change them asap as they should be unique,

just a thought.

Sorry No just one. smiley-confuse

I found out that the program always jumps to void mkmethernetRESET().
Because I haven't set a new IP address the EEprom values are wrong.
I forced the program to jump to void mkmethernetDEFAULTS().
Now I get only a blank page and I can ping the Arduino.


Logged

Pages: 1 [2] 3   Go Up
Jump to: