Skip to content

Commit 3b9a927

Browse files
committed
reconnect
1 parent 64e566d commit 3b9a927

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/CoAP.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,36 @@ uint16_t Coap::sendResponse(IPAddress ip, int port, uint16_t messageid, char *pa
376376
}
377377

378378
void Coap::iSYNC_POST(String key,String msg){
379+
unsigned long lasttime = millis();
379380
key = "NBIoT/"+key;
380381
this->post(SERVER_IP, SERVER_PORT, key.c_str(),msg.c_str());
381382
this->ready=false;
382-
unsigned long lasttime = millis();
383-
while((millis() - lasttime > 10000) && !this->ready){this->loop();};
384-
if(millis()-lasttime>10000){
385-
Serial.println("Timeout!!!");
383+
while((millis() - lasttime < 10000) && !this->ready){this->loop();};
384+
if(!this->ready){
385+
Serial.print(F("Reconnect..."));
386+
while (!BC95.attachNetwork()) {
387+
Serial.print(".");
388+
delay(500);
389+
}
390+
Serial.println();
391+
this->start();
386392
this->ready=true;
387393
}
388394
}
389395
void Coap::iSYNC_GET(String key){
396+
unsigned long lasttime = millis();
390397
key = "NBIoT/"+key;
391398
this->get(SERVER_IP, SERVER_PORT, key.c_str());
392399
this->ready=false;
393-
unsigned long lasttime = millis();
394-
while((millis() - lasttime > 10000) && !this->ready){this->loop();};
395-
if(millis()-lasttime>10000){
396-
Serial.println("Timeout!!!");
400+
while((millis() - lasttime < 10000) && !this->ready){this->loop();};
401+
if(!this->ready){
402+
Serial.print(F("Reconnect..."));
403+
while (!BC95.attachNetwork()) {
404+
Serial.print(".");
405+
delay(500);
406+
}
407+
Serial.println();
408+
this->start();
397409
this->ready=true;
398410
}
399411
}

0 commit comments

Comments
 (0)