* updated from upstream

* forced connection attempt is now hardcoded in Sodaq_nbIOT::connectSocket()
* udp send recieve now works, may contain bugs on fast multiple incoming messages,
  have to check if this can be an issue or not
This commit is contained in:
Dávid Danyi
2018-02-15 18:48:07 +01:00
parent cfae7d6ba8
commit e0f54a37cd
10 changed files with 1077 additions and 198 deletions

View File

@@ -22,13 +22,48 @@
#include <Sodaq_wdt.h>
#ifdef ARDUINO_SODAQ_EXPLORER
/* SODAQ Explorer + SODAQ NB-IoT Shield */
#define DEBUG_STREAM SerialUSB
#define MODEM_ON_OFF_PIN 7
#define MODEM_STREAM Serial
#elif defined(ARDUINO_SAM_ZERO)
/* Arduino Zero / M0 + SODAQ NB-IoT Shield */
#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1
#define MODEM_ON_OFF_PIN 7
#elif defined(ARDUINO_AVR_LEONARDO)
/* Arduino Leonardo + SODAQ NB-IoT Shield */
#define DEBUG_STREAM Serial
#define MODEM_STREAM Serial1
#define MODEM_ON_OFF_PIN 7
#elif defined(ARDUINO_SODAQ_AUTONOMO)
/* SODAQ AUTONOMO + SODAQ NB-IoT Bee */
#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1
#define MODEM_ON_OFF_PIN BEE_VCC
#define MODEM_DTR BEEDTR
#elif defined(ARDUINO_AVR_SODAQ_MBILI)
/* SODAQ MBILI + SODAQ NB-IoT Bee */
#define DEBUG_STREAM Serial
#define MODEM_STREAM Serial1
#define MODEM_DTR BEEDTR
#elif defined(ARDUINO_SODAQ_SARA)
/* SODAQ SARA */
#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1
#define MODEM_ON_OFF_PIN SARA_ENABLE
#define MODEM_DTR SARA_TX_ENABLE
#else
#error "You need to declare the modem on/off pin and stream for your particular board!"
#endif
#define DEBUG_STREAM SerialUSB
#define DEBUG_STREAM_BAUD 115200
#define STARTUP_DELAY 5000
@@ -50,9 +85,43 @@ void setup()
DEBUG_STREAM.print("Initializing and connecting... ");
#ifdef MODEM_DTR
// Set state to active
pinMode(MODEM_DTR, OUTPUT);
digitalWrite(MODEM_DTR, HIGH);
#endif // MODEM_DTR
nbiot.init(MODEM_STREAM, MODEM_ON_OFF_PIN);
nbiot.setDiag(DEBUG_STREAM);
connectModem();
}
void loop()
{
if (nbiot.isConnected()) {
const char* message = "Hello World!";
DEBUG_STREAM.print("Sending message: \"");
DEBUG_STREAM.print(message);
DEBUG_STREAM.print("\"... ");
if (!nbiot.sendMessage(message)) {
DEBUG_STREAM.println("Could not queue message!");
}
else {
DEBUG_STREAM.println("Message queued for transmission!");
}
showMessageCountFromModem();
}
else {
connectModem();
}
sodaq_wdt_safe_delay(5000);
}
void connectModem() {
if (nbiot.connect(apn, cdp, forceOperator)) {
DEBUG_STREAM.println("Connected succesfully!");
}
@@ -60,29 +129,6 @@ void setup()
DEBUG_STREAM.println("Failed to connect!");
return;
}
showMessageCountFromModem();
const char* message = "Hello World!";
DEBUG_STREAM.print("Sending message: \"");
DEBUG_STREAM.print(message);
DEBUG_STREAM.print("\"... ");
if (!nbiot.sendMessage(message)) {
DEBUG_STREAM.println("Could not queue message!");
}
else {
DEBUG_STREAM.println("Message queued for transmission!");
}
}
void loop()
{
if (nbiot.isConnected()) {
showMessageCountFromModem();
}
sodaq_wdt_safe_delay(5000);
}
void showMessageCountFromModem()