Skip to content

UBee

Passthrough

With the passthrough sketch you can send AT commands (NB-IoT) to the ublox module on the ubee.

Follow the steps on the Mbili or Autonomo support pages to install the required board files.

This example doesn’t require any additional libraries. Simply plug the bee into your Mbili or Autonomo and upload the example code.

/*
 * SODAQ UBee - Serial Passthrough
 *
 * This sketch is tested with the UBee with the N2 and the R4 module in combination 
 * with a SODAQ Autonomo and SODAQ Mbili
 * The UBee will work on every board with a (x)bee pinout.
 * The Mbili does not wok with the R4 module, it can't handle the fast baudrate.
 *
 * If you have questions about this sketch you can ask them on forum.sodaq.com
 */

#include <Arduino.h>

// #define R4XX // Uncomment when you use the ublox R4XX module

#if defined(ARDUINO_SODAQ_AUTONOMO)
/* SODAQ AUTONOMO + SODAQ (uBlox SARA) UBee */
#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1
#define powerPin BEE_VCC
#define enablePin BEEDTR
#define powerTogglePin BEERTS

#elif defined(ARDUINO_AVR_SODAQ_MBILI)
/* SODAQ MBILI + SODAQ (uBlox SARA) UBee */
#define DEBUG_STREAM Serial
#define MODEM_STREAM Serial1
#define powerPin 20
#define enablePin BEEDTR
#define powerTogglePin BEERTS

#else
#error "Please use one of the listed boards or add your board."
#endif

#ifdef R4XX
    // Start at 115200 allow the USB port to change the Baudrate.
    unsigned long baud = 115200;  
#else
    // Start at 9600 allow the USB port to change the Baudrate.
    unsigned long baud = 9600;
#endif

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

#ifdef enablePin
  // Set state to active
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, HIGH);
#endif // enablePin

#ifdef R4XX
    // The R4XX module has an on/off pin. 
    // You can toggle this pin or keep it low to switch on the module.
    pinMode(powerTogglePin, OUTPUT);
    digitalWrite(powerTogglePin, LOW);
#endif

  delay(100);

  // Start communication
  DEBUG_STREAM.begin(baud);
  MODEM_STREAM.begin(baud);

  delay(1000);
}

// Forward every message to the other serial
void loop()
{
  while (DEBUG_STREAM.available())
  {
    MODEM_STREAM.write(DEBUG_STREAM.read());
  }

  while (MODEM_STREAM.available())
  {
    DEBUG_STREAM.write(MODEM_STREAM.read());
  }
}

Note

The Mbili can not handle the high baudrate of the R4 module.

Library

You can install libraries with the Arduino Library manager.

Open Arduino
Click on Sketch > Include Libraries > Manage Libraries…

Search for Sodaq_N2X, Sodaq_R4X or Sodaq_3Gbee(2G/GPRS and 3G) depending on your module. Click on the bar to show the install button and install the library.

Click on File > Examples > [library name] to see more example codes.

Our libraries can also be found on GitHub.
Sodaq_R4X
Sodaq_N2X
Sodaq_3Gbee

R4XX Example

This is an example for the R4XX module together with the SODAQ Autonomo.
For the Autonomo and other boards a custom class Sodaq_OnOffBee needs to be made.
In the example below we made the custom class Sodaq_OnOffBee for the SODAQ Autonomo.

It's recommended to turnon debug in the library.
This can be done in Sodaq_R4x.cpp to comment out #define DEBUG.

It's a bit harded to update the UBEEs R4XX firmware.
Settings the MNO Profile is required in the latest firmware, this is also required in the library.
By setting it to SWD_DEFAULT you can the new library with the old firmware.
#define CURRENT_MNO_PROFILE MNOProfiles::SWD_DEFAULT

