Skip to content

toyowata/BLEClient_mbedDevConn_Watson

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Getting started with mbed Client on mbed OS

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.

Required hardware

  • 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.

Supported Target hardware configurations

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).

Requirements for non-K64F boards

  • 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.

Required software

Application setup

To configure the example application:

  1. Select the connection type.
  2. Set the client credentials.
  3. Change Ethernet settings.
  4. Set up an IP address. This step is optional.
  5. Change the socket type. This step is optional.

Connection type

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"
    }

Client credentials

To register the application with the Connector service, you need to create and set the client side certificate.

  1. Go to mbed Device Connector and log in with your mbed account.
  2. 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.
  3. Replace the contents in the security.h file of this project's directory with the content copied above.

Ethernet settings

For running the example application using Ethernet, you need:

  • An Ethernet cable.
  • An Ethernet connection to the internet.

IP address setup

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.

Changing socket type

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:

  1. In the simpleclient.h file, find the parameter SOCKET_MODE. The default is M2MInterface::UDP.
  2. To switch to TCP, change it to M2MInterface::TCP.
  3. Rebuild and flash the application.

Tip: The instructions in this document remain the same, irrespective of the socket mode you select.

Building the example

To build the example using mbed CLI:

  1. Open a command line tool and navigate to the project’s directory.

  2. Clone this repo.

  3. Configure the client application.

  4. 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.

  5. Plug the Ethernet cable into the board if you are using Ethernet mode.

  6. Plug the micro-USB cable into the board. The board is listed as a mass-storage device.

  7. Drag the binary BUILD/NUCLEO_F429ZI/ARM/*.bin to the board to flash the application.

  8. 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.

  9. Press the Reset button on the board to run the program.

  10. For verification, continue to the Monitoring the application chapter.

Monitoring the application

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.

Testing the application

  1. Flash the application.
  2. Verify that the registration succeeded. You should see Registered object successfully! printed to the serial port.
  3. On mbed Device Connector, go to My devices > Connected devices. Your device should be listed here.
  4. Go to Device Connector > API Console.
  5. Click the Endpoint directory lookups drop down menu.
  6. 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 as MBED_ENDPOINT_NAME. Choose 3200/0/5501as a resource path and click TEST API.
  7. 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.

Application resources

The application exposes three resources:

  1. 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.

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 67.6%
  • Objective-C 18.1%
  • C 12.0%
  • Python 2.3%