The STM32 Discovery pack (P-L496G-CELL01) is an STM32L496AG I6-based low-power Discovery mother board and an STMod+ Cellular 2G/3G worldwide expansion board with antenna. Following this guide you will be able to program the P-L496G-CELL01 Discovery Pack to connect with Ubidots.
- STM32 Discovery Pack for 2G/3G Cellular to Cloud
- [OPTIONAL] X-NUCLEO-IKS01A1
- Espruino Web IDE
- Ubidots account
- Active SIM card with data plan
- Getting Started
- Firmware Setup
– Espruino Web IDE Setup & Firmware Load
- Handling Data with Ubidots
IMPORTANT NOTE: Reference the official documentation for a detailed technical review of the P-L496G-CELL01 device.
1. Insert an activated SIM card into the cellular add-on board.
NOTE: To avoid future connectivity issues we recommend verifing if the SIM card inserted is already unlocked in the region where it will be operating.
2. Plug the cellular add-on board into the STMod+'s connector of the STM32 Discovery Base Board, as shown below:
3. Check the jumper default positions:
- JP3 on IDD
- JP3 ARD_V5_IN
- JP4 and JP5 on 3.3V
- JP6 on 1-2 position
- JP7 on STLK
- JP8 closed
- JP9 opened
4. Connect the STM32 Discovery base board to a PC using CN5(STLink) USB connector (also to power the board). The LEDs LD5 (PWR) and LD8 (COM) should be illuminated.
5. Add the STM32 cellular Discovery Pack to the STM32 dashboard using the following steps:
- Open any terminal emulator (communications) program based on the OS of the PC used to establish the serial communication with the STM32 Discovery Pack. Programs like TeraTerm & Cutecom.
- Establish the communication with the board choosing the right USB COM port and configured to 9600 bps, 8, N, 1.
- Follow the steps shown in the terminal to add the board to the STM32 Dashboard.
NOTE: If you are working with Windows make sure the ST Link USB drivers are installed on the PC.
1. Once the board is added to the STM32 Dashboard, scroll down until you find "Precompiled Demos Repositories"
2. Then find "Cellular to Ubidots Cloud Demos" and download the .zip file pressing the respective download button.
3. Once the .zip file is downloaded, unzipped and confirm the file contains and is similar to that of the below image:
NOTE: This guide is going to provided all the steps required to integrate the board with Ubidots. To avoid errors, it is advisable to read and become familiar with "What these JS file do" and "readme-CellularToUbidotsCloud." which are included in the zip file that is downloaded when you press the "Precompiled Demos Repositories".
4. To avoid issues with the firewall, the *.JS file in this zip have been renamed as *_JS.txt. Please rename them back to the .js extension before using them with Espruino JS Engine.
The examples provided in the folder is:
ubidots_MQTT_w_sensors_JS.txt (rename as ubidots_MQTT_w_sensors.js) : This is a demo where a value can be reported and mapped to a resource in the Cloud. The same resource can be read from the Cloud.
Further, subscription and callback can be registered when cloud updates the resource. If the environmental sensors board is connected, user can launch periodical report of their values to his profile.
ubidots_REST_w_sensors_JS.txt (rename as ubidots_REST_w_sensors.js) : This is a demo where a value can be reported and mapped to a resource in the Cloud. The same resource can be read from the Cloud.
If the environmental sensors board is connected, user can launch periodical report of their values to his profile.
Espruino Web IDE Setup & Firmware Load
1. Download or open the Espruino Web IDE if you already don't have it.
2. Download the up-to-date Espruino firmware for the STM32L496 provided here. The downloaded file should be titled:
1v97.35 is the latest version (as of this articles publication), but can be more recent.
3. Load the bin file previously downloaded into the STM32L496 Discovery Pack. To load the firmware, follow the next steps:
- Connect the PC to the board's ST Link USB connector (USB STLINK CN5)
- Open Windows File Explorer and make sure the discovery board is present as a drive with volume name "DIS_L496ZG".
- Get the BIN file previously downloaded and drag and drop it on to the volume name.
- The ST Link LED (LD5) should alternate between red and green color until programming is complete
4. Once the firmware is updated properly into the board. Open the Espruino Web IDE and assign a SandBox if you don't already have it. To select the folder SandBox go to Settings > Project and assign the folder desired.
Once the folder is assigned, the folders required are going to be a automatically generated, as shown below:
The SandBox is in charge of handling and loading all the requirements of the program, such as modules, firmwares, binary files, etc.
5. Connect the STM32L496 Discovery to the Espruino Web IDE. To connect the board, press the connection icon located in the upper right part of the IDE:
The board PORT will automatically be detected in the Espruino Web IDE, so select the correct one assigned or that you are working with:
Wait a couple of seconds until the board is connected properly:
6. Open the files meant to be loaded. To open the file, select the folder icon and choose one of the two script provided:
7. Update the the first part of both .js files
- Cellular Network Parameters (APN, USERNAME, PASSWORD)
- Ubidots Account credentials (Ubidots TOKEN)
- Ubidots Sever based on your Ubidots subscription
Ubidots for Educational - things.ubidots.com
Ubidots for Business - industrial.api.ubidots.com
PRO TIP: Also, in order to debug the behavior of the cellular connection, we highly recommend you set the debug to true. For this, you have to modify the following line at the ending of the code (ubidots_MQTT_w_sensors.js or ubidots_REST_w_sensors.js)
// start the modem and connection
// start the modem and connection
8. With the parameters updated, send the code to the Espruino by pressing the send icon pictured below:
This process is going to take a couple of minutes so please be patient.
9. Once the code is properly sent, you should start presenting the behavior below at the debug console of the Espruino Web IDE:
When complete you will find the response lines: "Good luck with Ubidots cloud!" at the bottom of of the connection process. Once an IP address is allocated, your "modem is ready to use."
Now it's time to start your App Development with Ubidots!
Handling Data with Ubidots
If you didn't notice, the first debug messages provided the initialization commands to handle data with Ubidots.
IMPORTANT NOTE: The .js files provided (MQTT and REST) have different initialization commands, so please make sure to use the commands provided based on your file. FYI, the file used in this tutorial is the ubidots_MQTT_w_sensors.js
1. When you get an IP address, install your device and activate the connection token using the following command:
dev = ubidotsMQTT(YOUR_DEVICE_NAME); dev.activate();
The "MQTT device YOUR_DEVICE_NAME is connected" shall appear on the screen.
2. To publish data to Ubidots, use the following command where the argument is the variable label of the variable desired to be published:
3. Then, to subscribe to different topics, use the following command where the argument is the variable label of the variable desired to be subscribed:
As an example, I decided establish the subscription with the variable previously published temperature; resulting in:
As you can see the message received is 23 which was the last value posted in the variable assigned to the command (temperature).
4. You can start X-NUCLEO-IKS01A1 sensors read-out by
SensorStart() with periodic update (30s). After 30 minutes, the
SensorStop() deactivates the read-out. To enable updating cloud service with sensor data, call:
5. At the end of the session, close the connection with:
Now its time to create Ubidots Dashboards to visualize and understand your data to make the best decisions, simply and coherently.
STMicroelectronics brings freedom and flexibility formass-market developers by configuring IoT devices working over 2G or 3G cellular connectivity or the coming soon LTE Cat M1/NB1 networks.
Happy Developing :)