/*
Copyright (c) 2020, SODAQ
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#include <Sodaq_R4X.h>
#include <Sodaq_wdt.h>

#define CONSOLE_STREAM   SerialUSB
#define MODEM_STREAM     Serial1

// Uncomment your operator
// #define MONOGOTO
// #define VODAFONE_LTEM
// #define VODAFONE_NBIOT
// #define CUSTOM

#if defined(MONOGOTO)
#define CURRENT_APN      "data.mono"
#define CURRENT_OPERATOR AUTOMATIC_OPERATOR
#define CURRENT_URAT     SODAQ_R4X_LTEM_URAT
#define CURRENT_MNO_PROFILE MNOProfiles::STANDARD_EUROPE
#elif defined(VODAFONE_LTEM)
#define CURRENT_APN      "live.vodafone.com"
#define CURRENT_OPERATOR AUTOMATIC_OPERATOR
#define CURRENT_URAT     SODAQ_R4X_LTEM_URAT
#define CURRENT_MNO_PROFILE MNOProfiles::VODAFONE
#elif defined(VODAFONE_NBIOT)
#define CURRENT_APN      "nb.inetd.gdsp"
#define CURRENT_OPERATOR AUTOMATIC_OPERATOR
#define CURRENT_URAT     SODAQ_R4X_NBIOT_URAT
#define CURRENT_MNO_PROFILE MNOProfiles::VODAFONE
#define NBIOT_BANDMASK "524288"
#elif defined(CUSTOM)
#define CURRENT_APN      "[your apn]"
#define CURRENT_OPERATOR AUTOMATIC_OPERATOR
#define CURRENT_URAT     SODAQ_R4X_LTEM_URAT
#define CURRENT_MNO_PROFILE MNOProfiles::SIM_ICCID
#else 
#error "Please define a operator"
#endif

#define HTTP_HOST        "time.sodaq.net"
#define HTTP_PORT        80
#define HTTP_QUERY       "/"

static Sodaq_R4X r4x;

class Sodaq_SARA_R4XX_UBEE_OnOff : public Sodaq_OnOffBee
{
public:
    Sodaq_SARA_R4XX_UBEE_OnOff();
    void on();
    void off();
    bool isOn();
private:
    bool _onoff_status;
};

static Sodaq_SARA_R4XX_UBEE_OnOff saraR4xxOnOff;
static bool isReady;

#ifndef NBIOT_BANDMASK
#define NBIOT_BANDMASK BAND_MASK_UNCHANGED
#endif

void setup()
{
    while ((!CONSOLE_STREAM) && (millis() < 10000)){
        // Wait max 10 sec for the CONSOLE_STREAM to open
    }

    CONSOLE_STREAM.begin(115200);
    MODEM_STREAM.begin(r4x.getDefaultBaudrate());

    r4x.setDiag(CONSOLE_STREAM);
    r4x.init(&saraR4xxOnOff, MODEM_STREAM);

    isReady = r4x.connect(CURRENT_APN, CURRENT_URAT, CURRENT_MNO_PROFILE, CURRENT_OPERATOR, BAND_MASK_UNCHANGED, NBIOT_BANDMASK);
    CONSOLE_STREAM.println(isReady ? "Network connected" : "Network connection failed");

    CONSOLE_STREAM.println("Setup done");

    if (isReady) {
        downloadFile();
    }
}

void loop()
{
    if (CONSOLE_STREAM.available()) {
        int i = CONSOLE_STREAM.read();
        CONSOLE_STREAM.write(i);
        MODEM_STREAM.write(i);
    }

    if (MODEM_STREAM.available()) {
        CONSOLE_STREAM.write(MODEM_STREAM.read());
    }
}

void downloadFile()
{
    char buffer[2048];

    uint32_t i = r4x.httpGet(HTTP_HOST, HTTP_PORT, HTTP_QUERY, buffer, sizeof(buffer));

    CONSOLE_STREAM.print("Read bytes: ");
    CONSOLE_STREAM.println(i);

    if (i > 0) {
        buffer[i] = 0;
        CONSOLE_STREAM.println("Buffer:");
        CONSOLE_STREAM.println(buffer);
    }
}

/******************************************************************************
 * OnOff
 *****************************************************************************/

Sodaq_SARA_R4XX_UBEE_OnOff::Sodaq_SARA_R4XX_UBEE_OnOff()
{
    // First write the output value, and only then set the output mode.
    digitalWrite(BEE_VCC, LOW);
    pinMode(BEE_VCC, OUTPUT);

    digitalWrite(BEEDTR, LOW);
    pinMode(BEEDTR, OUTPUT);

    _onoff_status = false;
}

void Sodaq_SARA_R4XX_UBEE_OnOff::on()
{
    digitalWrite(BEE_VCC, HIGH);
    digitalWrite(BEEDTR, HIGH);

    pinMode(BEERTS, OUTPUT);
    digitalWrite(BEERTS, LOW);
    // We should be able to reduce this to 50ms or something
    sodaq_wdt_safe_delay(2000);
    pinMode(BEERTS, INPUT);

    _onoff_status = true;
}

void Sodaq_SARA_R4XX_UBEE_OnOff::off()
{
    digitalWrite(BEE_VCC, LOW);
    digitalWrite(BEEDTR, LOW);

    _onoff_status = false;
}

bool Sodaq_SARA_R4XX_UBEE_OnOff::isOn()
{
    return _onoff_status;
}

Schematics

ubee_schematic

Firmware updates

Contact your u-blox representive to obtain the latest firmware.

N2

With the command ATI9 you can check your firware version. Result N2 should be: 06.57,A10.08

Note

The N2 modules need to be updated to 06.57,A07.03 before updating to 06.57,A09.06.
The N2 modules need to be updated to 06.57,A09.06 before updating to 06.57,A10.08.

  1. Load the passthrough sketch on your board.
  2. Open UEUpdater.
  3. Select the correct firmware file.
  4. Press the Update button and wait for 60 seconds.
  5. The programm tells you the update is complete.
  6. Your module is updated!

Ubees with SARA N2 modules can be updated through the serial interface.

Note

You need a board who can handle the 115200 baudrate.
The Mbili can not handle the high baudrate which is needed to upgrade the module.

R4

With the command ATI9 you can check your firmware version.

The latest firmware version for the R412 is M0.10.00,A.02.14.
The latest firmware version for the R410 is L0.0.00.00.05.08,A.02.04.

Note

From these firmware versions it's required to set a MNO Profile.

Ubees with SARA R4 modules can be updated with soldering an usb cable to the usb pins and turning the module on.

  1. Contact u-blox for the latest firmware and update tool.
  2. Solder the USB to the update pins, to directly communicate with the u-blox module.
    ubee_sara_pins
  3. Load the passthrough sketch on your board.
  4. Install EasyFlash.
  5. Reboot PC.
  6. Put the firmware file in the installation directory.
  7. Open EasyFlash as administrator.
  8. Select R4 and USB, leave baudrate empty.
  9. Hit Start and relax till the update is successful.

Other modules

All other Ubees shouldn’t require an firmware update.