From eb6f83118b4378af05b49ab30467093ccc6054a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Wed, 28 Feb 2018 13:13:13 +0100 Subject: [PATCH] * integrated real modem code into the sketch --- wakamaa_integrated/wakamaa_integrated.ino | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 wakamaa_integrated/wakamaa_integrated.ino 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); +} +