For instructions to get the BLE client working please refer to the repo: https://github.com/ashok-rao/BLE_Client_My_OPT3001.git
There is a slide deck in the repo that should help with an overview of the entire application. Please refer to this.
This is the mbed Client example for mbed OS. It demonstrates how to register a device with mbed Device Connector, how to read a device/resource and how to deregister. If you are unfamiliar with mbed Device Connector, it is recommended that you read the introduction to the data model first.
The application:
- Connects to network via Ethernet connection.
- Registers with mbed Device Connector.
- Gives mbed Device Connector access to its resources (currently read only).
- Reads the light sensor's value & display the same using HTTP GET request.
- Connect to IBM Watson via API keys and relay the same data to IBM Watson.
- A Node-RED app is provided in the repo for import under Node-RED in Watson.
- Configuration of Watson and ARM mbed bridge under Watson is a topic separately dealt with.
- NUCLEO_F429ZI target platform #(with hardware modification for SB121 and SB122 - the resistor needs to be shorted across SB122 since there is an SPI pin conflict between the arduino connector and the LAN controller).
- ST BLE shield (X-NUCLEO-IDB05A1)
- 1x micro-USB cable.
- Ethernet cable and connection to the internet.
This example has been tested in following configuration
- NUCLEO_F429ZI (Ethernet)
Apart from this, this example can work on other mbed OS supported hardware boards which support any of the given network interface including Ethernet, WiFi, Mesh (6LoWPAN) or Thread, provided the configuration fulfills condition that the target hardware has TLS entropy implemented for it and the complete example configuration of mbed Client, selected network interface and mbed OS components fits into hardware's given memory size (Flash size and RAM size).
-
This example requires TLS functionality to be enabled on mbed TLS. On devices where hardware entropy is not present, TLS is disabled by default. This would result in compile time failures or linking failures.
To learn why entropy is required, read the TLS Porting guide.
- ARM mbed account.
- mbed-cli - to build the example programs. To learn how to build mbed OS applications with mbed-cli, see the user guide.
- Serial port monitor.
- IBM Watson account (free account is fine.)
To configure the example application:
- Select the connection type.
- Set the client credentials.
- Change Ethernet settings.
- Set up an IP address. This step is optional.
- Change the socket type. This step is optional.
The application uses Ethernet as the default connection type. To change the connection type, set one of them in mbed_app.json
. For example, to enable 6LoWPAN ND mode:
"network-interface": {
"help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
"value": "MESH_LOWPAN_ND"
}
To register the application with the Connector service, you need to create and set the client side certificate.
- Go to mbed Device Connector and log in with your mbed account.
- On mbed Device Connector, go to My Devices > Security credentials and click the Get my device security credentials to get new credentials for your device.
- Replace the contents in the
security.h
file of this project's directory with the content copied above.
For running the example application using Ethernet, you need:
- An Ethernet cable.
- An Ethernet connection to the internet.
This example uses IPv4 to communicate with the mbed Device Connector Server except for 6LoWPAN ND and Thread. The example program should automatically get an IPv4 address from the router when connected over Ethernet.
If your network does not have DHCP enabled, you have to manually assign a static IP address to the board. We recommend having DHCP enabled to make everything run smoothly.
Your device can connect to mbed Device Connector via UDP or TCP binding mode. The default is UDP. The binding mode cannot be changed in 6LoWPAN ND or Thread mode.
To change the binding mode:
- In the
simpleclient.h
file, find the parameterSOCKET_MODE
. The default isM2MInterface::UDP
. - To switch to TCP, change it to
M2MInterface::TCP
. - Rebuild and flash the application.
Tip: The instructions in this document remain the same, irrespective of the socket mode you select.
To build the example using mbed CLI:
-
Open a command line tool and navigate to the project’s directory.
-
Clone this repo.
-
Configure the client application.
-
To build the application, select the hardware board and build the toolchain using the command:
mbed compile -m NUCLEO_F429ZI -t ARM -c
mbed CLI builds a binary file under the project’s
BUILD/
directory. -
Plug the Ethernet cable into the board if you are using Ethernet mode.
-
Plug the micro-USB cable into the board. The board is listed as a mass-storage device.
-
Drag the binary
BUILD/NUCLEO_F429ZI/ARM/*.bin
to the board to flash the application. -
The board is automatically programmed with the new binary. A flashing LED on it indicates that it is still working. When the LED stops blinking, the board is ready to work.
-
Press the Reset button on the board to run the program.
-
For verification, continue to the Monitoring the application chapter.
The application prints debug messages over the serial port, so you can monitor its activity with a serial port monitor. The application uses baud rate 9600.
Note: Instructions to set this up are located here.
After connecting, you should see messages about connecting to mbed Device Connector:
Starting mbed Client example...
Using <Network Interface>
Connected to Network successfully
IP address xxx.xxx.xxx.xxx
SOCKET_MODE : UDP
Connecting to coap://api.connector.mbed.com:5684
Note: Device name is the endpoint name you will need later on when testing the application.
- Flash the application.
- Verify that the registration succeeded. You should see
Registered object successfully!
printed to the serial port. - On mbed Device Connector, go to My devices > Connected devices. Your device should be listed here.
- Go to Device Connector > API Console.
- Click the Endpoint directory lookups drop down menu.
- In the menu, click GET next to Endpoint's resource representation. Select your endpoint and resource-path. For example, the endpoint is the identifier of your endpoint that can be found in the
security.h
file asMBED_ENDPOINT_NAME
. Choose3200/0/5501
as a resource path and click TEST API. - The value of the light sensror is shown.
Tip: If you get an error, for example Server Response: 410 (Gone)
, clear your browser's cache, log out, and log back in.
Note: Only GET methods can be executed through Device Connector > API Console. For other methods, check the mbed Device Connector Quick Start.
The application exposes three resources:
OPT/0/5501
. Light sensor's readings (GET).
To learn how to get notifications when resource 1 changes, or how to use resources 2 and 3, read the mbed Device Connector Quick Start.