Problema funzione SNMP - SD

Ciao,
sto scrivendo un programma con il quale è possibile visualizzare la temperatura di un locale e monitorare le presenze tramite sensore di movimento. Tali dati li sto scrivendo all’interno dell’SD presente sullo shield ethernet. Inoltre, attraverso un server sto cercando di effettuare il prelevamento dei dati relativi alla temperatura attraverso la funzione SNMP. Il problemi che riscontro sono i seguenti:

  • dopo aver effettuato una get snmp il programma si blocca non riuscendo più ad effettuare una sucessiva lettura
  • non riesco più a vedere i rilevamenti di presenza e temperatura via seriale.

Qui il mio codice:

void pduReceived()
{
SNMP_PDU pdu;
//
#ifdef DEBUG
Serial << F(“UDP Packet Received Start…”) << F(" RAM:") << freeMemory() << endl;
#endif
//
api_status = Agentuino.requestPdu(&pdu);
//
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 ) {
// handle sysDescr (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read-only
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_READ_ONLY;
} else {
// response packet from get-request - locDescr
status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locDescr);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
#ifdef DEBUG
Serial << F(“sysDescr…”) << locDescr << F(” “) << pdu.VALUE.size << endl;
#endif
} else if ( strcmp_P(oid, sysUpTime ) == 0 ) {
// handle sysName (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read-only
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_READ_ONLY;
} else {
// response packet from get-request - locUpTime
status = pdu.VALUE.encode(SNMP_SYNTAX_TIME_TICKS, locUpTime);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
#ifdef DEBUG
Serial << F(“sysUpTime…”) << locUpTime << F(” “) << pdu.VALUE.size << endl;
#endif
} else if ( strcmp_P(oid, sysName ) == 0 ) {
// handle sysName (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read/write
status = pdu.VALUE.decode(locName, strlen(locName));
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
} else {
// response packet from get-request - locName
status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locName);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
#ifdef DEBUG
Serial << F(“sysName…”) << locName << F(” “) << pdu.VALUE.size << endl;
#endif
} else if ( strcmp_P(oid, sysContact ) == 0 ) {
// handle sysContact (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read/write
status = pdu.VALUE.decode(locContact, strlen(locContact));
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
} else {
// response packet from get-request - locContact
status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locContact);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
#ifdef DEBUG
Serial << F(“sysContact…”) << locContact << F(” “) << pdu.VALUE.size << endl;
#endif
} else if ( strcmp_P(oid, sysLocation ) == 0 ) {
// handle sysLocation (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read/write
status = pdu.VALUE.decode(locLocation, strlen(locLocation));
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
} else {
// response packet from get-request - locLocation
status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locLocation);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
#ifdef DEBUG
Serial << F(“sysLocation…”) << locLocation << F(” “) << pdu.VALUE.size << endl;
#endif
} else if ( strcmp_P(oid, sysServices) == 0 ) {
// handle sysServices (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read-only
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_READ_ONLY;
} else {
// response packet from get-request - locServices
status = pdu.VALUE.encode(SNMP_SYNTAX_INT, locServices);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//Temperaturaaaaa
} else if ( strcmp_P(oid, sysTemp) == 0 ) {
// handle sysServices (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read-only
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_READ_ONLY;
} else {
// response packet from get-request - locServices
status = pdu.VALUE.encode(SNMP_SYNTAX_INT, Temperatura);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
//Set SNMP
} else if ( strcmp_P(oid, sysSet) == 0 ) {
// handle sysServices (set/get) requests
if ( pdu.type == SNMP_PDU_SET ) {
// response packet from set-request - object is read/write
status = pdu.VALUE.decode(led, strlen(led));
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
} else {
// response packet from get-request - locServices
status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, led);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
//
#ifdef DEBUG
Serial << F(“locServices…”) << locServices << F(” “) << pdu.VALUE.size << endl;
#endif
} else {
// oid does not exist
//
// response packet - object not found
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_NO_SUCH_NAME;
}
//
Agentuino.responsePdu(&pdu);
}
//
Agentuino.freePdu(&pdu);
//
Serial << “UDP Packet Received End…” << " RAM:” << freeMemory() << endl;
}

void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);

//GESTIONE TIMER LOG
Udp.begin(localPort);

setSyncProvider(getNtpTime);

while(timeStatus()== timeNotSet) {Serial.println(“4”);}

//GESTIONE SD
Serial.print(“Initializing SD card…”);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
return;
}
Serial.println(“card initialized.”);
pinMode(PinMov,INPUT);

//GESTIONE SNMP
api_status = Agentuino.begin();
Agentuino.onPduReceive(pduReceived);

return;
}

void loop()
{
int Presenza;
char data_presenza;
String h,m,s;
// listen/handle for incoming SNMP requests
Agentuino.listen();

Temperatura = int(Thermister(analogRead(Pinmode)));
File dataFile = SD.open(“Temp.log”, FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print("Temperatura: ");
dataFile.println(Temperatura);
dataFile.close();

}
// if the file isn’t open, pop up an error:
else {
Serial.println(“Errore apertura file!!”);
}

if (digitalRead(8)== 1)
{
Presenza=1;
Time = now();
// digitalClockDisplay();
File data = SD.open(“Presenze.log”, FILE_WRITE);
// if the file is available, write to it:
if (data)
{
h=String (hour());
m=String (minute());
s=String(second());

String date = h+":"+m+":"+s;
data.print(date);
data.println(“C’è stata una presenza!”);
data.close();
}
// if the file isn’t open, pop up an error:
else
{
Serial.println(“No presenza”);
}
}
else
{
Presenza=0;
}

delay(500);
}

se il problema è della libreria l'unica è da rimpinzarla di Serial.println("Qualcosa") fino a quando non capisci esattamente dove si blocca, poi ppossiamo capire perchè