Pages: [1]   Go Down
Author Topic: IP for ethernetshield  (Read 787 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I have a new arduino controller and this is really fun working with, but I have a problem with setting op an ethernetconnection. I tried many times but it doesn't work.

This is my code. I have two led's. One that says everything is good and the otherone says there is a problem. The only led that is given light is the one with the error

Code:
#include <Ethernet.h>

byte mac[] = { 0x00, 0x1C, 0xF0, 0xFB, 0x6B, 0x8A };
byte ip[] = { 192, 168, 0, 2 };                      // this is the ip within my lan
byte gateway[] = { 192, 168, 0, 1 };                  // neccessary to get access to the internet via your router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 216, 239, 59, 104 };               // Google.nl

int gledPin =  13;    // LED connected to digital pin 13 yellow one
int fledPin =  12;    // LED connected to digital pin 12 red one


Client client(server, 80);

void setup()
{
   pinMode(gledPin, OUTPUT);  
 pinMode(fledPin, OUTPUT);  
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600);

  Serial.println("connecting...");

  if (client.connect()) {
       digitalWrite(gledPin, HIGH);   // set the LED on
  } else {
    Serial.println("connection failed");
        digitalWrite(fledPin, HIGH);   // set the LED on
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}




This i a copy of my d-link router
WAN
Connection Type : DHCP Client .
QoS Engine : Active .
Cable Status : Connected .
DNS Status : Online .
Network Status : Established .
Connection Up Time : 0 Day 9 Hour 19 Min 40 Sec .
MAC Address : 00:1C:F0:FB:6B:8B .
Authentication & Security :   .
IP Address : 192.168.0.2 .
Subnet Mask : 255.255.255.0 .
Default Gateway : 192.168.0.1 .
Primary DNS Server : 192.168.0.1 .
Secondary DNS Server : 0.0.0.0 .
 .
LAN
MAC Address : 00:1C:F0:FB:6B:8A .
IP Address : 192.168.1.1 .
Subnet Mask : 255.255.255.0 .
DHCP Server : Enabled .


Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
you have your lan ip as 192,168,1,1 yet in you sketch you have your adapter ip as 192,168,0,2 maybe this should be 192,168,1,2
for instance my gateway is 192,168,2,1 so my ethernet shield ip is set to 192,168,2.15   15 because other family members use laptops within the house so theres no chance of bumping into one of them. it's confusing but maybe this will help
Logged

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

Try chaning the ip on the board from 192.168.0.2 to somthing other, as it wil make a conflict if both your computer and the arduino have the same ip. But keep within the same subnet ( 192.168.0.x)

-joakim
« Last Edit: April 04, 2010, 05:03:47 pm by zyruz » Logged

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

Thank you for the aswers, but they didn't work out.

I worked it out that the lan port one my router went on, but when i loged in i my router there was no sighn he was connected. I tried multi codes, but alle with no succes.

But how can I set an IP that is not giving a way by the router. The router is the one who wille give all the IP's adresses, right. But for the code I need to set it before I connected to the router.

Or do I need to connect the route by lan and the usb to the computer at the same time and than I can see witch Ip he will set.

Thank you for your reply. My English is not really good so I hove you can understand it.

Thanks
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 626
Posts: 34123
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But how can I set an IP that is not giving a way by the router.

You need to turn off the DHCP system at your router and assign the IP addresses manually.

Edit. yes I did  smiley
« Last Edit: April 06, 2010, 03:49:51 am by Grumpy_Mike » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 133
Posts: 6749
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote
But how can I set an IP that is not giving a way by the router.
You need to turn off the DNS system at your router and assign the IP addresses manually.
You probably mean DHCP...

You may have to dig out the manual for your router.  MOST routers will have a mechanism for allowing some hosts to have "static" IP addresses, rather than ones assigned by the router.  As long as these are on the same network as the assigned addresses, routing and etc will work fine.

For example, on my Linksys router, the DHCP configuration tab has a spot for "starting IP address" and "maximum number of clients", which I have set like 192.168.1.100 and 50.  That means that the router will automatically assign addresses from 192.168.1.100 to 192.168.1.150.  All the other addresses on 192.168.1.x can be used by devices that do not use DHCP for configuration  (the router itself is 192.168.1.1, there's a wireless Access Point at 192.168.1.2, etc...)
Logged

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

Thanks it works. I update my router and than i switch the DHCP Server off.

The last question i have is a php issue. I wrote the next code, and the php script really worked, so there is a communication.

How can I read the php answer in the board.

This is the code and this is the script

Code:
#include <Ethernet.h>

byte mac[] = { 0x00, 0x1c, 0xf0, 0x90, 0xd7, 0x23 };
byte ip[] = { 192, 168, 1, 109 };
byte server[] = { 79, 170, 43, 15 }; //lollie
byte gw[] = { 192, 168, 1, 1 };   //your router's IP address
byte subnet[] = { 255, 255, 255, 0 };    //subnet mask of the network
int entrada = 0;
int data = 0;
int tempPin = 2;  // I det her tilfælde sendes temperaturen fra pin 2 til en sql server
Client client(server, 80);

void setup()
{
Ethernet.begin(mac, ip, gw, subnet);
pinMode(tempPin, INPUT);
Serial.begin(9600);
Serial.println("Starten van programma");
}
void loop()
{
senddata();
delay(100000);      
}

void senddata()
{
data = analogRead(tempPin);           //Laeser analog værdi
Serial.println();
Serial.println("Verbinding van start.............");
delay(1000);                                    //Forhindrer forbindelsen i at hænge

if (client.connect()) {
Serial.println("Is verbonden: Verturen van de data");
client.print("GET http://www.lollie-webdesign.nl/test.php?go=temp&temp=");
client.print(data);
client.println(" HTTP/1.1");
client.println("Host: www.lollie-webdesign.nl");
client.println();
client.read();
Serial.println("data is verstuurd");
}

else
{
Serial.println("Niet verbonden dus een fout");
}
//}
 //stop client
 client.stop();
 while(client.status() != 0)
{
  delay(5);
}
}

This is the PHP code
Code:
<?
mysql_connect('localhost', 'xxxxxxxx', 'xxxxxx') or die(mysql_error());
mysql_select_db('xxxxxxxxx') or die(mysql_error());

if ($_GET['go']=="temp") {

  $query = "INSERT INTO temp (temp, date) VALUES ('$temp',CURDATE())";
$result = mysql_query($query) or die(mysql_error());
echo "The data has been added";
}
?>


I my communication with serialmonitor I see al the Print, but not the one of client.read(); There is no line "The data has been added"

I tried every code but it doesn't work
Logged

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

You do not read the page that are beeing sent back to you.
The only thing I see you are doing is: client.read();
But this alone wont do annything.
See http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238640832/0 for example on how to read a response.

--joakim
Logged

Pages: [1]   Go Up
Jump to: