* ping added to see if it keeps the connection alive
This commit is contained in:
parent
c8428f4e4d
commit
e77d494e4d
@ -12,16 +12,20 @@
|
||||
#define DEBUG_STREAM_BAUD 9600
|
||||
|
||||
Sodaq_nbIOT nbIOT;
|
||||
int socket;
|
||||
|
||||
int pingSocket;
|
||||
int pending;
|
||||
char * buffer;
|
||||
|
||||
// constructor only sets uri, init() called later so we can debug print
|
||||
/**
|
||||
* 40.115.26.19 - ethinnoday-lwm2m-server.westeurope.cloudapp.azure.com
|
||||
* 5.39.83.206 - leshan.eclipse.org
|
||||
*/
|
||||
ArduinoClient wakaamaClient("coap://40.115.26.19:5683");
|
||||
ArduinoClient wakaamaClient("coap://5.39.83.206:5683");
|
||||
|
||||
void setup() {
|
||||
buffer = static_cast<char*>(malloc(250));
|
||||
DEBUG_STREAM.begin(DEBUG_STREAM_BAUD);
|
||||
while(!DEBUG_STREAM) {
|
||||
;
|
||||
@ -38,6 +42,9 @@ void setup() {
|
||||
|
||||
// initialize the client
|
||||
nbIOT.connectSocket();
|
||||
|
||||
pingSocket = nbIOT.createSocket(1313);
|
||||
|
||||
wakaamaClient.init(&nbIOT);
|
||||
}
|
||||
|
||||
@ -49,15 +56,23 @@ void loop() {
|
||||
if(!nbIOT.isRegistered()) {
|
||||
DEBUG_STREAM.println(F("Modem is deregistered, trying to reconnect."));
|
||||
if(!nbIOT.reconnectSocket()) {
|
||||
delay(1000);
|
||||
// delay(1000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nbIOT.sendSocket(pingSocket, "87.229.111.223", 1111, (uint8_t*)"asdf", 4);
|
||||
pending = nbIOT.socketBytesPending(pingSocket);
|
||||
if(pending > 0) {
|
||||
nbIOT.socketReceive(pingSocket, buffer, pending);
|
||||
DEBUG_STREAM.print(F(__FILE__":loop() ping:"));
|
||||
DEBUG_STREAM.println(buffer);
|
||||
}
|
||||
|
||||
// our worker loop
|
||||
wakaamaClient.doWorkStep();
|
||||
|
||||
// sleep a bit?
|
||||
delay(1000);
|
||||
// delay(1000);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user