SNMP initialization problem - A SOLUTION!.. or is it?...

Hi all!,

So i have a problem with SNMP. i've got an arduino uno board with SHT sensor. I'm using icinga web app to monitor temperature and humidity and sysuptime. I have everything set up and working properly.
My arduino, before answering any SNMP requests, work properly. However, after having answered all three, it stalls and stops. More likely, it hangs.
So upon researching on google, i found out that i'm not the only one facing the same kind of problem.

check these out:

  1. https://code.google.com/p/agentuino/issues/detail?id=5
  2. Arduino Forum

Now i am facing the same problem as the forum in link number 2 - "After a few hours the device hangs up and the SNMP stops responding. I can still ping the device but no SNMP until I do a reset."
So apparently it seems like the problem is that when a non-SNMP packet is caught, it gets stuck in the buffer and gets processed repeatedly<-

The only way out i have seen is according to "yesyes", the person built a watchdog timer based on NE555. However, I do not have any other resources or hardware other than my arduino board and the SHT sensor.

So I did a little bit of playing around. This is the void pduReceived(); code

if ( pdu.type == SNMP_PDU_GET || pdu.type == SNMP_PDU_GET_NEXT || pdu.type == SNMP_PDU_SET
        && pdu.error == SNMP_ERR_NO_ERROR && api_status == SNMP_API_STAT_SUCCESS )
      {
        pdu.OID.toString(oid);
           Serial << "OID: " << oid << endl;
       
              if(strcmp_P(oid,sysDescr)==0)
                  {
                      Serial.print("Requesting sysDescription");
                      if( pdu.type==SNMP_PDU_SET ) 
                          {
                            pdu.type = SNMP_PDU_RESPONSE;
                            pdu.error = SNMP_ERR_READ_ONLY;
                          } 
                          else
                            {
                              status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locDescr);
                              pdu.type = SNMP_PDU_RESPONSE;
                              pdu.error = status;
                            }
                            #ifdef DEBUG
                            Serial << "sysDescr..." << locDescr << " " << pdu.VALUE.size << endl;
                            #endif
                   } some more OID blocks

Then an else statement that says if NOT a valid packet then send general error

 else 
      {
      //packet is not valid, send General_Error resposnse. Required, otherwise the invalid packet 
     // will get stuck in the buffer and processed over and over again
    
      
        Serial << "Unknown Packet!!" << endl;
        Serial << "PDU Type: " << pdu.type << " PDU Error: " << pdu.error << " API status: "<< api_status << endl; 
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = SNMP_ERR_GEN_ERROR;
        Agentuino.responsePdu(&pdu);
        Serial << "Sent 'GENERAL_ERROR' response" << endl;
    } 
    
    
 Serial << "freeing PDU.." << " RAM:" << freeMemory() << endl;
 Agentuino.freePdu(&pdu);
  //
 Serial << "UDP Packet Received End.." << " RAM:" << freeMemory() << endl;
    
}//end pudRecieved();

I got curious and thought every time Agentuino frees the pdu, arduino eventually stops. So I commented out the Aguentino.freePdu(&pdu) in the code.

and ALAS! it works! it reads the temperature, humidity, sysuptime and does not hang or stop at all. however, with Agentuino.freePDU(&pdu) commented out, I am only left with a constant 684bytes of RAM.

Now I am really just a noobie with arduino, and I am a java programmer and I am still learning C.

My thought on this is that when an invalid SNMP is caught, it gets stuck and gets buffered over and over then calling the Agentuino.freePDU releases everything. It releases even the embedded method??..

So at the moment commenting out the Agentuino.freePDU has delivered success to me. I know that I am left with 684bytes, however, I am a bit hesitant to this approach. Im sure this is not just an easy fix. I have a few questions. will arduino run out of memory I can always add memory through microSD card. hmmm.. so yea.? what could be the effects of not freeing the pdu?. is this even the right apporach?.. so at this very moment the code works but I will have to see what happens in the following days

To the experts at this topic, please give me your feedback and your comments. Thank you! as I said I am really new to arduino. First time programming directly to a device.. men this is so primitive! ^^,

Please, to anyone, enlighten me. Thank you