NB-IoT 04b: Basic connection Cat-M
This example shows how to switch on the NB-IoT module connect it to the network and get the operator name.
Required Materials
1 x Waspmote 1 x Battery 1 x NB-IoT / Cat-M module 2 x NB-IoT / Cat-M antenna 1 x SIM card
Notes
- The battery has to be connected. - This example can be executed in Waspmote v15
Code
/*
* ------ NB_IoT 04 - Basic connection to LTE Cat-M1 network --------
*
* Explanation: This example shows how to switch on the NB-IoT module
connect it to the network and get the operator name.
*
* Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version: 3.1
* Design: David Gascón
* Implementation: P.Moreno, J.Siscart
*/
#include
// APN settings
char apn[] = "";
char login[] = "";
char password[] = "";
///////////////////////////////////////
// Operator selection
///////////////////////////////////////
char network_operator[] = "";
///////////////////////////////////////
// options:
// LALPHANUMERIC_OPERATOR Long format alphanumeric which can be up to 16 characters long.
// SALPHANUMERIC_OPERATOR Short format alphanumeric .
// NUMERIC_OPERATOR Numeric . GSM location area identification number.
///////////////////////////////////////
uint8_t operator_type = LALPHANUMERIC_OPERATOR;
///////////////////////////////////////
// Band configuration
///////////////////////////////////////
// NB-IoT & LTE-M1 bands:
// B1
// B2
// B3
// B4
// B5
// B8
// B12
// B13
// B18
// B19
// B20
// B26
// B28
// B39
// ------------------------------------
// GSM bands:
// GSM900
// GSM1800
// GSM850
// GSM1900
// GSM_ANYBAND
// NB_ANYBAND
// M1_ANYBAND
/////////////////////////////////////
char band[] = B20;
/////////////////////////////////////
uint8_t error;
void setup()
{
USB.ON();
USB.println(F("Start program\n"));
//////////////////////////////////////////////////
// 1. sets operator parameters
//////////////////////////////////////////////////
BG96.set_APN(apn, login, password);
//////////////////////////////////////////////////
// 2. Show APN settings via USB port
//////////////////////////////////////////////////
BG96.show_APN();
}
void loop()
{
//////////////////////////////////////////////////
// 1. Switch ON the NB-IoT module
//////////////////////////////////////////////////
error = BG96.ON();
if (error == 0)
{
USB.println(F("1. NB-IoT module ready"));
////////////////////////////////////////////////
// 1.1. Check connection to network and continue
////////////////////////////////////////////////
error = BG96.lteM1Connection(apn, band, network_operator, operator_type);
if (error == 0)
{
USB.println(F("1.1. LTE Cat-M1 connection: OK "));
////////////////////////////////////////////////
// 1.2.1 LTE Cat-M1 Context Activation
////////////////////////////////////////////////
error = BG96.contextActivation(1,5);
if (error == 0)
{
USB.println(F("1.1. LTE Cat-M1 context connection: OK "));
USB.print(F("IP: ")); USB.println(BG96._ip);
}
}
}
else
{
// Problem with the communication with the NB-IoT module
USB.println(F("NB-IoT module not started"));
USB.print(F("Error code: "));
USB.println(error, DEC);
}
//////////////////////////////////////////////////
// 2. Switch OFF the NB-IoT module
//////////////////////////////////////////////////
error = BG96.OFF();
if (error == 0)
{
USB.println(F("2. Module is power off"));
}
else
{
USB.println(F("2. Power off ERROR"));
}
USB.println(F("2. Switch OFF NB-IoT module"));
//////////////////////////////////////////////////
// 3. Sleep
//////////////////////////////////////////////////
USB.println(F("3. Enter deep sleep..."));
PWR.deepSleep("00:00:00:10", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
USB.ON();
USB.println(F("4. Wake up!!\n\n"));
}
Output
J#
Start program
*****************************
APN:
LOGIN:
PASSWORD:
*****************************
1. NB-IoT module ready
1.1. Cat-M connection: OK
1.1. Cat-M context connection: OK
IP: 10.175.32.25
2. Module is power off
2. Switch OFF NB-IoT module
3. Enter deep sleep...
4. Wake up!!
Last updated