Overview

Skill Level: Beginner

Send Onion Omega2 CPU Utilization metrics to the IBM Watson IoT Platform Quickstart and graph the data. Download / Install / Run the ibm-iot-quickstart.py Python script on your Onion Omega2 to publish MQTT events to Quickstart.

Ingredients

  1. Onion Omega2 - The World's smallest $5 Linux server with Wi-Fi built-in. Building for IoT doesn't get easier than this!
  2. Onion Omega2 Expansion Dock or the Mini Expansion Dock

Step-by-step

  1. Prepare

    Complete the Onion Omega2 First Time Setup steps to connect your Omega2 to the WiFi network.Β  These steps include logging into the Omega2 Console with a Windows, Mac or Linux computer and opening a Command Line (or ssh).

  2. Install Python and Watson IoT QuickStart program

    1. Install Python and the Python Install Program (pip) on your Omega2.Β  Make certain you are running the latest Python setuptools package by uninstalling and reinstalling.
      opkg install python
      opkg install python-pip
      pip uninstall setuptools
      pip install setuptools
    2. Install the prerequiste Python libraries needed by the Watson IoT QuickStart program. The Python script ibm-iot-quickstart.py requires the ibmiotf python library to be in place before it can be executed. The following PIP command ensures that this module dependency is met by downloading and installing the ibmiotf python library. Use sudo privilege to execute the PIP command, as needed.
      pip install ibmiotf

      If an Out of Memory error occurs, you might need to install each of the python library dependencies separately.

      pip install iso8601
      pip install xmltodict
      pip install dicttoxml
      pip install requests_toolbelt
      pip install requests
      pip install pytz
      pip install paho_mqtt
      pip install ibmiotf
    3. Download the ibm-iot-quickstart.py file.
      wget https://raw.githubusercontent.com/ibm-messaging/iot-gw-solutions/master/samples/ibm-iot-quickstart.py
  3. Connect and Visualize (Quickstart)

    1. Run the Watson IoT Quickstart program
      python ibm-iot-quickstart.py
    2. Note the MAC address that is displayed in the console window.
    3. To Visualize the CPU Utilitization metrics of your Omega2, visit the Watson IoT QuickStart page and enter the MAC address of your device.
  4. Register your Device in Watson IoT Platform

    To explore and make use of the full capabilities of Watson IoT Platform, we need to setup and register your device(s) in the Watson IoT Platform. This section shows how you can setup a device.

    Carry out the steps present in this recipe to register your device(s) in IBM Watson Internet of Things Platform.

    At this step, we have successfully created the Watson IoT service and registered your device(s).

  5. Connect and Visualize (Registered)

    1. If the ibm-iot-quickstart.py script is still running, stop it by pressing Ctrl+C from the command line.
    2. Download the device.cfg file.
      wget https://raw.githubusercontent.com/ibm-messaging/iot-gw-solutions/master/samples/device.cfg
    3. Edit the configuration file by typing
      vi device.cfg
    4. If you didn’t download the device.cfg above, you can create a new one by copying the following code and paste it into the opened sample configuration file. To paste, press β€˜insert’ then Shift + Insert
      [device] =
      org=<Organization ID>
      type=<Device Type>
      id=<Device ID>
      auth-method=token
      auth-token=<password>
      clean-session=true
    5. Provide the values for each of the parameters in the configuration file, with the details gathered during the Watson IoT Device registration.
    6. Exit the vi editor by pressing Escape, then typing ‘:wq’ and pressing Enter
    7. At the console enter the following command and see your device connecting to the registered service.
      python ibm-iot-quickstart.py

      Β 

    8. In the Watson Internet of Things Platform there are boards and cards capabilities where you can build your own Custom dashboard without writing any code. You can use the boards as a landing page and then make use of the cards to:

      • Create visualization charts of the real time data from your devices
      • Create Gauges for visualizing physical quantities like Vehicle Speed, Temperature, pressure
      • Create Donuts charts, bar charts to display the current value of the data points
      • See the Data and storage consumption of your devices
      • List of registered devices

      Refer to Configuring Boards & Cards in the new Watson IoT Dashboard recipe to view the registered device events in Watson IoT Platform.

  6. Conclusions and other related Recipes

    In this recipe, we showcased how to connect an Onion Omega2 to IBM Watson IoT Platform. We also have many recipes that demonstrate connecting devices to IBM Watson IoT Platform.

