Development

» NB-IoT 23: scan operator

This example shows how to scan network operators.

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_23 - Scan operators  ---------------

    Explanation: This example shows how to scan network operators.

    *  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 <http://www.gnu.org/licenses/>.
    *
    *  Version:           1.0
    *  Design:            David Gascón
    *  Implementation:    P.Moreno, J.Siscart
    */

#include <WaspBG96.h>

uint8_t error;
uint32_t previous;

void setup()
{
  //////////////////////////////////////////////////
  // 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
  {
    // Problem with the communication with the 4G module
    USB.println(F("1. BG96 module not started"));
    USB.print(F("Error code: "));
    USB.println(error, DEC);
  }


    ////////////////////////////////////////////////
    // 1.1. Hardware identification
    ////////////////////////////////////////////////
    error = BG96.getInfo(WaspBG96::INFO_HW);
    if (error == 0)
    {
      USB.print(F("1.1. Hardware identification: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("1.1. Manufacturer identification ERROR"));
    }

    ////////////////////////////////////////////////
    // 1.2. User manual AT command
    // sendATcommand("<AT command>", "<Module response>", timeout)
    // AT command: AT command sent to the module.
    // Module response: Response to the AT command sent it. Typical response is OK.
    // timeout: Time period to wait a module response.
    ////////////////////////////////////////////////
    error = BG96.sendATcommand("AT+CFUN=0", "OK", 2000);
    if (error == 0)
    {
      USB.print(F("BG96 answer: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("1.2. AT command ERROR"));
    }

    ////////////////////////////////////////////////
    // 1.3. User manual AT command
    // sendATcommand("<AT command>", "<Module response>", timeout)
    // AT command: AT command sent to the module.
    // Module response: Response to the AT command sent it. Typical response is OK.
    // timeout: Time period to wait a module response.
    ////////////////////////////////////////////////
    error = BG96.sendATcommand("AT+QCFG=\"nwscanseq\",00,1", "OK", 2000);
    if (error == 0)
    {
      USB.print(F("BG96 answer: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("1.2. AT command ERROR"));
    }

    ////////////////////////////////////////////////
    // 1.4. User manual AT command
    // sendATcommand("<AT command>", "<Module response>", timeout)
    // AT command: AT command sent to the module.
    // Module response: Response to the AT command sent it. Typical response is OK.
    // timeout: Time period to wait a module response.
    ////////////////////////////////////////////////
    error = BG96.sendATcommand("AT+QCFG=\"nwscanmode\",0,1", "OK", 2000);
    if (error == 0)
    {
      USB.print(F("BG96 answer: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("1.2. AT command ERROR"));
    }

    ////////////////////////////////////////////////
    // 1.5. User manual AT command
    // sendATcommand("<AT command>", "<Module response>", timeout)
    // AT command: AT command sent to the module.
    // Module response: Response to the AT command sent it. Typical response is OK.
    // timeout: Time period to wait a module response.
    ////////////////////////////////////////////////
    error = BG96.sendATcommand("AT+QCFG=\"iotopmode\",2,1", "OK", 2000);
    if (error == 0)
    {
      USB.print(F("BG96 answer: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("1.2. AT command ERROR"));
    }

    ////////////////////////////////////////////////
    // 1.6. User manual AT command
    // sendATcommand("<AT command>", "<Module response>", timeout)
    // AT command: AT command sent to the module.
    // Module response: Response to the AT command sent it. Typical response is OK.
    // timeout: Time period to wait a module response.
    ////////////////////////////////////////////////
    error = BG96.sendATcommand("AT+CFUN=1", "OK", 2000);
    if (error == 0)
    {
      USB.print(F("BG96 answer: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("1.2. AT command ERROR"));
    }

    //Waitting a little bit
    delay(5000);

    ////////////////////////////////////////////////
    // 2. Scan operators network
    ////////////////////////////////////////////////
    error = BG96.scanOperators();
    if (error == 0)
    {
      USB.print(F("2. Operators List: "));
      USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("2. Scan ERROR"));
    }

    ////////////////////////////////////////////////
    // 3. Scan operators network
    ////////////////////////////////////////////////
    error = BG96.OFF();
    if (error == 0)
    {
      USB.print(F("3. Module is power off"));
      //USB.println(BG96._buffer, BG96._length);
    }
    else
    {
      USB.println(F("3. Power off ERROR"));
    }

}


void loop()
{
  // put your main code here, to run repeatedly:

}

Output

J#
BG96 Module ON...
1. BG96 module ready in 12625 ms
1.1. Hardware identification: BG96MAR02A08M1G
Manual AT: AT+CFUN=0
BG96 answer:
OK
Manual AT: AT+QCFG="nwscanseq",00,1
BG96 answer:
OK
Manual AT: AT+QCFG="nwscanmode",0,1
BG96 answer:
OK
Manual AT: AT+QCFG="iotopmode",2,1
BG96 answer:
OK
Manual AT: AT+CFUN=1
BG96 answer:
OK
This operation could take a time...
2. Operators List:
+COPS: (1,"vodafone ES","voda ES","21401",0),(1,"Movistar","Movistar","21407",0),(1,"Orange SP","ESPRT","21403",0),(1,"vodafone ES","voda ES","21401",9),,(0,1,2,3,4),(0,1,2)

OK
3. Module is power off

Quick Publish: