2018-02-28 13:13:13 +01:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <wakaama-client.h>
|
|
|
|
|
|
|
|
|
|
#include <Sodaq_wdt.h>
|
|
|
|
|
#include <Sodaq_nbIOT.h>
|
|
|
|
|
|
|
|
|
|
#define MODEM_ON_OFF_PIN 7
|
|
|
|
|
#define MODEM_STREAM Serial1
|
|
|
|
|
|
|
|
|
|
#define DEBUG_STREAM SerialUSB
|
|
|
|
|
//#define DEBUG_STREAM_BAUD 115200
|
|
|
|
|
#define DEBUG_STREAM_BAUD 9600
|
|
|
|
|
|
|
|
|
|
Sodaq_nbIOT nbIOT;
|
|
|
|
|
int socket;
|
|
|
|
|
|
|
|
|
|
// constructor only sets uri, init() called later so we can debug print
|
2018-02-28 13:36:54 +01:00
|
|
|
/**
|
|
|
|
|
* 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");
|
2018-02-28 13:13:13 +01:00
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
DEBUG_STREAM.begin(DEBUG_STREAM_BAUD);
|
|
|
|
|
while(!DEBUG_STREAM) {
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
MODEM_STREAM.begin(nbIOT.getDefaultBaudrate());
|
|
|
|
|
while(!MODEM_STREAM) {
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEBUG_STREAM.println(F("nbIOT init(): start"));
|
|
|
|
|
nbIOT.init(MODEM_STREAM, MODEM_ON_OFF_PIN);
|
|
|
|
|
nbIOT.setDiag(DEBUG_STREAM);
|
|
|
|
|
DEBUG_STREAM.println(F("nbIOT init(): done"));
|
|
|
|
|
|
|
|
|
|
// initialize the client
|
|
|
|
|
nbIOT.connectSocket();
|
|
|
|
|
wakaamaClient.init(&nbIOT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
DEBUG_STREAM.println(F("Checking modem state ... "));
|
|
|
|
|
|
|
|
|
|
nbIOT.isConnected();
|
|
|
|
|
|
|
|
|
|
if(!nbIOT.isRegistered()) {
|
|
|
|
|
DEBUG_STREAM.println(F("Modem is deregistered, trying to reconnect."));
|
|
|
|
|
if(!nbIOT.reconnectSocket()) {
|
|
|
|
|
delay(1000);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// our worker loop
|
|
|
|
|
wakaamaClient.doWorkStep();
|
|
|
|
|
|
|
|
|
|
// sleep a bit?
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
|