The BG95 belongs to a series of LTE Cat M1/Cat NB2/EGPRS modules and the BG96 is an LTE Cat M1/Cat NB1/EGPRS module, both of which support a wide set of internet protocols and industry-standard interfaces like USB/UART/I2C that make them suitable for a large number of IoT applications.
In this tutorial, we will show the steps and AT commands list needed to send data to Ubidots using BG95/BG96 modules.
Note: Before starting, make sure you can send AT commands to the device and receive the response. To make a simple test, try sending the ATI command and verify the product information is successfully received as the response. e.g.:
ATI
Quectel
BG96
Revision: BG96MAR02A07M1G
OK
Requirements
An active Ubidots account.
A BG95/BG96-based device.
APN configuration information from your mobile network provider.
Understanding how to send data through our HTTP(S) data API.
Table of contents
1. Save the certificate
In order to keep your data safe and private, HTTPS will be used to send data to Ubidots, and to be a little bit safer, the device will verify that in effect it is connecting to Ubidots. To achieve that, the Ubidots root PEM certificate will be saved in the device's non-volatile storage. This is a one-time step and can be done at the production stage.
First, download the root certificate and save it into a know location, then send the file with the AT command:
AT+QFUPL="UBIDOTS.PEM",3139,10
After receiving CONNECT
as a response, transfer the raw file. You should receive an OK
if the transfer succeeds.
2. Setup mobile connection
Before an HTTPS request can be done, mobile data connection must be set up. For this, APN configuration information from your mobile network provider is needed. You must provide the following:
Access point name (APN)
Username if required
Password if required
Authentication method:
0: None
1: PAP
2: CHAP
3: PAP or CHAP
With the information above, build the following AT command replacing the corresponding values:
AT+QICSGP=1,3,"<APN>","<username>","<password>",<authentication>
For authentication
use the corresponding number listed above. If username
and/or password
is not required, leave its corresponding field empty. e.g.:
AT+QICSGP=1,3,"<APN>","","",<authentication>
Wait for the OK
response, then activate the connection by sending:
AT+QIACT=1
This may take a while and if successful, OK
is received as a response. After that, you can check the IP address with the AT command:
AT+QIACT?
3. Setup HTTP(S) parameters
Send the following AT commands to configure HTTP(S) connection to Ubidots server:
AT+QHTTPCFG="contextid",1
AT+QHTTPCFG="requestheader",1
AT+QHTTPCFG="sslctxid",1
AT+QSSLCFG="sslversion",1,3
AT+QSSLCFG="ciphersuite",1,0xFFFF
AT+QSSLCFG="seclevel",1,1
AT+QSSLCFG="cacert",1,"UBIDOTS.PEM"
Remember to wait for the OK
response after each command before sending the next.
4. Send data
Build the URL according to our data API. e.g:
https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/
Remember to replace <device_label
accordingly and get the final URL length.
Setup the URL for the request with the following AT command:
AT+QHTTPURL=<URL_length>,60
After receiving CONNECT
response send the URL, then wait for OK
to be received.
Example:
AT+QHTTPURL=57,60
CONNECT
https://industrial.api.ubidots.com/api/v1.6/devices/bg96/
OK
Build the HTTP(S) request data as follows:
POST /api/v1.6/devices/<device_label>/ HTTP/1.1
Host: industrial.api.ubidots.com
User-Agent: QUECTEL_BG96
Accept: */*
X-Auth-Token: <Ubidots_token>
Content-Type: application/json
Content-Length: <JSON_string_length>
<JSON_string>
Replace the fields marked with <>
accordingly and get the final length of the request data. Take into account that line endings for an HTTP(S) request are CRLF.
Send request data:
AT+QHTTPPOST=<data_length>,60,60
Wait for the CONNECT
response and then send the request data. After receiving OK
you can get the server response with:
AT+QHTTPREAD=60
Example:
AT+QHTTPPOST=231,60,60
CONNECT
POST /api/v1.6/devices/bg96/ HTTP/1.1
Host: industrial.api.ubidots.com
User-Agent: QUECTEL_BG96
Accept: */*
X-Auth-Token: XXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
Content-Length: 12
{"my-var":1}
OK
+QHTTPPOST: 0,200
AT+QHTTPREAD=60
CONNECT
{"my-var":[{"status_code":201}]}
OK
+QHTTPREAD: 0
5. Feedback and suggestions
Feel free to post questions or suggestions in our community portal, or drop us a line at support@ubidots.com.