Pages: 1 [2] 3   Go Down
Author Topic: Server on Arduino Ethernet fails  (Read 5685 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50908
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Teleinfo_Webserver_Arduino_V0_2_c:4: error: variable or field 'ListFiles' declared void
This means that somewhere you are trying to assign the return value from ListFiles to a variable. Since ListFiles is not defined to return a value, that is not allowed.

Quote
Teleinfo_Webserver_Arduino_V0_2_c:4: error: 'EthernetClient' was not declared in this scope
Probably missing an include file, or the code is in the wrong place.

Quote
Teleinfo_Webserver_Arduino_V0_2_c:4: error: expected primary-expression before 'flags'
Need to see the code, but somewhere before where flags appears, there is a syntax error.
Logged

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

Hello Paul,

Thank you for your responses.
I attach the .ino file to this post.
It's not the definitive version : I must simplify the code ...

I think that the definition of the ListFiles function generates those errors.
I tried including the EthernetClient ("#include <EthernetClient.h>"), but It solves nothing : I had the same errors :
Quote
Teleinfo_Webserver_Arduino_V0_2_c:4: error: variable or field 'ListFiles' declared void
Teleinfo_Webserver_Arduino_V0_2_c:4: error: 'EthernetClient' was not declared in this scope
Teleinfo_Webserver_Arduino_V0_2_c:4: error: expected primary-expression before 'flags'

The code generating the errors was just copied and paste from the "SDWebBrowse.ino" code, witch is working properly ...

* Teleinfo_Webserver_Arduino_V0_2_c.ino (32.95 KB - downloaded 7 times.)
* SDWebBrowse.ino (7.31 KB - downloaded 6 times.)
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50908
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The code generating the errors was just copied and paste from the "SDWebBrowse.ino" code, witch is working properly ...
Not a straight copy and paste...

The Arduino IDE adds code to the sketch, for things like function prototypes and necessary include files. It makes the additions after the first line of code in your file. Your first non-comment line is:
Code:
char version_logiciel[6] = "V0.2c";

The IDE added function prototypes after this statement, like:
Code:
void ListFiles(EthernetClient client, uint8_t flags);

Since this is added BEFORE the EthernetClient include statement, the EthernetClient class is "not declared in this scope". This error caused the line to be ignored. Then, the ListFiles function was actually encountered. Since there was no function prototype, the compiler expected that the function would return an int. It's signature does not match the compiler's expectations, hence the first message.

I'm not sure what the third one is about.

Moving the version_logiciel declaration and initialization AFTER the include files got rid of these three error messages, but introduced a whole slew of new errors. Some of them are because I do not have all the libraries that you do. If you encounter more problems, post the errors (and the modified code).
Logged

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

If I understand your reply, the organization for a sketch is :

1/ #include
2/ #define
3/ Variables declarations (int, byte, char, unsigned, ...)
4/ Functions
5/ Setup
6/ Loop

Is that good ?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50908
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is that good ?
That's almost the way I organize my programs. It plays well with the IDE. Functions can be in any order. The IDE will generate function prototypes for all functions that it can. You may need to manually add some, if you use reference values or templates.

But, the includes should come first.
Logged

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

Thank you for the clarification.

I reorder line codes and make a new try with the sketch.
Logged

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

Hello everybody !

I reordered my sketchcode and saw ... that it makes 33098 bytes ! smiley-eek-blue

So I modified it to obtain a 32000 bytes sketch.

I think I can decrease the size of the sketch by using the Ethernet2.h library (normally 2,5Ko less and the sketch will be under 30720 bytes).
The problem is that it generates more compilation errors  ...

(I join a file name "Erreurs.txt" where you can see the errors returned by the IDE)

Any idea ?

* Erreurs.txt (16.08 KB - downloaded 9 times.)
* Teleinfo_Webserver_Arduino_V0_2_c.ino (32.99 KB - downloaded 9 times.)
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the first error. I presume the errors cascade from here.
Quote
In file included from Teleinfo_Webserver_Arduino_V0_2_c.cpp:14:
C:\Program Files (x86)\arduino-1.0.1\libraries\Ethernet2/Ethernet2.h:69: error: stray '#' in program
Logged

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

Thanks for your response ! ^^

But what does it means ?
I don't understand why this error appears
I haven't modify the code of this library ...
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50908
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't understand why this error appears
I haven't modify the code of this library ...
Well, we can't see how you got the library, from where, what OS you are using, etc. So, I guess we are even.
Logged

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

Ok.
I'm using Windows7 on a core4 processor and the IDE is 1.0.1 version.
I take the library at this address : http://code.google.com/p/tinkerit/source/browse/#svn%2Ftrunk%2FEthernet2%20library%253Fstate%253Dclosed. It's the r17 revision from 2008.
I make a try tomorrow (actually, it's 3:00 AM !).

Good night !
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It's the r17 revision from 2008.

Try something newer. This works for me. It has a form page. Change the network settings if necessary. Compile, upload, and open the serial monitor.
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 192,168,0,2 );
IPAddress gateway( 192,168,0,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(80);

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop()
{
  EthernetClient client = server.available();
  if(client) {
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;
    
    Serial.print("Client request: ");
    
    while (client.connected()) {
      while(client.available()) {
        char c = client.read();

        if(currentLineIsGet && tCount < 63)
        {
          tBuf[tCount] = c;
          tCount++;
          tBuf[tCount] = 0;          
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response
          while(client.available()) client.read();
          Serial.println(tBuf);
          pch = strtok(tBuf,"?");

          while(pch != NULL)
          {
            if(strncmp(pch,"t=",2) == 0)
            {
              t = atoi(pch+2);
              Serial.print("t=");
              Serial.println(t,DEC);            
            }

            if(strncmp(pch,"r=",2) == 0)
            {
              r = atoi(pch+2);
              Serial.print("r=");              
              Serial.println(r,DEC);
            }


            pch = strtok(NULL,"& ");
          }
          Serial.println("Sending response");
          client.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html><body><H1>TEST</H1>");

          client.write("<form method=GET>T: <input type=text name=t><br>");
          client.write("R: <input type=text name=r><br><input type=submit></form>");
          
          client.write("</body></html>\r\n\r\n");
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    Serial.println("done");
  }
}

You may need to remove the serial output if you don't have that feature.

edit: I don't see how you would troubleshoot this without a usb/serial port. If you don't have that adapter, I recommend you get one.
http://arduino.cc/en/Main/USBSerial
« Last Edit: July 21, 2012, 06:35:44 am by SurferTim » Logged

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

Hello,
I have the Serial-USB adapter (this is the only way to load the program in an Ethernet Arduino).

The program you made is it a file server in html ?
I adapt the ethernet settings with my MAC@, IP@, gateway@ and subnet mask.

The program you made compiles good.

When I send it to the Arduino, I have this error :
Quote
Taille binaire du croquis : 11 656 octets (d'un max de 32 256 octets)
avrdude: stk500_getsync(): not in sync: resp=0x00


What is the problem ? Is it a transfert problem ?

When in use, I would need no more messages on the serial port taken out of the data only towards the SD card and the ethernet port.
Could I comment lines " Serial. " ?
« Last Edit: July 21, 2012, 01:18:22 pm by Sathard » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you successfully uploaded other programs to that device before? In Windows, there is normally a driver install involved before it will recognize the Arduino usb.

edit: I use a #define for the serial debugging stuff, but you can comment them out.
Code:
// in the global area
#define serialDEBUG
// then later in the code
#ifdef serialDEBUG
  Serial.println("Test");
#endif
« Last Edit: July 21, 2012, 01:24:14 pm by SurferTim » Logged

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

I integrate the conditional debug orders.
Is that code good ?

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


#define serialDEBUG

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x62, 0x40 };
IPAddress ip( 192,168,1,2 );
IPAddress gateway( 192,168,1,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(80);

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop()
{
  EthernetClient client = server.available();
  if(client) {
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;
   
    #ifdef serialDEBUG
    Serial.print("Client request: ");
    #endif
   
   
    while (client.connected()) {
      while(client.available()) {
        char c = client.read();

        if(currentLineIsGet && tCount < 63)
        {
          tBuf[tCount] = c;
          tCount++;
          tBuf[tCount] = 0;         
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response
          while(client.available()) client.read();
          Serial.println(tBuf);
          pch = strtok(tBuf,"?");

          while(pch != NULL)
          {
            if(strncmp(pch,"t=",2) == 0)
            {
              t = atoi(pch+2);
              Serial.print("t=");
              Serial.println(t,DEC);             
            }

            if(strncmp(pch,"r=",2) == 0)
            {
              r = atoi(pch+2);
              Serial.print("r=");             
              Serial.println(r,DEC);
            }


            pch = strtok(NULL,"& ");
          }
          #ifdef serialDEBUG
          Serial.println("Sending response");
          #endif
         
          client.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html><body><H1>TEST</H1>");

          client.write("<form method=GET>T: <input type=text name=t><br>");
          client.write("R: <input type=text name=r><br><input type=submit></form>");
         
          client.write("</body></html>\r\n\r\n");
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    #ifdef serialDEBUG
    Serial.println("done");
    #endif
  }
}



If I understand good, I don't have to make any change on the lines like "Serial.println(tBuf);", otherwise the code don't work ... ?
Logged

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