* integrated real modem code into the sketch
This commit is contained in:
parent
a845b34fbc
commit
eb6f83118b
59
wakamaa_integrated/wakamaa_integrated.ino
Normal file
59
wakamaa_integrated/wakamaa_integrated.ino
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#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
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user