NB IoT 2 click
NB IoT 2 Click is a compact add-on board that contains a compact LTE Cat NB2 module with ultra-low power consumption. This board features the BC66-NA, a high-performance, multi-band LTE Cat NB2 module with extremely low power consumption from Quectel Wireless Solutions.
click Product page
Click library
- Author : Stefan Ilic
- Date : Feb 2023.
- Type : UART type
Software Support
We provide a library for the NB IoT 2 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.
Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.
Library Description
This library contains API for NB IoT 2 Click driver.
Standard key functions :
nbiot2_cfg_setup
Config Object Initialization function.
void nbiot2_cfg_setup(nbiot2_cfg_t *cfg)
NB IoT 2 configuration object setup function.
NB IoT 2 Click configuration object.
Definition nbiot2.h:181
nbiot2_init
Initialization function.
err_t nbiot2_init(nbiot2_t *ctx, nbiot2_cfg_t *cfg)
NB IoT 2 initialization function.
NB IoT 2 Click context object.
Definition nbiot2.h:162
Example key functions :
nbiot2_set_rst_pin_state
This function sets RST pin state.
void nbiot2_set_rst_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the RST pin.
nbiot2_hw_reset
NB IoT 2 hardware reset function.
void nbiot2_hw_reset(nbiot2_t *ctx)
NB IoT 2 hardware reset function.
nbiot2_send_cmd
NB IoT 2 send command function.
void nbiot2_send_cmd(nbiot2_t *ctx, char *cmd)
NB IoT 2 send command function.
Example Description
This example reads and processes data from NB IoT 2 clicks.
The demo application is composed of two sections :
Application Init
Initializes driver, wake-up module and sets default configuration for connecting device to network.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( UART_ERROR ==
nbiot2_init( &nbiot2, &nbiot2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_printf( &logger, " - Reseting device... \r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
app_error_flag = nbiot2_process( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
app_error_flag = nbiot2_process( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
app_error_flag = nbiot2_check_response( );
nbiot2_error_check( app_error_flag );
log_info( &logger, " Application Task " );
app_buf_len = 0;
app_buf_cnt = 0;
}
#define NBIOT2_CMD_CPSMS
Definition nbiot2.h:99
#define NBIOT2_CMD_CEREG
Definition nbiot2.h:78
#define NBIOT2_CMD_QBAND
Definition nbiot2.h:101
#define NBIOT2_CMD_QSCLK
Definition nbiot2.h:104
#define NBIOT2_CMD_QNBIOTEVENT
Definition nbiot2.h:102
#define NBIOT2_CMD_ATI
Definition nbiot2.h:74
#define NBIOT2_CMD_SM
Definition nbiot2.h:103
#define NBIOT2_CMD_QRST
Definition nbiot2.h:100
#define NBIOT2_CMD_AT
NB IoT 2 control commands.
Definition nbiot2.h:73
#define NBIOT2_CMD_CSCON
Definition nbiot2.h:85
#define NBIOT2_CMD_CFUN
Definition nbiot2.h:76
#define NBIOT2_CMD_QSPCHSC
Definition nbiot2.h:98
#define NBIOT2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition nbiot2.h:148
void nbiot2_send_cmd_with_parameter(nbiot2_t *ctx, char *at_cmd_buf, char *param_buf)
NB IoT 2 send command function with parameter.
void nbiot2_set_apn(nbiot2_t *ctx, char *apn)
NB IoT 2 set sim card APN.
void application_init(void)
Definition main.c:185
#define CONFIGURATION_FOR_EXAMPLE
Definition main.c:72
#define SIM_APN
Definition main.c:67
Application Task
This application is split into two examples:
- TCP/UDP example - connecting to echo server and writing and reading data.
- SMS example - Sending SMS message to desired number using TEXT or PDU mode.
{
switch( app_connection_status )
{
{
nbiot2_config_device_for_example( );
break;
}
{
#if defined( NBIOT2_TCP_UDP_EXAMPLE )
nbiot2_tcp_udp_example( );
#endif
#if defined( NBIOT2_SMS_EXAMPLE )
nbiot2_send_sms( );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
#endif
break;
}
default:
{
log_error( &logger, "Application status error!" );
Delay_ms ( 1000 );
break;
}
}
}
#define EXAMPLE
Definition main.c:73
void application_task(void)
Definition main.c:283
Note
In order for the examples to work, user needs to set the APN and SMSC (SMS PDU mode only)
of entered SIM card as well as the phone number to which he wants to send an SMS. Enter valid values for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER_TO_MESSAGE.
Example:
- SIM_APN "internet"
- SIM_SMSC "+381610401"
- PHONE_NUMBER_TO_MESSAGE "+381659999999"
The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.
Other Mikroe Libraries used in the example:
- MikroSDK.Board
- MikroSDK.Log
- Click.NBIoT2
Additional notes and informations
Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.