diff --git a/wakamaa_integrated/wakamaa_integrated.ino b/wakamaa_integrated/wakamaa_integrated.ino new file mode 100644 index 0000000..f321aea --- /dev/null +++ b/wakamaa_integrated/wakamaa_integrated.ino @@ -0,0 +1,59 @@ +#include +#include + +#include +#include + +#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 +ArduinoClient wakaamaClient("coap://5.39.83.206:5683"); + +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); +} +