1.概述

Gravity:I2C & UART BC20 NB-IoT & GNSS通信模块是具有NB-IoT低功耗蜂窝通信和GPS/BeiDou双星精确定位功能的物联网通信模块。只要设备所在地区在NB-IoT信号覆盖范围内,无论在室内外均可轻松将开发板或设备采集的各类数据上传至云端,当然也可以通过云端发送指令来远程控制设备,实现云端与真实设备的双向通信与控制,实现“物联”,尤其适用于环境监控站、共享单车、车载定位追踪器等户外物联网应用场景。

此外,模块带有GPS/BeiDou双星精确定位功能,只要将定位天线置于室外即可获取精确的地理坐标和授时信息,实时监控设备的物理位置。用户可通过板载RGB指示灯,清晰了解模块的各类工作状态。为了兼容常见的Arduino、掌控和树莓派等各类3.3V/5V开发板,模块还采用了Gravity I2C & UART复合标准接口,并对这些创客用户常用的开发板在软件上作了全面支持。

注意

  • NB-IoT工作于授权频带下,类似于手机2G/3G/4G SIM卡,需要通过SIM卡额外支付通信套餐费用,产品包装附有一张NB-IoT专用SIM卡,可免费使用一年,无需实名,上电即用(流量详见后续NB-IoT SIM卡资费表)。 *注意:不建议使用sendATCMD()修改bc20的波特率,会造成模块无法初始化

2.物联网与NB-IoT简介

物联网(The Internet of things,IoT)顾名思义,就是物与物相连的互联网。这有两层意思:第一,物联网的核心和基础仍然是互联网,是在互联网基础上的延伸和扩展的网络;第二,其用户端延伸和扩展到了任何物品与物品之间,进行信息交换和通信。

窄带物联网(Narrow Band Internet of Things,NB-IoT)是物联网领域一个新兴的技术,主要用于低移动性、小数据量、对时延不敏感的连接服务,其支持低功耗设备在网络中的数据传输,因此也是一种低功耗广域网(Low Power Wide Area Network,LPWAN)通信技术。相对于被逐渐淘汰的2G通信,NB-IoT具有三大优势:

3.特性

4.应用场景

5.技术规格

6.接口说明


标号 名称 功能描述
1 D/T I2C数据线SDA或串口UART发送端TXD(3.3V电平)
2 C/R I2C时钟线SCL或串口UART接收端RXD(3.3V电平)
3 GND 电源负极
4 VCC 电源正极(3.3~5.5V)
5 IRQ PSM休眠唤醒管脚,当模块处于PSM低功耗模式下,将该管脚拉高以唤醒模块。
6 I2C/UART I2C/UART接口选择开关
7 NB NB-IoT天线接口
8 RGB RGB LED全彩指示灯
9 / I2C地址选择拨码。0x30(A0=0,A1=0),0x31(A0=0,A1=1),0x32(A0=1,A1=0),0x33(A0=1,A1=1,默认)
10 RST 模块复位按钮
11 GNSS GPS/BeiDou卫星定位天线接口
12 Micro SIM NB-IoT专用SIM卡座(micro SIM)

7.硬件连接

注意

  • PCB天线背后有3M双面胶,撕开保护层后可贴附于非金属表面,在非金属箱体中使用,如:水质监控站或太阳能气象站的塑料防水盒,项目制作常用的亚克力表面。但是不能贴附于金属表面在金属箱体中使用,否则会严重影响信号质量。


8.Arduino使用教程

8.1 准备

8.2 接线图



8.3 样例代码(Arduino IDE)

配置通信接口

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO17       |               D16(RX)        |       D/T
   IO16       |               D17(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial1);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD, PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif
DFRobot_BC20_IIC myBC20(0x33);
/*Communication by IIC*/
//#define USE_IIC

/*Communication by HardwareSerial*/
#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL
/*Communication by IIC*/
//#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
#define USE_SSERIAL
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD, PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);

测量NB-IoT的信号强度

/*!
   @file SignalDetector.ino

   @n This example detects the NB-IoT signal strength

   @Copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
   @licence     The MIT License (MIT)
   @author      [Peng kaixing](kaixing.peng@dfrobot.com)
   @version  V1.0
   @date   2019-12-18
   @get from https://www.dfrobot.com
*/

#include <DFRobot_BC20_Gravity.h>

/*7 colors are available*/
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO17       |               D16(RX)        |       D/T
   IO16       |               D17(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial1);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD, PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

