Spivey
Published © MIT

Publish an Event to Wia Using Your SODAQ SARA N211 & NB-IoT

Learn how to set up your SODAQ SARA N211 and post an Event to Wia via NB-IoT.

IntermediateFull instructions provided2 hours609
Publish an Event to Wia Using Your SODAQ SARA N211 & NB-IoT

Things used in this project

Hardware components

SODAQ SARA N211
×1
Crowduino M0
×1
SODAQ NB-IoT Compatible Antenna
×1
NB-IoT Compatible SIM Card
(speak to your network operator about this)
×1

Software apps and online services

Wia
Wia

Story

Read more

Code

initial_config.ino

Arduino
#include "Arduino.h"

#if defined(ARDUINO_AVR_LEONARDO)
#define USB Serial
#define UBLOX Serial1

#elif defined(ARDUINO_SODAQ_EXPLORER)
#define USB SerialUSB
#define UBLOX Serial

#elif defined(ARDUINO_SAM_ZERO)
#define USB SerialUSB
#define UBLOX Serial1

#else
#error "Please select a Sodaq ExpLoRer, Arduino Leonardo or Arduino m0."
#endif

// Pin to turn on/off the nb-iot module
#define powerPin 7
unsigned long baud = 9600;  //start at 9600 allow the USB port to change the Baudrate


void setup()
{
  // Turn the nb-iot module on
  pinMode(powerPin, OUTPUT);
  digitalWrite(powerPin, HIGH);

  // Start communication
  USB.begin(baud);
  UBLOX.begin(baud);
}

// Forward every message to the other serial
void loop()
{
  while (USB.available())
  {
    uint8_t c = USB.read();
    UBLOX.write(c);
  }

  while (UBLOX.available())
  {
    USB.write(UBLOX.read());
  }

  // check if the USB virtual serial wants a new baud rate
  if (USB.baud() != baud) {
    baud = USB.baud();
       UBLOX.begin(baud);
  }
}

Credits

Spivey

Spivey

82 projects • 59 followers
Tourist in a Tutu || US Born || Melbourne/Mexico/California Raised || New Yorker at ❤️ || SF to Dublin to be COO of Wia the best IoT startup

Comments