NB-IoT 22: manual AT command
This example shows how to send manual AT commands to NB-IoT module.
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_22 - manual AT commands ---------------
Explanation: This example shows how to send manual AT commands to NB-IoT module.
* 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
uint8_t error;
uint32_t previous;
void setup(){
}
void loop()
{
//////////////////////////////////////////////////
// 1. Switch on the BG96 module
//////////////////////////////////////////////////
previous = millis();
USB.println("BG96 Module ON...");
error = BG96.ON();
if (error == 0)
{
USB.print(F("1. BG96 module ready in "));
USB.print(millis()-previous);
USB.println(F(" ms"));
}
else
{
USB.println(F("1. BG96 module not started"));
USB.print(F("Error code: "));
USB.println(error, DEC);
}
////////////////////////////////////////////////
// 2.1. User manual AT command
// sendCommand("","","",timeout)
// AT command: AT command sent to the module.
// Module response: Response to the AT command sent it. Typical response is OK.
// Module response_2: ERROR Response. Typical response is ERROR.
// timeout: Time period to wait a module response.
////////////////////////////////////////////////
error = BG96.sendCommand("ATI\r", "OK", "ERROR", 2000);
if (error != 1)
{
if (error == 2)
{
USB.println(F("2.1. AT command ERROR:"));
USB.println(BG96._buffer, BG96._length);
}
if (error == 0)
{
USB.println(F("2.1. AT command Timeout:"));
}
}
else
{
USB.println(F("2.1. SendCommand OK. Module answer: "));
USB.println(BG96._buffer, BG96._length);
}
////////////////////////////////////////////////
// 2.2. User manual AT command
// sendCommand("","","",timeout)
// AT command: AT command sent to the module.
// Module response: Response to the AT command sent it. Typical response is OK.
// Module response_2: ERROR Response. Typical response is ERROR.
// timeout: Time period to wait a module response.
////////////////////////////////////////////////
error = BG96.sendCommand("AT+QGMR\r", "OK", "ERROR", 2000);
if (error != 1)
{
if (error == 2)
{
USB.println(F("2.2. AT command ERROR:"));
USB.println(BG96._buffer, BG96._length);
}
if (error == 0)
{
USB.println(F("2.2. AT command Timeout:"));
}
}
else
{
USB.println(F("2.2. SendCommand OK. Module answer: "));
USB.println(BG96._buffer, BG96._length);
}
//////////////////////////////////////////////////
// 3. Sleep
//////////////////////////////////////////////////
USB.println(F("3. Enter deep sleep..."));
PWR.deepSleep("00:00:01:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
USB.ON();
USB.println(F("4. Wake up!!\n\n"));
}
Output
J#
BG96 Module ON...
1. BG96 module ready in 12624 ms
Manual AT: ATI
2.1. BG96 answer:
Quectel
BG96
Revision: BG96MAR02A08M1G
OK
Manual AT: AT+QGMR
2.2. BG96 answer:
BG96MAR02A08M1G_01.008.01.008
OK
3. Enter deep sleep...
Last updated