/*
   The signal strength is indicated by both numerical value in dBm
   and the flashing LED:
   Strong signal - fast flash
   Medium signal - slow flash
   Weak signal - burst flash.
*/
static void NB_Signal_Fun() {

  /*Get the NB-IoT signal strength.*/
  myBC20.getSQ();

  /*Signal quality RSSI<10, WEAK signal strength*/
  myBC20.changeColor(WHITE);
  if (sSQ.rssi < 10 || sSQ.rssi == 99) {
    if (sSQ.rssi == 99) {
      Serial.println("Signal not detectable");
    } else if (sSQ.rssi == 0) {
      Serial.println("Signal Strength: -113 dBm or less");
    } else {
      Serial.print("Signal Strength: ");
      Serial.print((sSQ.rssi - 2) * 2 - 109);
      Serial.println(" dBm Weak");
    }

    //Burst flash
    myBC20.LED_ON();
    delay(100);
    myBC20.LED_OFF();
    delay(900);
  }

  /*Signal quality 10<=RSSI<25, MEDIUM signal strength*/
  else if (sSQ.rssi >= 10  && sSQ.rssi < 25) {
    Serial.print("Signal Strength: ");
    Serial.print((sSQ.rssi - 2) * 2 - 109);
    Serial.println(" dBm Medium");

    //Slow flash
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }

  /*Signal quality RSSI>=25, STRONG signal strength*/
  else if (sSQ.rssi >= 25) {
    if (sSQ.rssi < 31) {
      Serial.print("Signal Strength: ");
      Serial.print((sSQ.rssi - 2) * 2 - 109);
      Serial.println(" dBm Strong");
    } else if (sSQ.rssi == 31) {
      Serial.print("Signal Strength: -51 dBm or greater");
    }

    //Fast flash
    for (int i = 0; i < 5 ; i++) {
      myBC20.LED_ON();
      delay(100);
      myBC20.LED_OFF();
      delay(100);
    }
  }
  else {
    ;
  }
}

