Table of Contents:

1. The use of this guideline

This configure instruction is for Dragino NB-IoT models with -NB or -NS suffix, for example DDS75-NB. These models use the same NB-IoT Module BC660K-GL and has the same software structure. The have the same configure instruction to different IoT servers. Use can follow the instruction here to see how to configure to connect to those servers.

2. Network Connection

The -NB and -NS models support LTE Cat NB2, with below frequency band: multiple frequency bands of B1/B2/B3/B4/B5/B8/B12/B13/B14/B17/B18/B19/B20/B25/B28/B66/B70/B85 . Make sure you use a the NB-IoT SIM card.

SIM ProviderAPNNB-IoT CoverageComments
1NCE   
China Mobile   

2.1 1NCE SIM Card.

3. Configure to connect to different servers

3.1 General UDP Connection

The NB-IoT Sensor can send packet to server use UDP protocol. 

3.1.1 Simulate UDP Connection by PC tool

We can use PC tool to simulate UDP connection to make sure server works ok. 

image-20230802112413-1.png

3.1.2 Configure NB-IoT Sensor

3.1.2.1 AT Commands

AT Commands:

  • AT+PRO=2,0         //  Set to use UDP protocol to uplink ,Payload Type select Hex payload
  • AT+SERVADDR=120.24.4.116,5601      //  Set UDP server address and port
  • AT+CFM=1          //  If the server does not respond, this command is unnecessary

image-20230802112413-2.png

3.1.2.2 Uplink Example

image-20230802112413-3.png

3.2 General MQTT Connection

The NB-IoT Sensor can send packet to server use MQTT protocol. 

Below are the commands.

AT Commands:

  • AT+PRO=3,0      //  Set to use MQTT protocol to uplink, Payload Type select Hex payload.
  • AT+SERVADDR=120.24.4.116,1883        //  Set MQTT server address and port
  • AT+CLIENT=CLIENT                                 //  Set up the CLIENT of MQTT
  • AT+UNAME=UNAME                              //  Set the username of MQTT
  • AT+PWD=PWD                                        //  Set the password of MQTT
  • AT+PUBTOPIC=NSE01_PUB                    //  Set the sending topic of MQTT
  • AT+SUBTOPIC=NSE01_SUB                    //  Set the subscription topic of MQTT

image-20230802112413-4.png

image-20230802112413-5.png

Notice: MQTT protocol has a much higher power consumption compare with UDP/CoAP protocol. Please check the power analyze document and adjust the uplink  period to a suitable interval.

3.3 ThingSpeak (via MQTT)

3.3.1 Get MQTT Credentials

ThingSpeak connection uses MQTT Connection. So we need to get MQTT Credentials first. You need to point MQTT Devices to ThingSpeak Channel as well. 

image-20230802112413-6.png

image-20230802112413-7.png

3.3.2 Simulate with MQTT.fx

3.3.2.1 Establish MQTT Connection

After we got MQTT Credentials, we can first simulate with PC tool MQTT.fx tool to see if the Credentials and settings are fine. 

image-20230802112413-8.png

  • Broker Address: mqtt3.thingspeak.com
  • Broker Port: 1883
  • Client ID: <Your ThingSpeak MQTT ClientID>
  • User Name: <Your ThingSpeak MQTT User Name>
  • Password: <Your ThingSpeak MQTT Password>

3.3.2.2 Publish Data to ThingSpeak Channel

image-20230802112413-9.png

image-20230802112413-10.png

In MQTT.fx, we can publish below info:

  • Topic: channels/YOUR_CHANNEL_ID/publish
  • Payload: field1=63&field2=67&status=MQTTPUBLISH 

Where 63 and 67 are the value to be published to field1 & field2. 

Result: 

image-20230802112413-11.png

3.3.3 Configure NB-IoT Sensor for connection

3.3.3.1 AT Commands:

In the NB-IoT, we can run below commands so to publish the channels like MQTT.fx

  • AT+PRO=3,1     // Set to use ThingSpeak Server and Related Payload
  • AT+CLIENT=<Your ThingSpeak MQTT ClientID>
  • AT+UNAME=<Your ThingSpeak MQTT User Name>
  • AT+PWD=<Your ThingSpeak MQTT Password>
  • AT+PUBTOPIC=<YOUR_CHANNEL_ID>
  • AT+SUBTOPIC=<YOUR_CHANNEL_ID>

3.3.3.2 Uplink Examples

For S31-NB

For SE01-NB

For DDS20-NB

For DDS45-NB

For DDS75-NB

For NMDS120-NB

For SPH01-NB

For NLM01-NB

For NMDS200-NB

For CPN01-NB

For DS03A-NB

For SN50V3-NB

3.3.3.3 Map fields to sensor value

