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 Quectel's Mini PCle EVB kit.
Requirements
An active Ubidots account.
A serial terminal utility.
APN configuration information from your mobile network provider.
Understanding how to send data through our HTTP(S) data API.
1. Setup Serial Communication
First of all, make sure the BG96 module is attached to the evaluation board kit, then you can proceed to power the module by connecting it to the PC using the USB Mini cable and then setting the switch to the "On" position. The following picture serves as a guide.
Now in order to establish the serial communication with the PC, you must use the RS232 to USB converter cable which is included with the evaluation kit, proceed to connect it to the PC.
If you are wondering, up to this point there are two connections to the PC from the evaluation kit board: the power supply through the USB Mini cable and the serial communication going through the RS-232 to USB converter cable.
In order to test the serial communication you will need a serial terminal utility. In this guide, Arduino's serial terminal was used, however you can pick any that you feel comfortable with.
If you decided to use Arduino's serial terminal, you'll need to select the serial device with which you want to talk, to do that, open your Arduino IDE and head to "Tools" ---> "Port", then select your serial device:
Pro Tip: On Linux based systems, your device should be labeled something like "/dev/ttyUSB0" while on Windows OS the device should be labeled something like "COM1"
After selecting your serial device, start the serial terminal by clicking on "Serial Monitor" as shown above. The following GUI will be displayed, there be sure to set the baud rate at 115200 as well as setting the "Both NL & CR" option from the bottom of the window as depicted below:
Now you should check if there is communication between the PC and the BG95/BG96 module. To do so, type in the text field the following command and hit the "Send" button:
ATI
This AT command displays the device's manufacturer information. The device shall respond something like:
2. Save the certificate
For the purpose of keeping 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.
In order to save the root certificate to the device's storage media, send the following AT command:
AT+QFUPL="UBIDOTS.PEM",3139,10
After doing so, you will receive a "CONNECT" as a response, then send the following raw text as if you did for all of the other commands sent previously.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A1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw 7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ -----END CERTIFICATE-----
The following GIF depicts the whole process:
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 "<APN>" , "<username>", "<password>", "<authentication>" with your carrier settings (keeping the double quotes)
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>
Example: For this guide, the following parameters are used:
APN: web.vmc.net.co
Username: Virgin Mobile
Then the above AT command should be something like the following:
AT+QICSGP=1,3,"web.vmc.net.co","Virgin Mobile","",0
Send this command and wait for its confirmation response.
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.