France
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« on: July 16, 2012, 06:54:01 am » |
hello world, I'm a novice in the Arduino-wise and I need some help to use the Arduino Ethernet board.
I'm ask for the IP address to the network administrator, so I have the MAC address and the IP address for my board. So I plug my board thank a wire to the Eternet plug in the wall, and I try to connect myself to the server by entered the IP address on my browser.
But the serial monitor return only: chat server address: 180.88.107.66.
My questions are: 1/ Do I make something wrong? 2/ Do I need something else to connect the Board correctly? 3/Why the "client connection doesn't work? 4/How can I connect a "client" to the server ?
I hope someone can help me... And thank a lot for your help and your time.
Didine
The sketch that a use is a example of Ethernet connection, it's the following sketch: /* Chat Server A simple server that distributes any incoming messages to all connected clients. To use telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. Using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe */
#include <SPI.h> #include <Ethernet.h>
// Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x76E, 0x12 };
// telnet defaults to port 23 EthernetServer server(23); boolean alreadyConnected = false; // whether or not the client was connected previously
void setup() { // initialize the ethernet device Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }
Serial.print("Chat server address:"); Serial.println(Ethernet.localIP()); }
void loop() { // wait for a new client: EthernetClient client = server.available();
// when the client sends the first byte, say hello: if (client) { if (!alreadyConnected) { // clead out the input buffer: client.flush(); Serial.println("We have a new client"); client.println("Hello, client!"); alreadyConnected = true; }
if (client.available() > 0) { // read the bytes incoming from the client: char thisChar = client.read(); // echo the bytes back to the client: server.write(thisChar); // echo the bytes to the server as well: Serial.write(thisChar); } } }
|
|
|
|
« Last Edit: July 16, 2012, 12:36:49 pm by didine97369 »
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Online
Faraday Member
Karma: 50
Posts: 3450
|
 |
« Reply #1 on: July 16, 2012, 07:11:34 am » |
You will not be able to access any ip except localnet with these settings. Considering the subnet mask, then the ip and gateway must share the same first three numbers. IPAddress ip(130,88,107,66); IPAddress gateway(130,88,106,250); IPAddress subnet(255, 255, 255, 0);
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #2 on: July 16, 2012, 07:42:59 am » |
surfferTim ,
Do you mean that I can't use the network from my office ? But it's a project for a lab here... How can have a access to the localnet. On the network I can see the other PC connected, but not my board, It's normal or not ?
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Online
Faraday Member
Karma: 50
Posts: 3450
|
 |
« Reply #3 on: July 16, 2012, 07:49:27 am » |
That is not what I meant. You have one of those setting incorrect, but I can't tell which. This is valid: IPAddress ip(130,88,106,66); IPAddress gateway(130,88,106,250); IPAddress subnet(255, 255, 255, 0);
This is valid: IPAddress ip(130,88,107,66); IPAddress gateway(130,88,107,250); IPAddress subnet(255, 255, 255, 0);
This is valid: IPAddress ip(130,88,107,66); IPAddress gateway(130,88,106,250); IPAddress subnet(255, 255, 254, 0);
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #4 on: July 16, 2012, 08:01:18 am » |
I try each and it failed too. I have to put the IP that my administrator give me for the board? it's 130.88.107.66 for the first but for the rest I don't know what I have to put ....
Can you explain me a bit about how the connection is working? I don't really understand what is a client in this sketch.
Thank a lot for your answers!!!
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Online
Faraday Member
Karma: 50
Posts: 3450
|
 |
« Reply #5 on: July 16, 2012, 08:05:48 am » |
I have to put the IP that my administrator give me for the board? it's 130.88.107.66 for the first but for the rest I don't know what I have to put ....
If that is all the administrator gave you, a new administrator may help.  Minimum setting info required for a static ip: ip subnet gateway dns If your administrator needs help with this, I charge money for that.
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 40
|
 |
« Reply #6 on: July 16, 2012, 09:16:16 am » |
You will not be able to access any ip except localnet with these settings. Considering the subnet mask, then the ip and gateway must share the same first three numbers. IPAddress ip(130,88,107,66); IPAddress gateway(130,88,106,250); IPAddress subnet(255, 255, 255, 0);
I agree with SurferTim . I try a little explanation (but it's difficult for me to explain in english ...) ... To define your network, you must define several values : an Ip address and a subnet mask. If you want to go out of your subnet, you address the gateway address, on the same subnet. With those two numbers, you calculate (in bits or with tables) the subnet area (you can define a smal subnet with 4 computers for example). I see that your gateway is not on the same subnet than your Arduino (130.88. 106.250 is not on the same subnet than 130.88. 107.66). The subnet mask (at 255.255.255.0) limit your subnet into those addresses : 130.88.107.1 to 130.88.107.254. 130.88.1.0 is your subnet address and 130.88.107.255 is the broadcast address (i.e. you ping at this address and all the computers of your subnet are pinged). That means that your Arduino can't go out of your subnet. The DNS serves to convert internet types addresses onto Ip addresses (for exemple " www.arduino-server.net" onto "130.88.107.66"). I hope that you will understand my explanations ...
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #7 on: July 16, 2012, 11:05:57 am » |
I agree with SurferTim . I try a little explanation (but it's difficult for me to explain in english ...) ... To define your network, you must define several values : an Ip address and a subnet mask. If you want to go out of your subnet, you address the gateway address, on the same subnet. With those two numbers, you calculate (in bits or with tables) the subnet area (you can define a smal subnet with 4 computers for example). I see that your gateway is not on the same subnet than your Arduino (130.00. 90.250 is not on the same subnet than 130.00. 10.66). The subnet mask (at 255.255.255.0) limit your subnet into those addresses :130.00.10.1 to 130.00.10.254. 130.00.1.0 is your subnet address and 130.00.10.255 is the broadcast address (i.e. you ping at this address and all the computers of your subnet are pinged). That means that your Arduino can't go out of your subnet. The DNS serves to convert internet types addresses onto Ip addresses (for exemple " www.arduino-server.net" onto "130.00.10.66"). I hope that you will understand my explanations ... Merci beaucoup de votre réponse, OUI en faite je suis française je me suis dit que en anglais j'aurais plus de réponse ;-) j'ai finalement réussi à me connecter( ça fait du bien) sur le server arduino depuis n'impporte quel ordinateur(en réseau ou hors). Mais je n'ai absoluement pas utilisée les passerelles ou sous-réseau. (J'ai réussi à afficher un texte quelconque.) Car je ne comprend pas encore la subtilité lorsque j'utilise ou non ces attributs en définnisant mon réseau. Maintenant que je veux integrer des valeurs récupérées par des capteurs j'ai plus rien qui fonctionne.... à partir du moment où je remplie ma boucle loop, le serial moniteur n'affiche plus rien, bien que certain texte se trouve dans la boucle setup. Je crois que la structure m'échape, je croyais qu'il y avais un ordre d'éxecution, le setup en premier s'exécutant qu'une seul fois et le loop après bouclé sur lui-même. Pour l'instant je crois que je suis dans le faux.... Je vous montre mon code peut etre que mes erreurs vont vous paraître évidente.... Encore merci pour l'explication sur les sous-réseau et serveur DNS. Didine
|
|
|
|
« Last Edit: July 16, 2012, 12:36:01 pm by didine97369 »
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #8 on: July 16, 2012, 11:07:29 am » |
//call the library #include <WeatherShield1.h> #include <Ethernet.h> #include <SPI.h> //Declaration Ethernet byte mac[] = { 0x00,0x00,0x00,0x00,0x00,0x00,}; IPAddress ip(130,80,10,00); EthernetServer server(80); //server HTTP EthernetClient client; //declaration WeatherShield const int RXBUFFERLENGTH= 4 ;//***********************I've to know if it's better to use #define or const WeatherShield1 weatherShield; float tempAvgArray[255]; int tempInstArray[255]; long a=3; unsigned char ucBuffer[RXBUFFERLENGTH] ; float fTemp= 0.0f; unsigned short shTemp = 0; float fPress=0.0f ; unsigned short shPress; float fHum=0.0f; unsigned short shHum= 0; boolean haveWeatherData= false;
void setup () { Serial.begin(9600); Ethernet.begin(mac,ip); server.begin(); Serial.println("server is at :"); Serial.println(Ethernet.localIP()); delay(1000); } void loop() { for (int i=0; i <= 255; i++){ getData(i); serialPrint(i); // to check if the getData works //private declartion boolean currentLineIsBlank= true; //get yields of sensors printYield(i); // displayed its on a web page if (server.available() ) { if (client.connected()) { //*************may be use a while Serial.println("new client"); if( client.available()) {//****************************************************************************HERE char c= client.read(); if (c=='/n' && currentLineIsBlank){ // check if c contain /n wiche mean a newline character********* look why we need /n client.println("HTTP/1.1 200 OK"); client.println("Content-Type:text/html"); client.println(); client.println("<DOCTYPE HTML>"); client.println("<html>"); if(haveWeatherData) { printYield(i); client.println("</html>"); } else { client.print("Error reading from WeatherShield"); client.println("<br/>"); break; } } if (c=='/n') { currentLineIsBlank=true; } else if (c=='/r') { currentLineIsBlank=false; } } } delay(1000); client.stop(); Serial.println ("Disconnected"); } } } void getData(int counter) { if(weatherShield.sendCommand(CMD_ECHO_PAR,100,ucBuffer)) { //temperature if (weatherShield.sendCommand(CMD_GETTEMP_C_AVG,0,ucBuffer)) { fTemp = weatherShield.decodeFloatValue(ucBuffer); } if (weatherShield.sendCommand(CMD_GETTEMP_C_RAW, PAR_GET_LAST_SAMPLE,ucBuffer)){ shTemp = weatherShield.decodeShortValue(ucBuffer); } tempAvgArray[counter]= fTemp; tempInstArray[counter]=shTemp; //Pressure if(weatherShield.sendCommand(CMD_GETPRESS_AVG,10,ucBuffer)) { fPress= weatherShield.decodeFloatValue(ucBuffer); } if (weatherShield.sendCommand(CMD_GETPRESS_RAW, PAR_GET_LAST_SAMPLE,ucBuffer)) shPress= weatherShield.decodeShortValue(ucBuffer); //humidity if( weatherShield.sendCommand(CMD_GETHUM_AVG,0,ucBuffer)){ fHum=weatherShield.decodeFloatValue(ucBuffer); } if (weatherShield.sendCommand( CMD_GETHUM_RAW, PAR_GET_LAST_SAMPLE,ucBuffer)){ shHum= weatherShield.decodeShortValue(ucBuffer); } haveWeatherData=true; delay(2*1000); } } void printYield(int counter2) { //temperature client.print("Temperature: "); client.print(fTemp); client.print(" Celsius("); client.print(shTemp); client.println(")"); if (counter2 % a ==0 & counter2>=a) { client.print(char(10)); client.print("tempAvgArray:(" ); for (int x=0; x<=counter2; x++) { client.print(tempAvgArray[x]); client.print(";"); } client.println(")<br/>"); } //pressure client.print("Pressure:"); client.print(fPress); client.print("hPa ("); client.print(shPress); client.println(")<br/>"); //humidity client.print("Humidity:"); client.print(fHum); client.print("% ("); client.print(shHum); client.println(")<br/>"); delay(1000); } void serialPrint(int i) { Serial.print(char(10)); Serial.print("Temperature: "); Serial.print(fTemp); Serial.print(" Celsius("); Serial.print(shTemp); Serial.print(")"); if (i % a ==0 & i>=a) { Serial.print(char(10)); Serial.print("tempAvgArray:(" ); for (int x=0; x<=i; x++) { Serial.print(tempAvgArray[x]); Serial.print(";"); } Serial.print(")"); Serial.print(char(10)); Serial.print("tempInstArray:(" ); for (int x=0; x<=i; x++) { Serial.print(tempInstArray[x]); Serial.print(";"); } } Serial.print(")"); Serial.print(char(10));
Serial.print("Press:"); Serial.print(fPress); Serial.print("hPa ("); Serial.print(shPress); Serial.print(")"); Serial.print(char(10)); Serial.print("Humidity:"); Serial.print(fHum); Serial.print("% ("); Serial.print(shHum); Serial.print(")"); Serial.print(char(10)); delay(1000); }
|
|
|
|
« Last Edit: July 16, 2012, 12:34:17 pm by didine97369 »
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 40
|
 |
« Reply #9 on: July 16, 2012, 12:56:59 pm » |
Bonjour, Je suis aussi français et je n'ai pas pratiqué l'anglais écrit depuis des lustres ! Je reprends mes explications en français : Le masque de sous-réseau sert à limiter le nombre d'adresses IP que comprend le sous-réseau dans lequel on se trouve. Ce masque est calculé en binaire (1111.1111= 255; 1111.1110= 254; 1111.1100= 252; 1111.1000= 248; 1111.0000= 240; 1110.0000= 224; 1100.0000= 192; 1000.0000= 128; 0000.0000= 0). Les seules valeurs pouvant figurer dans un masque de sous-réseau sont celles notées ci-dessus. Pour la valeur 0 dans le masque de sous-réseau, on a 256 possibilités d'adresses (de 0 à 255), et plus la valeur dans le masque de sous-réseau est grande, moins on a de possibilités (pour 255, on a 1 seule possibilité). L'adresse de passerelle est l'adresse vers laquelle un ordinateur ou un périphérique doit pointer pour sortir du sous-réseau, pour atteindre un serveur ou un périphérique ayant une adresse non incluse dans le sous-réseau (dans un réseau domestique, on pointe vers la box - qui sert de passerelle vers l'internet - pour aller vers un serveur hébergeant un site). Par exemple, avec une adresse de réseau 130.88.107.66, si on veut atteindre une page web hébergée par un serveur qui a l'adresse 89.107.171.183, il faut définir l'adresse de la passerelle. Si on ne veut pas sortir du sous-réseau, pas besoin de spécifier d'adresse de passerelle ... En ce qui concerne le DNS, c'est simple : c'est une table de correspondance adresses IP/noms de domaines (89.107.171.183/www.reverso.net, par exemple). Je ne vais pas décrire le fonctionnement de ce système car il est transparent pour nous. On pointe vers un serveur DNS (serveur de noms de domaines) et il se débrouille pour obtenir la réponse et nous la renvoyer. L'adresse qui t'a été fournie par ton administrateur réseau est celle de votre fournisseur d'accès. C'est elle qui permet de taper par exemple " www.reverso.net" au lieu de 89.107.171.183). Pour ce qui est de l'Arduino, je suis aussi un grand débutant. Par contre, j'ai aussi compris que le Setup s'exécute en premier une seule fois (mais après la définition des types de valeurs, comme en programmation Pascal), et qu'ensuite la boucle Loop s'exécute de manière infinie (sauf erreur d'exécution). Pour ce qui est de l'analyse de votre code, je ne suis pas encore assez calé ! Je découvre le C+ depuis très peu ... L'anglais est une excellente idée (j'ai fait de même ^^) car il y a des gens compétents sur ce forum, mais anglophones ! Bon courage !
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #10 on: July 17, 2012, 04:47:26 am » |
Bonjour Sathard, Merci beaucoup pour votre explication sur les sous réseaux et passerelle. Je pense avoir, cette fois si, réellement saisi le gros du fonctionnement de celles-ci. J'ai sais maintenant pourquoi, dans mon précédent code je n'en ai pas eu besoin. Car ma carte Arduino ne solicitait aucun autres sites hors du sous réseau, elle ne postait que un texte sur un server au sein de même sous réseau qu'elle. Vous m'avez été d'une grande aide pour mon prochain code, THANKS A LOT !Votre confirmation sur le fonctionnement des principales boucles de l'Arduino également. Je vous souhaite bon courage pour votre apprentissage du language C+. 
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Newbie
Karma: 0
Posts: 40
|
 |
« Reply #11 on: July 17, 2012, 07:25:12 am » |
Merci beaucoup de vos commentaires.  Bon courage aussi pour votre prochain code !
|
|
|
|
|
Logged
|
|
|
|
|
|