Ethernet Webserver together with UDP

Hello,

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).

client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<div align=center>");
          client.print("<body style=background-color:lightblue>");
          client.println("<font color=red><h1>HTML Testsite</font></h1>");
          client.println("<hr/>");
          client.println("<h1><font color='#2076CD'>Room</font color></h1>");
          client.println("<hr />
");
          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>");
//          }
//
          client.println("</form></body></html>");
          break;

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

The UDP code is:

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

And it is called in the main loop as

void loop()  {  
  webserv();   
//  delay(1000);
  udptest();
//    delay(1000);
}

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

I am out of ideas, can anyone help me ?

greets

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.

tdrat:
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: PROGMEM - Arduino Reference

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 ?

Thanks

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 :slight_smile:

Thanks again,
greets