When NB-IoT sensor upload to ThingSpeak. The payload already specify which fileds related to which sensor value. Use need to create fileds in Channels Settings. with name so to see the value correctly. 

image-20230802112413-12.png

image-20230802112413-13.png

Below is the NB-IoT Product Table show the mapping. 

 Field1Field2Field3Field4Field5Field6Field7Field8Field9Field10
S31x-NBTemperature HumidityBatteryRSSI      
SE01-NBTemperature Humidityconductdielectric_constantBatteryRSSI    
DDS20-NBdistanceBatteryRSSI       
DDS45-NBdistanceBatteryRSSI       
DDS75-NBdistanceBatteryRSSI       
NMDS120-NBdistanceBatteryRSSI       
SPH01-NBphTemperatureBatteryRSSI      
NLM01-NBHumidityTemperatureBatteryRSSI      
NMDS200-NBdistance1distance2BatteryRSSI      
CPN01-NBalarmcountdoor open durationcalc flagBatteryRSSI    
DS03A-NBlevelalarmpb14door open numpb14 last open timepb15 level statuspb15 alarm statuspb15 door open numpb15 last open timeBatteryRSSI
SN50V3-NB          
mod1modBatteryRSSIDS18B20 Tempexit_state/input PA4adc0Temperature Humidity  
mod2modBatteryRSSIDS18B20 Tempexit_state/input PA4adc0distance   
mod3modBatteryRSSIadc0exit_state/input PA4adc1TemperatureHumidityadc4 
mod4modBatteryRSSIDS18B20 Tempadc0exit_state/input PA4DS18B20 Temp2DS18B20 Temp3  
mod5modBatteryRSSIDS18B20 Tempadc0exit_state/input PA4Weight   
mod6modBatteryRSSIcount      

3.4 Datacake

3.4.1 Define Product

Firstly, we need to set the MQTT mode to datacake, and we need to run AT+PRO=3,2. This command is set to datacake. After running the command, the device automatically sets the server address, port.

By chosing to add the device under a "New Product" you are required to give a name for this product. You can name it something like "My First MQTT Product".

image-20230802112413-14.png

3.4.2 Create Device

In the second step you have to define the device which should be added to the product. 

image-20230802112413-15.png

Enter a name here (such as "My First MQTT Device") and complete the creation of the device by clicking on the "Next" button.

3.4.3 Create Database Fields

After creating the device, it is listed in the table of the fleet view. Now open the device by clicking on the entry in the list.

You will then see a device view with an empty dashboard. Now, the first thing we want to do is navigate to the Device configuration. To do this, use the tab bar and click on "Configuration".

image-20230802112413-16.png

image-20230802112413-17.png

To create a first database field, please click on the "Add Field" button as marked in the screenshot above.

This will open another modal asking for some required input for your first field.

image-20230802112413-18.png

image-20230802112413-19.png

3.4.4 Set up Broker

The broker is running on mqtt.datacake.co on ports 1883 and 8883. Port 1883 is unsecured and should not be used in production environments. Port 8883 uses a CA signed server certificate.

You will need an access token to log into the Datacake MQTT Broker. You can use your own personal token or create a token explicitly for individual devices or groups of devices.

View your Personal Access Token

You can view your own token via the User-Settings-Menu. You can reach this menu by clicking on "Edit Profile" at the end of the list using the Workspace Selector:

image-20230802112413-20.png

MQTT Client-ID

The Datacake Broker manages the client IDs internally. You do not need to worry about a client ID. If your client optionally supports the specification of a client ID, please leave this 
specification blank. Your client then creates a randomly generated ID. 

  • AT+CLIENT=“Any value”
  • AT+UNAME=Token
  • AT+PWD=Token

image-20230802112413-21.png

3.4.5 Create your first Subscription

Subscribe

Data is published according to the following structure: dtck/// 

Subscribe to topics using this structure to receive messages via MQTT when readings (via API or MQTT) arrive in the Datacake Cloud. Messages are published whenever there is a change to a corresponding database field.

image-20230802112413-22.png

image-20230802112413-23.png

image-20230802112413-24.png

example:

AT+PUBTOPIC=dtck-pub/nbmattest/936c0db6-e9a5-4353-9fdb-3f63c8bfce7e/Temperature

image-20230802112413-25.png

3.4.6 Define Publish Topic

Publish

To upload data into the Datacake Cloud and into a specific device, you publish the data to the respective topic structure.

Due to the nature of MQTT, the topic prefix differs as follows: dtck-pub///

example:

AT+SUBTOPIC=dtck/nbmattest/936c0db6-e9a5-4353-9fdb-3f63c8bfce7e/Temperature

3.4.7 upload data

image-20230802112413-26.png

image-20230802112413-27.png

image-20230802112413-28.png

