Pages: [1]   Go Down
Author Topic: aiuto per webserver  (Read 659 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

buongiorno a tutti,
vi scrivo perchè non riesco a vedere più il mio arduino in rete...
il problema è nato con il passaggio alla versione IDE arduino 1.0...
dichiaravo i parametri x la rete

byte mac[] = { 0x--, 0x--, 0x--, 0x--, 0x--, 0x-- };
byte ip[] = { 192, 168, 1, 128 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = {255, 255, 255, 0};

Server server(80);
void setup(){
   Ethernet.begin(mac, ip, subnet, gateway);
        ....

void loop(){
Client client = server.available();
   if (client) {
     boolean currentLineIsBlank = true;
     while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         readString.concat(c);
        if (c == '\n' && currentLineIsBlank){
valore = analogRead(A0);
                        Serial.println(valore);
                      // INIZIO DICHIARAZIONE PAGINA HTML
                        client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();
                        client.println("<html><head><meta http-equiv='refresh' content='1' />");
                        client.println("</head><body>");

e poi facevo fare delle operazioni...
ora con la versione 1.0 ho fatto l'upload dello sketch webserver base e nulla....
qualcuno sa cosa fare?
grazie mille

« Last Edit: January 18, 2012, 05:56:21 am by michelegnocchi » Logged

Cagliari, Italy
Offline Offline
Tesla Member
***
Karma: 104
Posts: 6617
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Il mac-address l'hai indicato così per non pubblicarlo o hai compilato lo sketch im quel modo?

Code:
byte mac[] = { 0x--, 0x--, 0x--, 0x--, 0x--, 0x-- };
Logged

Code fast. Code easy. Codebender --> http://codebender.cc/?referrer=PaoloP

Genova
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2757
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A parte quello, non vedo le librerie, non capisco perché si debba passare a 1.0 quando ci sono le nuove release
Logged

Meglio imparare dalle cose inutili piuttosto che non imparare niente.   [Arduino Mega R3 + Ethernet shield W5100 + SD card 8Gb FAT32]

Cagliari, Italy
Offline Offline
Tesla Member
***
Karma: 104
Posts: 6617
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Prova a compilare ed eseguire questo codice inserendo il giusto mac address al posto di FF FF FF FF FF FF.
Se hai un router con server DHCP abilitato sulla seriale dovresti leggere i vari parametri.

Code:
#include <SPI.h>        
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

void setup()
{
  Serial.begin(9600);
  Serial.println("Start!");
  // start Ethernet
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  else
  {
    Serial.println("Ethernet configured using DHCP");
    Serial.print("Local IP: ");
    Serial.println(Ethernet.localIP());
    Serial.print("SubnetMask: ");
    Serial.println(Ethernet.subnetMask());
    Serial.print("Gateway: ");
    Serial.println(Ethernet.gatewayIP());
    Serial.print("DNS Server: ");
    Serial.println(Ethernet.dnsServerIP());
  }
}

void loop()
{
}

Comunque il codice del WebServer versione 1.0 è:
Code:
#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:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("<br />");
          }
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}
« Last Edit: January 18, 2012, 08:36:33 am by PaoloP » Logged

Code fast. Code easy. Codebender --> http://codebender.cc/?referrer=PaoloP

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

grazie mille per avermi risposto!
il mac nn l'ho messo x non comunicarlo in rete  smiley-lol ..
ho scritto lo sketch e cosa mooooooooooolto strana non entra nè nell'if nè nell'else!!! smiley-eek smiley-eek smiley-eek
esce scritto solo

Start!
Logged

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

non mi esegue l' Ethernet.begin  smiley-money
Logged

Cagliari, Italy
Offline Offline
Tesla Member
***
Karma: 104
Posts: 6617
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sostituisci il mac del listato (FF FF FF FF FF FF) con il tuo.
Logged

Code fast. Code easy. Codebender --> http://codebender.cc/?referrer=PaoloP

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

ovviamente avevo messo il mio smiley-grin
Logged

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

questo è il codice :
metto un fake mac ma nel compilare qll reale
#include <SPI.h>         
#include <Ethernet.h>

byte mac[] = { 0x--, 0x--, 0x--, 0x--, 0x--, 0x-- };
IPAddress ip(192,168,1, 45);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192,168,1, 1);
int a=1;
void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac,ip,dns,gateway,subnet);
  Serial.println("Start!");
}

void loop()
{
  Serial.print("Local IP al ciclo numero ");
  Serial.print(a);
  Serial.print(" : ");
  Serial.println(Ethernet.localIP());
  Serial.print("SubnetMask: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server: ");
  Serial.println(Ethernet.dnsServerIP());
  delay(1000);
  a=a+1;
}


l'output è :

Local IP al ciclo numero 1 : 0.0.0.0
SubnetMask: 0.0.0.0
DNS Server: 192.168.1.1
e va avanti all'infinito...
ricordo che mi da qst problema solo con la versione 1.0 mentre se usavo le vecchie dichiarazioni di ip etc con la 022 andava tutto
Logged

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

il tasto reset fa miracoli... grazie a tutti
Logged

Cagliari, Italy
Offline Offline
Tesla Member
***
Karma: 104
Posts: 6617
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

il tasto reset fa miracoli... grazie a tutti
smiley-eek-blue smiley-lol smiley-lol
Logged

Code fast. Code easy. Codebender --> http://codebender.cc/?referrer=PaoloP

Pages: [1]   Go Up
Jump to: