56 lines
1.2 KiB
Arduino
Raw Permalink Normal View History

2017-10-17 21:39:34 +02:00
#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;
int pending;
char * buffer;
2017-10-18 00:58:21 +02:00
int sendResult = 0;
2017-10-17 21:39:34 +02:00
void setup() {
buffer = static_cast<char*>(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);
}
void loop() {
2017-10-18 00:58:21 +02:00
DEBUG_STREAM.println(F(__FILE__":loop() start"));
sendResult = nbiot.sendSocket(socket, "87.229.111.223", 1111, "asdf", 4);
DEBUG_STREAM.print(F(__FILE__":loop() sent:"));
DEBUG_STREAM.println(sendResult);
delay(2000);
2017-10-17 21:39:34 +02:00
pending = nbiot.socketBytesPending(socket);
if(pending > 0) {
2017-10-18 00:58:21 +02:00
DEBUG_STREAM.println(F(__FILE__":loop() got pending"));
2017-10-17 21:39:34 +02:00
nbiot.socketReceive(socket, buffer, pending);
DEBUG_STREAM.println(buffer);
}
2017-10-18 00:58:21 +02:00
DEBUG_STREAM.println(F(__FILE__":modem_teszt.ino:loop() delay"));
delay(2000);
2017-10-17 21:39:34 +02:00
}