3.5 Node-Red (via MQTT)

3.5.1 Configure Node-Red

image-20230802112413-29.png

image-20230802112413-30.png

3.5.2 Simulate Connection

image-20230802112413-31.png

3.5.3 Configure NB-IoT Sensors

  • AT+PRO=3,0(hex format) or 3,5(json format)    //  Set to mqtt Server and  Payload
  • AT+CLIENT=any value
  • AT+UNAME=any value
  • AT+PWD=any value
  • AT+PUBTOPIC=any value
  • AT+SUBTOPIC=any value

3.6 ThingsBoard.Cloud (via MQTT)

3.6.1 Configure ThingsBoard

3.6.1.1 Create Device

Create a New Device in ThingsBoard

image-20230802112413-32.png

3.6.1.2 Create Uplink & Downlink Converter

Uplink Converter

The purpose of the decoder function is to parse the incoming data and metadata to a format that ThingsBoard can consume. deviceName and deviceType are required, while attributes and telemetry are optional. Attributes and telemetry are flat key-value objects. Nested objects are not supported.

To create an uplink converter go to the Integrations center -> Data converters page and click “plus” button. Name it “MQTT Uplink Converter” and select type "Uplink". Use debug mode for now.

image-20230802112413-33.png

Downlink Converter

The Downlink converter transforming outgoing RPC message and then the Integration sends it to external MQTT broke

image-20230802112413-34.png

Note:Our device payload is already human readable data. Therefore, users do not need to write decoders. Simply create by default.

3.6.1.3 MQTT Integration Setup

Go to the Integrations center -> Integrations page and click plus icon to add a new integration. Name it “MQTT Integration”, select type MQTT;

image-20230802112413-35.png

  • The next steps is to add the recently created uplink and downlink converters;

image-20230802112413-36.png

image-20230802112413-37.png

Add a topic filter:

tb/mqtt-integration-tutorial/sensors//temperature --> Temperature  固定的? 对的。

You can also select an MQTT QoS level. We use MQTT QoS level 0 (At most once) by default;

image-20230802112413-38.png

3.6.2 Simulate with MQTT.fx

image-20230802112413-39.png

image-20230802112413-40.png

3.6.3 Configure NB-IoT Sensor

AT Commands

  • AT+PRO=3,3    // Use MQTT to connect to ThingsBoard.
  • AT+SUBTOPIC=device name    --> 只需要 Device Name 吗?对的
  • AT+PUBTOPIC=device name   --> 只需要 Device Name 吗?对的

Users do not need to fill in the client, username, and password. But the configuration information of the device requires setting the client, username, and password, which can be entered freely. (软件自动填充为 Device Name 吧).这边不用提示了,客户不需要输入。(大部分客户还是会自己去设置这个的,提高安全性)

CLIENT :“Any value”

User Name:“Any value”

Password:“Any value”

Test Uplink by click the button for 1 second

image-20230802112413-41.png

image-20230802112413-42.png

image-20230802112413-43.png

3.7 Tago.io (via MQTT)

3.7.1 Create device & Get Credentials

We use MQTT Connection to send data to Tago.io. We need to Create Device and Get MQTT Credentials first. 

image-20230802112413-44.png

image-20230802112413-45.png

Go to the Device section and create a device. Then, go to the section tokens and copy your device-token.

image-20230802112413-46.png

On the Connection Profile window, set the following information: (这边加一个截图)

  • Profile Name: “Any name”
  • Broker Address: mqtt.tago.io
  • Broker Port: 1883
  • Client ID: “Any value”

On the section User credentials, set the following information: (这边加一个截图)

  • User Name: “Any value”   //  Tago validates your user by the token only
  • Password: “Your device token”
  • PUBTOPIC: “Any value”
  • SUBTOPIC: “Any value”

3.7.2 Simulate with MQTT.fx

image-20230802112413-47.png

image-20230802112413-48.png

Users can run the AT+PRO=3,5 command, and the payload will be converted to JSON format.

image-20230802112413-49.png

3.7.3 tago data

image-20230802112413-50.png

image-20230802112413-51.png

3.7.4 TLS mode

Users can choose to use SSL/TLS mode.

On the SSL/TLS section, check the option Enable SSL/TLS, and click OK.

The device needs to enable the TLS mode and set the AT+TLSMOD=1,0 command.

  • Profile Name: “Any name”
  • Broker Address: mqtt.tago.io
  • Broker Port: 8883
  • Client ID: “Any value”
  • User Name: “Any value”       // Tago validates your user by the token only
  • Password: “Your device token”
  • PUBTOPIC: “Any value”
  • SUBTOPIC: “Any value”

image-20230802112413-52.png

 

Tags:
Created by Edwin Chen on 2023/07/21 12:31
    
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0