Go Down

Topic: Ethernet Webserver together with UDP (Read 804 times) previous topic - next topic


Sep 12, 2011, 11:06 am Last Edit: Sep 12, 2011, 11:10 am by tdrat Reason: 1

I got a Problem when using the Webserver example together with an UDP Listener.
If i start the Webserver alone everything is fine.
Same happens when the UDP Listener is called alone.
But together i am only able to get the Webserver working when stripping it down. That means i can only have one IF case for the input buttons (as seen in the webserver example).

Code: [Select]

client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("<div align=center>");
          client.print("<body style=background-color:lightblue>");
          client.println("<font color=red><h1>HTML Testsite</font></h1>");
          client.println("<h1><font color='#2076CD'>Room</font color></h1>");
          client.println("<hr /><br>");
          client.println("<form method=GET>");
  if (lon == true) {
            client.println("<input type=submit value=light  name=1 style=width:200;height:100;background-color:red;/>");
          }else {
            client.println("<input type=submit  value=light name=0 style=width:200;height:100;background-color:lightgreen;>");
// --->>  If this is left out everything works, even with UDP called !
//          if (mon == true) {
//            client.println("<input type=submit name=1 value=motor style=width:200;height:100;background-color:red>");
//          }else{
//            client.println("<input type=submit name=0 value=motor style=width:200;height:100;background-color:lightgreen>");
//          }

If i do a second IF case for a second input type button, the arduino resets every second.

The UDP code is:

Code: [Select]

void udptest(){
  int packetSize = Udp.available();
    packetSize = packetSize - 8;      // subtract the 8 byte header
    Udp.readPacket(packetBuffer,1024, remoteIp, remotePort);
    for (int i=0;i<7;i++){         

And it is called in the main loop as

Code: [Select]

void loop()  { 
//  delay(1000);
//    delay(1000);

I have the DFRduino Ethernet shield attached to a Nano 3.0.

I am out of ideas, can anyone help me ?



You have an awful lot of strings, in just that little snippet. I'm guessing that you are running out of memory. The Nano 3.0 has only 2K of SRAM.
The art of getting good answers lies in asking good questions.


But together i am only able to get the Webserver working when stripping it down. That means i can only have one IF case for the input buttons (as seen in the webserver example).

Sounds like you're running out of RAM.

I think you need to read this page: http://www.arduino.cc/en/Reference/PROGMEM

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)


Thanks for your answers, that helped me a little bit !

As the normal webserver example works very well, and there are a lot more Strings in it, I tested this with the freeMemory function.
When calling the webserver alone (with a few more lines of Strings added), I have 1028 bytes free.

And when calling the UDP function alone i only get 93 bytes of free Memory.

edit: Tested this with buffer sizes from 1 to 1024, always the same result.

So, can anyone point out why the UDP function is taking up the whole Memory ?



As you found out correctly, i was eating up all sram.
Stupid me..  I did the UDP.read with a small buffer but reserved for the packetbuffer char a lot of space :)

Thanks again,

Go Up