mbed Client Communication with mbed Device Connector on a Raspberry Pi

This is a walkthrough that gets the mbed Client example program to talk to mbed Device Connector running on a Raspberry Pi. The steps include installing yotta and its dependencies, adding security certificates for mbed Device Connector, and building the example program. Controlling the Rasberry Pi hardware is not explored in this tutorial and is left for future blog posts.

  1. Install Raspbian or another Linux distribution ~30min.


    1. Use DiskPark to clear the SD card:

      list disk
      select disk 1
      clear

    2. Quick format the SD card.


    3. Copy files to the SD card.


    4. Insert the SD card into Raspberry Pi, select Raspbian, wait for it to install.



  2. Install yotta dependencies ~30min


    1. Install yotta dependencies: Use the Debian or Ubuntu instructions. Copy and paste the command presented in the instructions into the terminal and press Enter to install all dependencies.


    2. Install the arm-none-eabi-gcc Linux compiler: sudo apt-get install gcc-arm-none-eabi
      Note: this will take about 500MB and around 15 minutes to download and install.



  3. Update pip ~20s
    pip install -U pip


  4. Install python virtual environment ~10s
    pip install virtualenv


  5. Create virtual environment, install yotta on it ~20min.


    1. Create the virtual environment: virtualenv mbed-venv.


    2. Activate the virtual environment:


      1. Change into the directory: cd mbed-venv


      2. Activate the virtual environment: source ./bin/activate. You should see (mbed-venv) added to the beginning of your command line. To deactivate, run deactivate.

    3. Install yotta on the virtual environment:
      sudo pip install -U yotta. This will take a while to complete (about 20 to 30 minutes, depending on your system), because the crypto libraries like to regenerate a lot of hashes.



  6. Download mbed-client-linux example code:


    1. git clone https://github.com/ARMmbed/mbed-client-linux-example.git.


    2. If you don’t have git installed, you can download the repository as an archive: https://github.com/ARMmbed/mbed-client-linux-example/archive/master.zip.



  7. Build the example code:


    1. Change into the example code directory: cd mbed-client-linux-example.


    2. Check the current yotta target; it should be arm-linux-native: yotta target.


    3. Build the example code: yotta build.


    4. You will have to log in with an mbed account to continue using yotta at this point.



  8. Run the example code:

    Run the generated binary: ./build/arm-linux-native/source/mbed-client-linux-example. It will fail with the following message - this is expected.

    
    
    Endpoint Name : mbed-linux-endpoint
    
    Interface created
    register object created
    Device object created !!
    Registering endpoint
    
    Error occured  : M2MInterface::NetworkError
    
    

    You can exit the code by pressing Ctrl+C.


  9. Add security.h details from mbed Connector


    1. Click on Get My Device Security Credentials to generate a security.h file.


    2. Copy and paste the contents of this to ./source/security.h.



  10. Rebuild and run the project


    1. Run this from the top level of the mbed-client-linux-examples folder: yt build


    2. Run the example code: ./build/arm-linux-native/source/mbed-client-linux-example. It should output to the terminal every five seconds. The outputs look like this:

      
      
      Endpoint Name : 4d4254c3-b373-44a2-a579-ba379d649212
      
      Interface created
      register object created
      Device object created !!
      Registering endpoint
      
      Registered
      Incrementing Resource Value
      Resource Value /Test/0/D : 1
      Sending update register
      
      registration updated
      Incrementing Resource Value
      Resource Value /Test/0/D : 2
      Incrementing Resource Value
      Resource Value /Test/0/D : 3
      Sending update register
      
      registration updated
      Incrementing Resource Value
      Resource Value /Test/0/D : 4
      Incrementing Resource Value
      Resource Value /Test/0/D : 5
      Sending update register
      
      


  11. Customize the code


    system("command")

    Use this command to execute arbitrary shell commands. You can use the Python RPi.gpio library to control the Raspberry Pi, or execute other scripts as you see fit.




Coming Soon: more in-depth examples detailing how to control the board and interact with PUT and POST messages.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.