* ping added to see if it keeps the connection alive

This commit is contained in:
Dávid Danyi 2018-03-01 14:41:00 +01:00
parent c8428f4e4d
commit e77d494e4d

View File

@ -12,16 +12,20 @@
#define DEBUG_STREAM_BAUD 9600 #define DEBUG_STREAM_BAUD 9600
Sodaq_nbIOT nbIOT; Sodaq_nbIOT nbIOT;
int socket;
int pingSocket;
int pending;
char * buffer;
// constructor only sets uri, init() called later so we can debug print // constructor only sets uri, init() called later so we can debug print
/** /**
* 40.115.26.19 - ethinnoday-lwm2m-server.westeurope.cloudapp.azure.com * 40.115.26.19 - ethinnoday-lwm2m-server.westeurope.cloudapp.azure.com
* 5.39.83.206 - leshan.eclipse.org * 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() { void setup() {
buffer = static_cast<char*>(malloc(250));
DEBUG_STREAM.begin(DEBUG_STREAM_BAUD); DEBUG_STREAM.begin(DEBUG_STREAM_BAUD);
while(!DEBUG_STREAM) { while(!DEBUG_STREAM) {
; ;
@ -38,6 +42,9 @@ void setup() {
// initialize the client // initialize the client
nbIOT.connectSocket(); nbIOT.connectSocket();
pingSocket = nbIOT.createSocket(1313);
wakaamaClient.init(&nbIOT); wakaamaClient.init(&nbIOT);
} }
@ -49,15 +56,23 @@ void loop() {
if(!nbIOT.isRegistered()) { if(!nbIOT.isRegistered()) {
DEBUG_STREAM.println(F("Modem is deregistered, trying to reconnect.")); DEBUG_STREAM.println(F("Modem is deregistered, trying to reconnect."));
if(!nbIOT.reconnectSocket()) { if(!nbIOT.reconnectSocket()) {
delay(1000); // delay(1000);
return; 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 // our worker loop
wakaamaClient.doWorkStep(); wakaamaClient.doWorkStep();
// sleep a bit? // sleep a bit?
delay(1000); // delay(1000);
} }