17 comments on"Connect an Onion Omega2 to IBM Watson IoT Platform"

  1. Zaghloul Saad April 01, 2017

    root@Omega-50C3:~# pip install ibmiotf
    Collecting ibmiotf
    Downloading ibmiotf-0.2.7.zip (57kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 61kB 265kB/s
    Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-BN0MxN/ibmiotf/
    root@Omega-50C3:~#

    Any ideas?

    • John Walicki April 02, 2017

      Hi Zaghloul – I saw that error once. I rebooted the Omega2 and ran the command again. It succeeded.

      • Zaghloul Saad April 02, 2017

        Hi John, even after do the setup from scratch to the Omega2+ still facing the below issue (Same)
        root@Omega-50C3:~# pip install ibmiotf
        Collecting ibmiotf
        Downloading ibmiotf-0.2.7.zip (57kB)
        100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 61kB 322kB/s
        Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-ncofc4/ibmiotf/

        any ideas how to get the logs? to understand what is the issue?

        • John Walicki April 03, 2017

          Hi Zaghloul – The Onion is memory constrained. You might need to install one Python dependency at a time. Try this:
          $ pip install iso8601
          $ pip install xmltodict
          $ pip install dicttoxml
          $ pip install requests_toolbelt
          $ pip install requests
          $ pip install pytz
          $ pip install paho_mqtt
          $ pip install ibmiotf

          • Zaghloul Saad April 03, 2017

            i had to run the below commands before
            pip install –upgrade setuptools
            pip install ez_setup

            than it works successfully when i try again.. i’ll continue the tutorial now πŸ™‚

          • John Walicki April 03, 2017

            Great suggestion to run
            $ pip install –upgrade setuptools
            I had run that command at some point while setting up Python on the Omega2. That might be the trick. I will add that to the recipe. Thanks for the improvement.

  2. Zaghloul Saad April 03, 2017

    No im facing agian error while running the ibm-iot-quickstart.py
    ===================================================
    root@Omega-50C3:/tmp# python ibm-iot-quickstart.py
    Traceback (most recent call last):
    File “ibm-iot-quickstart.py”, line 16, in
    import client as mqtt
    ImportError: No module named client
    ==========================================

    is that last updated file?

  3. Zaghloul Saad April 05, 2017

    No i’m facing a new issue after configer the device file

    ======================================================
    root@Omega-50C3:~# python ibm-iot-quickstart.py
    please check the format of your config file
    please check the format of your config file
    Configuration file found – connecting to the registered service
    Traceback (most recent call last):
    File “ibm-iot-quickstart.py”, line 145, in
    deviceClient = ibmiotf.device.Client(options)
    File “/usr/lib/python2.7/site-packages/ibmiotf/device.py”, line 105, in __init__
    port = self._options[‘port’]
    File “/usr/lib/python2.7/site-packages/ibmiotf/__init__.py”, line 105, in __init__
    if float(get_distribution(‘paho-mqtt’).version) < 1.1 and (sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 2)):
    ValueError: invalid literal for float(): 1.2.1
    ======================================================

  4. Zaghloul Saad April 06, 2017

    Hi Again,

    can you tell me what is wrong with my below parameters?
    =============================================
    root@Omega-50C3:~# python ibm-iot-quickstart.py
    please check the format of your config file
    please check the format of your config file
    Configuration file found – connecting to the registered service
    2017-04-06 14:27:04,623 ibmiotf.device.Client CRITICAL Not authorized: s (d:3brtc1:Omega2Plus:Omega50C3, use-token-auth, a-3brtc1-tzcjgvbboz)
    Exception in thread Thread-1:
    Traceback (most recent call last):
    File “/usr/lib/python2.7/threading.py”, line 801, in __bootstrap_inner
    self.run()
    File “/usr/lib/python2.7/threading.py”, line 754, in run
    self.__target(*self.__args, **self.__kwargs)
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 2630, in _thread_main
    self.loop_forever(retry_first_connection=True)
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 1411, in loop_forever
    rc = self.loop(timeout, max_packets)
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 927, in loop
    rc = self.loop_read(max_packets)
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 1210, in loop_read
    rc = self._packet_read()
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 1803, in _packet_read
    rc = self._packet_handle()
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 2284, in _packet_handle
    return self._handle_connack()
    File “/usr/lib/python2.7/site-packages/paho/mqtt/client.py”, line 2345, in _handle_connack
    self.on_connect(self, self._userdata, flags_dict, result)
    File “/usr/lib/python2.7/site-packages/ibmiotf/device.py”, line 142, in on_connect
    self.logAndRaiseException(ConnectionException(“Not authorized: s (%s, %s, %s)” % (self.clientId, self.username, self.password)))
    File “/usr/lib/python2.7/site-packages/ibmiotf/__init__.py”, line 137, in logAndRaiseException
    raise e
    ConnectionException: Not authorized: s (d:3brtc1:Omega2Plus:Omega50C3, use-token-auth, a-3brtc1-tzcjgvbboz)

    2017-04-06 14:27:14,383 ibmiotf.device.Client CRITICAL Operation timed out connecting to the IBM Internet of Things service: 3brtc1.messaging.internetofthings.ibmcloud.com
    Traceback (most recent call last):
    File “ibm-iot-quickstart.py”, line 146, in
    deviceClient.connect()
    File “/usr/lib/python2.7/site-packages/ibmiotf/__init__.py”, line 146, in connect
    self.logAndRaiseException(ConnectionException(“Operation timed out connecting to the IBM Internet of Things service: %s” % (self.address)))
    File “/usr/lib/python2.7/site-packages/ibmiotf/__init__.py”, line 137, in logAndRaiseException
    raise e
    ibmiotf.ConnectionException: Operation timed out connecting to the IBM Internet of Things service: 3brtc1.messaging.internetofthings.ibmcloud.com

    • John Walicki April 06, 2017

      Hi Zaghloud – Connect with me off line – walicki at us.ibm.com – so we don’t post too many of your auth tokens in the comments. We can debug privately.

  5. Hi,
    I was able to successfully complete the tutorial, and now my Omega2 is Watson-connected.
    I have a few questionts though:
    1st is:
    What are the use cases? I mean can you give an example, what kind of info I can retrieve from my Omega, and how it can be practically used?
    2. Now I am running a script via tmux ( to be able to disconnect from ssh without loosing the connectivity).
    Can you please clarify, how I can auto-start the script with Omega2 boot?
    Thank you in advance!

    • John Walicki April 13, 2017

      Hi Senovr – Great to hear that you have completed the tutorial. I’m thinking about my next Omega2 recipe. If you have the Onion GPS usb module, you could send GPS coordinates to Watson IoT Platform, use The Weather Company API to look up your current temp and send that back down to the Onion for display on the OLED module.

      If you want the Watson IoT CPU utilization report to autostart, you can follow the steps here: https://wiki.openwrt.org/doc/techref/initscripts

  6. vikasmalik22 April 14, 2017

    Hi John.
    One Suggestion – You Should mention how much amount of free memory is required before installing all these packages.
    As these packages occupy so much of memory.

  7. vikasmalik22 April 14, 2017

    Thanks for this quickstart tutorial. Successfully created and running it now.

    • John Walicki April 15, 2017

      Hi Vikasmalik – Great to hear that you have completed the tutorial and have turned your Omega2 into an IoT Device.

Join The Discussion