void setup() {
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("BC20 started successfully!");

  /*Check whether SIM card is inserted*/
  Serial.println("Checking SIM card ...");
  myBC20.changeColor(GREEN);
  while (!myBC20.checkNBCard()) {
    Serial.println("Please insert the NB SIM card !");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("SIM card check OK!");

  /*Print IMEI, ICCID and IMSI*/
  myBC20.getGSN(IMEI);
  Serial.print("BC20 IMEI: ");
  Serial.println(sGSN.imei);
  Serial.print("SIM card ICCID:");
  Serial.println(myBC20.getQCCID());
  Serial.print("SIM card IMSI: ");
  Serial.println((char *)myBC20.getIMI());

  /**
     The module will automatically attempt to connect to the network (mobile station).
     Check whether it is connected to the network.
  */
  Serial.println("Connecting network ...");
  myBC20.changeColor(BLUE);
  while (myBC20.getGATT() == 0) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("Network is connected!");
}

void loop() {
  /*Get local NB-IoT signal strength and print*/
  NB_Signal_Fun();
}

结果


校准日期与时间

/*!
   @file CalLocalTime_NB.ino

   @brief Get local date & time by NB-IoT (moblie station)

   @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
   @licence     The MIT License (MIT)
   @author      [PengKaixing](kaixing.peng@dfrobot.com)
   @date  2019-07-18
   @get from https://www.dfrobot.com
*/
#include <DFRobot_BC20_Gravity.h>

/*7 colors are available*/
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO17       |               D16(RX)        |       D/T
   IO16       |               D17(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial1);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD, PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

void getLocalTime()
{
  /* Check whether the data is legal */
  myBC20.changeColor(PURPLE);
  while (myBC20.getCLK()) {
    if (sCLK.Year > 2000) {
      break;
    }
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }

  //Date
  Serial.print((String)sCLK.Year + "/" + (String)sCLK.Month + "/" + (String)sCLK.Day + " ");
  //Time
  Serial.println((String)sCLK.Hour + ":" + (String)sCLK.Minute + ":" + (String)sCLK.Second);
}

void setup()
{
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("BC20 started successfully!");

  /*Check whether SIM card is inserted*/
  Serial.println("Checking SIM card ...");
  myBC20.changeColor(GREEN);
  while (!myBC20.checkNBCard()) {
    Serial.println("Please insert the NB SIM card !");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("SIM card check OK!");

  /*Print IMEI, ICCID and IMSI*/
  myBC20.getGSN(IMEI);
  Serial.print("BC20 IMEI: ");
  Serial.println(sGSN.imei);
  Serial.print("SIM card ICCID:");
  Serial.println(myBC20.getQCCID());
  Serial.print("SIM card IMSI: ");
  Serial.println((char *)myBC20.getIMI());

  /**
     The module will automatically attempt to connect to the network (mobile station).
     Check whether it is connected to the network.
  */
  Serial.println("Connecting network ...");
  myBC20.changeColor(BLUE);
  while (myBC20.getGATT() == 0) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("Network is connected!");
}

void loop()
{
  /*Get local date & time and print*/
  getLocalTime();
  delay(1000);
}

结果


获取物理位置坐标(精简版)

/*!
   @file getGNSS_simple.ino
   @brief Print all the GNSS info available in BC20.
   @This DEMO can be used for master control boards with small RAM space, such as UNO and leanordo
   @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
   @licence     The MIT License (MIT)
   @author      [Peng Kaixing](kaixing.peng@dfrobot.com)
   @version  V1.0
   @date  2019-10-29
   @get from https://www.dfrobot.com
*/
#include <DFRobot_BC20_Gravity.h>

/* 7 colors are available */
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO16       |               D16(RX)        |       D/T
   IO17       |               D17(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial2);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD,PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

void Display_Location_Information() {

  /*
     UTC time of the anchor point
  */
  Serial.print("Time:  ");
  Serial.print(sCLK.Hour);
  Serial.print(":");
  Serial.print(sCLK.Minute);
  Serial.print(":");
  Serial.println(sCLK.Second);

  Serial.print("Latitude:  ");
  Serial.print(sGGNS2.LatitudeVal,6);
  Serial.print(" deg ");  
  Serial.println(sGGNS2.LatitudeDir());
  Serial.print("Longitude:  ");
  Serial.print(sGGNS2.LongitudeVal,6);
  Serial.print(" deg ");  
  Serial.println(sGGNS2.LongitudeDir());
  Serial.print("Altitude:  ");  
  Serial.print(sGGNS2.Altitude);
  Serial.println(" m");  
  Serial.print("Fix Status: ");
  Serial.println(sGGNS2.Status()); 
  Serial.print("StatelliteNum: ");
  Serial.print(sGGNS2.StatelliteNum);
  Serial.println(" in Used");
  Serial.print("HDOP: ");
  Serial.println(sGGNS2.HDOP);  
  Serial.println("");
}

void setup() {
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("BC20 started successfully!");

  /* Disable sleep mode */
  myBC20.configSleepMode(eSleepMode_Disable);

  /*Power up GNSS*/
  Serial.print("Turning on GNSS ... ");
  myBC20.setQGNSSC(ON);
  myBC20.changeColor(YELLOW);
  if (myBC20.getQGNSSC() == OFF) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("GNSS is ON.");
  myBC20.changeColor(CYAN);
}

void loop() {
  myBC20.getQGNSSRD2();
  Display_Location_Information();
  myBC20.clearGPS();

  myBC20.LED_ON();
  delay(500);
  myBC20.LED_OFF();
#ifndef ARDUINO_ESP32_DEV  
  delay(500);
#else 
  delay(5000);
#endif
}

结果


获取物理位置坐标(详细版)

/*!
   @file getGNSS_detail.ino
   @brief Print all the GNSS info available in BC20.
   @This DEMO can be used for large RAM master boards like ESP32, MEGA2560.
   @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
   @licence     The MIT License (MIT)
   @author      [Peng Kaixing](kaixing.peng@dfrobot.com)
   @version  V1.0
   @date  2019-10-29
   @get from https://www.dfrobot.com
*/
#include <DFRobot_BC20_Gravity.h>

/* 7 colors are available */
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO16       |               D17(RX)        |       D/T
   IO17       |               D16(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial2);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD,PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

void Display_Location_Information() {

  /*
     UTC time of the anchor point
  */
  Serial.print("Time:\t\t");
  Serial.print(sCLK.Year);
  Serial.print("/");
  Serial.print(sCLK.Month);
  Serial.print("/");
  Serial.print(sCLK.Day);
  Serial.print("  ");
  Serial.print(sCLK.Hour);
  Serial.print(":");
  Serial.print(sCLK.Minute);
  Serial.print(":");
  Serial.println(sCLK.Second);

  Serial.print("Latitude:\t");
  Serial.print(sGGNS.LatitudeVal, 6);
  Serial.print(" deg ");
  Serial.println(sGGNS.LatitudeDir);
  Serial.print("Longitude:\t");
  Serial.print(sGGNS.LongitudeVal, 6);
  Serial.print(" deg ");
  Serial.println(sGGNS.LongitudeDir);
  Serial.print("Altitude:\t");
  Serial.print(sGGNS.Altitude, 1);
  Serial.println(" m");
  Serial.print("Speed:\t\t");
  Serial.print(sGGNS.Speed);
  Serial.println(" km/h");
  Serial.print("Heading:\t");
  Serial.print(sGGNS.Heading);
  Serial.println(" deg");
  Serial.print("Status:\t\t");
  Serial.println(sGGNS.FixStatus);
  Serial.print("PDOP:\t\t");
  Serial.println(sGGNS.PDOP);
  Serial.print("HDOP:\t\t");
  Serial.println(sGGNS.HDOP);
  Serial.print("VDOP:\t\t");
  Serial.println(sGGNS.VDOP);
  Serial.println();
}

void Display_Satellite_Information() {
  Serial.print(sSAT.NUM);
  Serial.println(" in view.");
  Serial.print(sSAT2.USE);
  Serial.println(" in used.");
  Serial.print("PRN\t");
  Serial.print("Elev(deg)\t");
  Serial.print("Azim(deg)\t");
  Serial.print("SNR(dBHz)\t");
  Serial.print("SYS\t");
  Serial.println("Used");
  for (uint8_t i = 0; i < sSAT.NUM; i++) {
    Serial.print(sSAT2.data[i].PRN);
    Serial.print("\t");
    Serial.print(sSAT2.data[i].Elev);
    Serial.print("\t\t");
    Serial.print(sSAT2.data[i].Azim);
    Serial.print("\t\t");
    Serial.print(sSAT2.data[i].SNR);
    Serial.print("\t\t");
    Serial.print(sSAT2.data[i].SYS);
    Serial.print("\t");
    Serial.println(sSAT2.data[i].Status);
  }
  Serial.println("");
}

void setup() {
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("BC20 started successfully!");

  /* Disable sleep mode */
  myBC20.configSleepMode(eSleepMode_Disable);

  /*Power up GNSS*/
  Serial.print("Turning on GNSS ... ");
  myBC20.setQGNSSC(ON);
  myBC20.changeColor(YELLOW);
  if (myBC20.getQGNSSC() == OFF) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("GNSS is ON.");
  myBC20.changeColor(CYAN);
}

void loop() {

  /**
     Is used to obtain the specified satellite information, and the parameter is used to specify the type of information to be obtained.
     The parameter is selected as follows:
  */
  myBC20.getQGNSSRD();
  Display_Location_Information();
  Display_Satellite_Information();
  myBC20.clearGPS();

  myBC20.LED_ON();
  delay(500);
  myBC20.LED_OFF();
#ifndef ARDUINO_ESP32_DEV  
  delay(500);
#else 
  delay(5000);
#endif
}

结果


串口透传调试模块

/*!
 * @file BC20_Serial.ino
 * 
 * @brief Send AT commands to the BC20 module via USB Serial.
 * 
 * @n Commonly used AT commands:
 * @n  AT - AT command test
 * @n  AT+QRST=1 - Reset BC20
 * @n  ATI - Revision of the firmware release
 * @n  AT+CSQ - Signal quality report
 * @n      0 - <=-113 dBm
 * @n      1 - -111 dBm
 * @n      2 - -109 dBm
 * @n      3 - -107 dBm
 * @n      ...
 * @n      30 - -53 dBm
 * @n      31 - >-51 dBm
 * @n     99 - Not known or not detectable
 * @n AT+CGATT? - PS attach or detach. Query network connection state.
 * @n     0 - Disconnected from the network
 * @n     1 - Connected to the network
 * @n AT+CGATT=1 - Connect to the network
 * @n AT+CGATT=0 - Disconnected from the network
 * @n AT+CIMI - Query the IMSI number of BC20
 * @n AT+CGSN=1 - Query the IMEI of the BC20.
 * @n AT+CGSN=0 - Query the SN(Serial Number) of the BC20.
 * @n AT+QCCID - USIM Card Identification(ICCID). This is usually used to check SIM card state.
 * @n AT+CCLK? - Return current date and time
 * @n AT+QPOWD=0 - Power off the module.(use "myBC20.powerOn()" to power on the module)
 *
 * @n The following AT commands are for GNSS:
 * @n AT+QGNSSC? - Query GNSS power state
 * @n     0 - GNSS power off
 * @n     1 - GNSS power on
 * @n AT+QGNSSC=1 - power on GNSS
 * @n AT+QGNSSC=0 - power off GNSS
 * @n AT+QGNSSRD? - Obtain all GNSS info
 *
 * @n For more details please refer to the "Quectel BC20 AT Commands Manual"
 * @n or the "BC20 GNSS AT Commands Manual"
 *
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author      [PengKaixing](kaixing.peng@dfrobot.com)
 * @version  V1.0
 * @date   2019-10-29
 * @get from https://www.dfrobot.com
 */

#include <DFRobot_BC20_Gravity.h>

/*7 colors are available*/
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO17       |               D16(RX)        |       D/T
   IO16       |               D17(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial1);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD, PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

void setup() {
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("BC20 started successfully!");

  /**
   * Deep Sleep Mode is automatically enable every time upon power up.
   * When this mode is entered, 
   * BC20 will not respond any AT commands from the controller
   * Disable sleep mode to ensure BC20 always responding AT commands

  myBC20.configSleepMode(eSleepMode_Disable);

  /**
   * Each AT command should begin with "AT" or "at" and end with "Carriage return".
   * The commands can be upper-case or lower-case. ex. "AT+CSQ" or "at+csq". 
  */
  Serial.println("Enter AT commands:");
}

void loop() {
  /* Serial transparent transmission with BC20. */
  if (Serial.available()) {
    myBC20.sendATCMDBychar((char)Serial.read());
  }
  if (myBC20.available()) {
    Serial.println(myBC20.readData());
  }
}

结果

8.4 样例代码(Mind+)

安装Mind+用户库


配置通信接口


测量NB-IoT的信号强度

结果

获取日期与时间

结果


获取物理位置坐标

结果


9. 掌控板使用教程

9.1 准备

9.2 连线图


9.3 样例代码(Mind+)

10. 详细说明

10.1 NB-IoT天线

NB-IoT通信和GNSS定位功能需要外接天线。用户可使用产品包装中所提供的天线,也可额外购买兼容的外接天线以进一步增强收发信号的能力或作为备用。

国内NB-IoT主要运营商与通信频段

频段 中心频率 上行频率 下行频率 运营商
B5 850 MHz 824 MHz ~ 849 MHz 869 MHz ~ 894 MHz 中国电信
B8 900MHz 880 MHz ~ 915 MHz 925 MHz ~ 960 MHz 中国移动、中国联通

10.2 GNSS天线

GNSS工作频段

定位系统 接受频段
GPS L1 C/A 1575.42 MHz
BeiDou(北斗) B1 C/A 1561.098 MHz

10.3 SIM卡

NB-IoT通信需要专用的NB-IoT物联网SIM卡,如手机SIM卡,4G物联网卡等其它类型的SIM卡无法代替。目前产品包装内包含有一张中国联通NB-IoT物联网专用SIM卡,包含一份年度基础套餐,插入NB-IoT开发板或通信模组内即可使用,若流量满足不了使用需求,可通过充值月度流量包增加当月流量。后续将会推出更多运营商的NB-IoT物联网专用SIM卡供用户选择。联通NB-IoT SIM卡资费情况如下表:

套餐 流量 有效期 资费 备注
年度基础套餐(续费,必需) 30 MB/月×12=360MB 360天 12元 1.有效期自激活之日(首次成功通信)起开始计算,共360天。
2.每30天为一个月度结算周期,每月流量不累计到下个月,超量停机,直到下个月度结算周期或充值月度流量包恢复。
3.360天到期后自动停机,续费年度基础套餐自动恢复开通。
4.有效期结束前续费年度基础套餐,下一年可不停机无缝继续使用。
月度流量包(可选) 30M/个 30天 3元 1.有效期自充值当天开始计算
2.随充随用,可无限叠加。
3.仅在年度基础套餐有效期内使用。
NB-IoT物联网专用SIM卡(补卡) 30 MB/月×12=360MB 360天 15元 1.需要联系客服核实信息方可购买,不单独销售。

注意

  • 根据国家工业和信息化部等六部门要求,为有效防范和打击通讯信息诈骗,所有NB-IoT物联网专用SIM卡均具有机卡绑定功能,不可取消
  • SIM卡插入设备,首次上电(与基站)成功通信即视为激活且与通信模组绑定(机卡绑定),开始年度计费周期(360天)
  • 2G/3G/4G手机SIM卡或大流量物联网卡无法代替用于NB-IoT设备。
  • 物联网SIM卡不能用于手机、平板、2G/3G/4G模组等非NB-IoT设备,否则会导致SIM卡停机
  • 已机卡绑定的SIM卡若被插入其它设备内进行通信会导致SIM卡停机
  • 物联网SIM卡仅能数据传输,无语音通信和短信功能
  • 用户可通过微信搜索并关注公众号“DF物联网”,自助查询SIM流量使用情况或对SIM卡进行充值。

11. 应用样例

11.1 使用DFRobot Easy-IoT测试云端通信(Arduino)

通过上面的样例完成NB-IoT信号测试,确认附近有NB-IoT信号后,接下来可测试设备与云端的通信情况。这里以DFRobot出品的轻量级Easy-IoT物联网云平台为样例进行介绍。该平台极大地简化了用户设备上云所需要的大量配置,让创客与入门开发者10分钟内实现设备与云端的连接,尤其适用于物联网通信的快速测试和简单物联网项目的搭建。下面简述测试过程




设备发送消息到云端

/*Configure device certificate information*/
char* Iot_id = "HJZv1ZFRSQ";        //填入Iot_id
char* Client_ID  = "1234";
char* Iot_pwd    = "ByfP1-YABX";    //填入Iot_pwd

/*Configure the domain name and port number*/
char* EasyIot_SERVER = "182.254.130.180";
char* PORT = "1883";

/*Set the Topic you need to publish to*/
char* pubTopic = "JoUOAg_WR";        //填入Topic
/*
   @file Publish_Topic.ino

   @brief Connect to DFRobot Easy-IoT cloud platform,
   @brief and publish data to your Topic

   @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
   @licence     The MIT License (MIT)
   @author      [PengKaixing](kaixing.peng@dfrobot.com)
   @version  V1.0
   @date  2019-10-29
   @get from https://www.dfrobot.com
*/

#include <DFRobot_BC20_Gravity.h>

/*7 colors are available*/
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Configure device certificate information*/
char* Iot_id = "HJZv1ZFRSQ";        //填入Iot_id
char* Client_ID  = "1234";
char* Iot_pwd    = "ByfP1-YABX";    //填入Iot_pwd

/*Configure the domain name and port number*/
char* EasyIot_SERVER = "182.254.130.180";
char* PORT = "1883";

/*Set the Topic you need to publish to*/
char* pubTopic = "JoUOAg_WR";        //填入Topic

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO17       |               D16(RX)        |       D/T
   IO16       |               D17(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial1);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD, PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

void ConnectCloud() {
  Serial.print("Attempting MQTT connection...");
  myBC20.changeColor(YELLOW);
  while (!myBC20.connected()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);

    if (myBC20.connect(Client_ID, Iot_id, Iot_pwd)) {
      Serial.println("\nConnect Server OK");
    } else {
      /**
         Used to detect the connection between the device and the server
      */
      if (myBC20.getQMTCONN())
        break;
    }
  }
}

void setup() {
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("BC20 started successfully!");

  /*Check whether SIM card is inserted*/
  Serial.println("Checking SIM card ...");
  myBC20.changeColor(GREEN);
  while (!myBC20.checkNBCard()) {
    Serial.println("Please insert the NB SIM card !");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("SIM card check OK!");

  /*Print IMEI, ICCID and IMSI*/
  myBC20.getGSN(IMEI);
  Serial.print("BC20 IMEI: ");
  Serial.println(sGSN.imei);
  Serial.print("SIM card ICCID:");
  Serial.println(myBC20.getQCCID());
  Serial.print("SIM card IMSI: ");
  Serial.println((char *)myBC20.getIMI());

  /**
     The module will automatically attempt to connect to the network (mobile station).
     Check whether it is connected to the network.
  */
  Serial.println("Connecting network ...");
  myBC20.changeColor(BLUE);
  while (myBC20.getGATT() == 0) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("Network is connected!");

  Serial.println("Connecting to DFRobot Easy-IoT");

  //Configure IoT Server
  myBC20.setServer(EasyIot_SERVER, PORT);
  Serial.println("Server is available!");
  ConnectCloud();
}

void loop() {
  delay(5000);
  Serial.println("send message to cloud...");
  myBC20.publish(pubTopic, "hello");
  Serial.println("Message is sent.");
}

结果




云端发送消息到设备

/*Configure device certificate information*/
char* Iot_id = "HJZv1ZFRSQ";        //填入Iot_id
char* Client_ID  = "1234";
char* Iot_pwd    = "ByfP1-YABX";    //填入Iot_pwd

/*Configure the domain name and port number*/
char* EasyIot_SERVER = "182.254.130.180";
char* PORT = "1883";

/*Set the Topic you need to publish to*/
char* pubTopic = "JoUOAg_WR";        //填入Topic
/*!
   @file Subscribe_Topic.ino

   @brief Connect to DFRobot Easy IoT cloud platform,
   @brief and subscribe your Topic

   @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
   @licence     The MIT License (MIT)
   @author      [PengKaixing](kaixing.peng@dfrobot.com)
   @version  V1.0
   @date  2019-10-29
   @get from https://www.dfrobot.com
*/
#include <DFRobot_BC20_Gravity.h>

/*7 colors are available*/
#define  RED 0
#define  BLUE 1
#define  GREEN 2
#define  YELLOW 3
#define  PURPLE 4
#define  CYAN 5
#define  WHITE 6

/*Configure device certificate information*/
char* Iot_id = "HJZv1ZFRSQ";        //填入Iot_id
char* Client_ID  = "1234";
char* Iot_pwd    = "ByfP1-YABX";    //填入Iot_pwd

/*Configure the domain name and port number*/
char* EasyIot_SERVER = "182.254.130.180";
char* PORT = "1883";

/*Set the Topic you need to publish to*/
char* pubTopic = "JoUOAg_WR";        //填入Topic

/*Communication by IIC*/
#define USE_IIC

/*Communication by HardwareSerial*/
//#define USE_HSERIAL

/*Communication by SoftwareSerial*/
//#define USE_SSERIAL


/******************IIC******************/
#ifdef USE_IIC
/*
   For general controllers. Communicate by IIC
   Connect Instructions
      Controller     |    Module(BC20)
          SDA        |       D/T
          SCL        |       C/R
          GND        |       GND
       5V or 3V3     |       VCC

   IIC address(A0,A1)
     0x30:(A0=0,A1=0)
     0x31:(A0=0,A1=1)
     0x32:(A0=1,A1=0)
     0x33:(A0=1,A1=1) default
*/
DFRobot_BC20_IIC myBC20(0x33);

/******************HardwareSerial******************/
#elif defined(USE_HSERIAL)
/*
   For MEGA2560/ESP32 HardwareSerial
   Connect Instructions
   esp32      |               MEGA Series    |    Module(BC20)
   IO16       |               D17(RX)        |       D/T
   IO17       |               D16(TX)        |       C/R
   GND        |               GND            |       GND
   5V(USB) or 3V3(battery)  | 5V or 3V3      |       VCC
*/
#if defined(ARDUINO_ESP32_DEV)
HardwareSerial Serial2(2);
DFRobot_BC20_Serial myBC20(&Serial2);//ESP32HardwareSerial
#else
DFRobot_BC20_Serial myBC20(&Serial2);//others
#endif

/******************SoftwareSerial******************/
#elif defined(USE_SSERIAL)
/*
    For Arduino Series SoftwareSerial
    Connect Instructions
        UNO     |    Module(BC20)
      PIN_RXD   |       D/T
      PIN_TXD   |       C/R
        GND     |       GND
     5V or 3V3  |       VCC
*/
#define PIN_TXD   3
#define PIN_RXD   4
SoftwareSerial ss(PIN_RXD,PIN_TXD);
DFRobot_BC20_SW_Serial myBC20(&ss);
#endif

/*
  Callback function.
  This will be called when message is received from the subscribed topic.
*/
void callback(char * topic, uint8_t * payload, unsigned int len) {
  Serial.print("Recevice [Topic:");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < len; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  //Control onboard RGB LED according to received message.
  String receivedData = payload;
  if (receivedData.equals("OFF") == true) {
    myBC20.LED_OFF();
    //    Serial.println("LED is OFF.");
  }
  else if (receivedData.equals("RED") == true) {
    myBC20.changeColor(RED);
    myBC20.LED_ON();
    //    Serial.println("LED is red.");
  }
  else if (receivedData.equals("GREEN") == true) {
    myBC20.changeColor(GREEN);
    myBC20.LED_ON();
    //      Serial.println("LED is green.");
  }
  else if (receivedData.equals("BLUE") == true) {
    myBC20.changeColor(BLUE);
    myBC20.LED_ON();
    //      Serial.println("LED is blue.");
  }
  else if (receivedData.equals("YELLOW") == true) {
    myBC20.changeColor(YELLOW);
    myBC20.LED_ON();
    //      Serial.println("LED is yellow.");
  }
  else if (receivedData.equals("PURPLE") == true) {
    myBC20.changeColor(PURPLE);
    myBC20.LED_ON();
    //      Serial.println("LED is purple.");
  }
  else if (receivedData.equals("CYAN") == true) {
    myBC20.changeColor(CYAN);
    myBC20.LED_ON();
    //      Serial.println("LED is cyan.");
  }
  else if (receivedData.equals("WHITE") == true) {
    myBC20.changeColor(WHITE);
    myBC20.LED_ON();
    //      Serial.println("LED is white.");
  }
  else {
    ;
  }
}

void ConnectCloud() {
  Serial.print("Attempting MQTT connection...");
  while (!myBC20.connected()) {
    Serial.print(".");
    if (myBC20.connect(Client_ID, Iot_id, Iot_pwd)) {
      Serial.println("\nConnect Server OK");
    } else {
      /**
         Used to detect the connection between the device and the server
      */
      if (myBC20.getQMTCONN())
        break;
    }
  }

  while (!myBC20.subTopic('0', '1', subTopic, '0')) {
    Serial.print(".");
  }
  Serial.print("\nTopic:");
  Serial.print(subTopic);
  Serial.println(" subscribed!");
}

void setup() {
  Serial.begin(115200);
  myBC20.LED_OFF();

  /*Initialize BC20*/
  Serial.print("Starting the BC20.Please wait. . . ");
  myBC20.changeColor(RED);
  while (!myBC20.powerOn()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("started successfully!");

  /*Check whether SIM card is inserted*/
  Serial.print("Checking SIM card ...");
  myBC20.changeColor(GREEN);
  while (!myBC20.checkNBCard()) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("OK!");

  //Disable sleep mode
  myBC20.configSleepMode(eSleepMode_Disable);
  //Disable PSM
  myBC20.setPSMMode(ePSM_OFF);

  /**
     The module will automatically attempt to connect to the network (mobile station).
     Check whether it is connected to the network.
  */
  Serial.print("Connecting network ...");
  myBC20.changeColor(BLUE);
  while (myBC20.getGATT() == 0) {
    Serial.print(".");
    myBC20.LED_ON();
    delay(500);
    myBC20.LED_OFF();
    delay(500);
  }
  Serial.println("connected!");

  //Set callback function
  myBC20.setCallback(callback);

  Serial.println("Connecting to DFRobot Easy-IoT");

  //Configure IoT Server
  myBC20.setServer(EasyIot_SERVER, PORT);
  Serial.println("Server is available!");

  //Conect to DFRobot Easy-IoT
  ConnectCloud();

}

void loop() {
  myBC20.loop();
}

结果





至此,通过上述两个样例,完成了通信模块(设备端)与Easy-IoT云平台(云端)的双向通信测试。

11.2 使用DFRobot Easy-IoT测试云端通信(Mind+)

通过上面的样例完成NB-IoT信号测试,确认附近有NB-IoT信号后,接下来可测试设备与云端的通信情况。这里以DFRobot出品的轻量级Easy-IoT物联网云平台为样例进行介绍。该平台极大地简化了用户设备上云所需要的大量配置,让创客与入门开发者10分钟内实现设备与云端的连接,尤其适用于物联网通信的快速测试和简单物联网项目的搭建。下面简述测试过程




设备发送消息到云端

注意

结果




云端发送消息到设备

结果





至此,通过上述两个样例,完成了通信模块(设备端)与Easy-IoT云平台(云端)的双向通信测试。

12. 常见问题

Q:uno接bc20,云端通讯为什么串口监视器打印的信息卡在connecting network........?
A:检查天线是否连接。微信公众号DF物联网查看卡的状态。如果同时使用两个库,uno内存可能不够,建议用mega2560,代码同样兼容。

Q:用了发送数据到iot平台的程序之后gnss定位数据就接收不到了?
A:检查上传程序时提示的内存是否不足。

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。

13. 更多

DFshopping_car1.png DFRobot商城购买链接