From 5417e8a3304ce3cbda3d3878852836cd88a37896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danyi=20D=C3=A1vid?= Date: Tue, 17 Oct 2017 21:39:34 +0200 Subject: [PATCH] * initial commit --- lwm2m/lwm2m.ino | 39 +++++++++++++++++++++++++++++ modem_teszt/modem_teszt.ino | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 lwm2m/lwm2m.ino create mode 100644 modem_teszt/modem_teszt.ino diff --git a/lwm2m/lwm2m.ino b/lwm2m/lwm2m.ino new file mode 100644 index 0000000..e29c860 --- /dev/null +++ b/lwm2m/lwm2m.ino @@ -0,0 +1,39 @@ +#include +#include +#include + +// network config +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192,168,14,21); +IPAddress dnsIp(8,8,8,8); +//IPAddress gatewayIp(192,168,14,1); + +// constructor only sets uri, init() called later so we can debug print +//ArduinoClient wakaamaClient("coap://192.168.14.14:5683"); +//ArduinoClient wakaamaClient("coap://leshan.eclipse.org:5683"); +ArduinoClient wakaamaClient("coap://ethinnoday-lwm2m-server.westeurope.cloudapp.azure.com:5683"); + +void setup() { + delay(5000); + Ethernet.begin(mac, ip, dnsIp); +// Ethernet.begin(mac, ip, dnsIp, gatewayIp); + SerialOut.begin(9600); + while (!SerialOut) { + ; // wait for serial port to connect. + } + SerialOut.println(F("Serial init done")); + + // initialize the client + wakaamaClient.init(); +} + +void loop() { + // our worker loop + wakaamaClient.doWorkStep(); + + // sleep a bit while we are in debug mode + delay(1000); +} + diff --git a/modem_teszt/modem_teszt.ino b/modem_teszt/modem_teszt.ino new file mode 100644 index 0000000..338b8d4 --- /dev/null +++ b/modem_teszt/modem_teszt.ino @@ -0,0 +1,50 @@ +#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; +int pending; +char * buffer; + +void setup() { + buffer = static_cast(malloc(250)); + DEBUG_STREAM.begin(DEBUG_STREAM_BAUD); + while(!DEBUG_STREAM) { + ; + } + MODEM_STREAM.begin(nbiot.getDefaultBaudrate()); + while(!MODEM_STREAM) { + ; + } + + nbiot.init(MODEM_STREAM, MODEM_ON_OFF_PIN); + nbiot.setDiag(DEBUG_STREAM); + + nbiot.connectSocket(); + + socket = nbiot.createSocket(1313); + DEBUG_STREAM.print("socket: "); + DEBUG_STREAM.println(socket); +} + + +void loop() { + DEBUG_STREAM.println("loop() start"); + nbiot.sendSocket(socket, "87.229.111.223", 1111, "asdf", 4); + + pending = nbiot.socketBytesPending(socket); + if(pending > 0) { + nbiot.socketReceive(socket, buffer, pending); + DEBUG_STREAM.println(buffer); + } + + DEBUG_STREAM.println("loop() delay"); + delay(5000); +}