Skip to content

Commit c092b00

Browse files
committed
fix bug
1 parent 7b8dbf4 commit c092b00

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

Examples/iSYNC_CoAP_GET/iSYNC_CoAP_GET.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AltSoftSerial bc95serial;
88
BC95UDP udp;
99
Coap coap(udp);
1010

11-
#define iSYNC_KEY "5c5d82fa3860984ee2a93ba3"
11+
#define iSYNC_KEY "5c888df67f56637c67cac702"
1212

1313
void responseHandler(CoapPacket *packet, IPAddress remoteIP, int remotePort) {
1414
char buff[6];
@@ -35,6 +35,8 @@ void setup() {
3535
delay(1000);
3636
}
3737
Serial.println(F("NB-IOT attached.."));
38+
Serial.print("IP: ");
39+
Serial.println(BC95.getIPAddress());
3840

3941
coap.response(responseHandler);
4042
coap.start();

Examples/iSYNC_CoAP_POST/iSYNC_CoAP_POST.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AltSoftSerial bc95serial;
88
BC95UDP udp;
99
Coap coap(udp);
1010

11-
#define iSYNC_KEY "5c5d82fa3860984ee2a93ba3"
11+
#define iSYNC_KEY "5c888df67f56637c67cac702"
1212

1313
void responseHandler(CoapPacket *packet, IPAddress remoteIP, int remotePort) {
1414
char buff[6];
@@ -35,6 +35,8 @@ void setup() {
3535
delay(1000);
3636
}
3737
Serial.println(F("NB-IOT attached.."));
38+
Serial.print("IP: ");
39+
Serial.println(BC95.getIPAddress());
3840

3941
coap.response(responseHandler);
4042
coap.start();
@@ -56,4 +58,4 @@ void loop() {
5658
coap.iSYNC_POST(iSYNC_KEY,payload);
5759
Serial.println("#----------------------------");
5860
}
59-
}
61+
}

library.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=This library transforms AT-commands on BC95 NB-IOT module into a famil
77
category=Communication
88
url=https://github.com/jackrobotics/iSYNC_BC95_Arduino
99
architectures=avr
10+
includes=BC95.h,BC95Udp.h,CoAP.h,Dns.h,NTPClient.h

src/CoAP.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
Coap::Coap(UDP& udp) {
88
this->_udp = &udp;
99
this->resp = NULL;
10+
this->ready = false;
1011
}
1112

1213
bool Coap::start() {
1314
this->start(COAP_DEFAULT_PORT);
15+
this->ready=true;
1416
return true;
1517
}
1618

1719
bool Coap::start(int port) {
1820
this->_udp->begin(port);
21+
this->ready=true;
1922
return true;
2023
}
2124

@@ -294,6 +297,7 @@ bool Coap::loop() {
294297
#if COAP_ENABLE_ACK_CALLBACK == 1
295298
if (resp != NULL)
296299
resp(packet, _udp->remoteIP(), _udp->remotePort());
300+
ready = true;
297301
#endif
298302
} else {
299303

@@ -374,8 +378,22 @@ uint16_t Coap::sendResponse(IPAddress ip, int port, uint16_t messageid, char *pa
374378
void Coap::iSYNC_POST(String key,String msg){
375379
key = "NBIoT/"+key;
376380
this->post(SERVER_IP, SERVER_PORT, key.c_str(),msg.c_str());
381+
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!!!");
386+
this->ready=true;
387+
}
377388
}
378389
void Coap::iSYNC_GET(String key){
379390
key = "NBIoT/"+key;
380391
this->get(SERVER_IP, SERVER_PORT, key.c_str());
381-
}
392+
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!!!");
397+
this->ready=true;
398+
}
399+
}

src/CoAP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class Coap {
176176
uint16_t sendPacket(CoapPacket &packet, IPAddress ip, int port);
177177
int parseOption(CoapOption *option, uint16_t *running_delta, uint8_t **buf, size_t buflen);
178178

179+
bool ready;
180+
179181
public:
180182
Coap(
181183
UDP& udp

0 commit comments

Comments
 (0)