blog.noob.pro

Very learning, much smart, so motivation

Introduction to CPaaS

CPaaS (Connected Platforms as a Service) is an IoT platform developed by Accenture (a global consulting firm that creates figuratively everything). I’ve decided to try out their IoT platform, let’s get started.

Hardware

  • A Raspberry Pi. I will be using a Raspberry Pi Zero (the version with in-built WiFi and Bluetooth)
  • A power pack for the Raspberry Pi
  • A mini-HDMI to full size HDMI cable (if you are using a Pi Zero). If your monitor doesn’t have a HDMI port you will need to obtain a mini-HDMI to VGA/DisplayPort/DVI adapter
  • On-the-Go USB cable (if you are using a Pi Zero you need this cable to plug your keyboard & mouse into)
  • Keyboard & mouse (I would recommend a self-powered USB keyboard/trackpad, for example the Logitech K400)
  • A monitor
  • A microSD memory card (> 8GB)
  • A microSD to SD adapter (or some other way to transfer files to the microSD card)

the gear

Installation

We will use the Raspbian operating system, download it from here (I will use the ‘RASPBIAN STRETCH WITH DESKTOP’ image).

We now need to install the operating system image onto our microSD card, follow these instructions (we basically just have to format the SD card then use Etcher to write the OS image to the SD card; no terminal commands are required).

Setup

Plug all the cables into the Pi and insert the microSD card, after a few minutes you should see the Raspbian desktop.

Now let’s connect to a WiFi network. If you are using Raspbian Stretch with Desktop you can tap on the network icon in the top-right hand corner and select your WiFi network name. Alternatively, you can follow the below steps. Note, the below step requires you to know the exact name (SSID) of the WiFi network you want to connect to (if you don’t know the exact name of the networking, you can enter this command: sudo iwlist wlan0 scan to see a list of WiFi networks, you will find the WiFi network name under the ESSID key). Type in the below command to connect to a network:

sudo raspi-config

Select the Network Options item from the menu, then the Wi-Fi option. On a fresh install, for regulatory purposes, you will need to specify the country in which the device is being used. Then set the SSID of the network, and the passphrase for the network.

Note: The Pi3/Pi Zero W inbuilt WiFi does not support 5GHz networks.

We will now enable SSH access on the Raspberry Pi. Back on the Pi you should still be in the Raspberry Pi Software Configuration tool, that is raspi-config (if you are not just type the following command into the Terminal sudo raspi-config).

raspi config 1

raspi config 2

raspi config 3

raspi config 4

When you tap on the selected buttons in the above images press the <FINISH> button.

Back in the Terminal on the Pi type in ifconfig (i.e. the Unix equivalent of the Windows ipconfig command), with this command we can obtain the Pi’s IP address (in my case it is 192.168.20.16).

rasp ifconfig

Note: The below steps will only work if your Raspberry Pi and computer are on the same network (connected to the same router).

On our main computer, navigate to the Terminal app (I’m using iTerm2) we can now SSH into the Pi by typing in ssh pi@192.168.20.16 (replace the IP address with your Pi’s IP address). When it prompts you for the password type in the default Raspbian password which is: raspberry

SSH into Pi

You can now run commands direct on the Raspberry Pi from your main computer, lets run some.

Note: To ensure that you are running these commands on the Pi and not your local computer, ensure that you can see pi@raspberrypi in front of your command (refer to the below image).

Pi SSH note

We will first update the local cache of packages (we will soon install some packages).

sudo apt-get update

We will now install Kura, Kura’s purpose is to simplify the design, deployment and web management of embedded applications. IoT devices have software installed on them, Kura makes it easy to deploy and manage this software.

Note: If you get a ‘Do you want to continue [Y/n]?’ prompt just hit the ‘y’ key and press Enter.

Install the gdebi command line tool (gdebi is a tool to install deb packages; Kura comes in a deb package):

sudo apt-get install gdebi-core

Make sure that Java 8 is installed (Kura has a dependency on Java) by running the following command on the Pi:

java -version

If you see something like this (i.e. the Java version) that means that Java is installed.

Check Java version

If Java is not installed (this shouldn’t happen if you followed the above steps), run the following command:

sudo apt-get install openjdk-8-jre-headless

We will now download Kura. As of July 2018 CPaaS only supports version 2.1.0 which was released in Nov 2016.

Note: As we are using a Raspberry Pi Zero we will use the Pi 3 Debian package (without Network Admin).

cd /home/pi
wget http://download.eclipse.org/kura/releases/2.1.0/kura_2.1.0_raspberry-pi-2-3-nn_installer.deb

Note: If you installed Kura with networking support, it will set your eth0 interface to be a DHCP client. If DHCP is not okay for your network, you will have to re-setup your Raspberry Pi and re-install Kura (you will have to remove packages such as dhcpcd5 and disable the network manager; you will also receive some failure message while Kura is being installed such as ‘Failed to start LSB: DHCP server.‘).

Now we will install Kura with gdebi (you can also just type ‘sudo gdebi k’ then press the tab key):

sudo gdebi kura_2.1.0_raspberry-pi-2-3-nn_installer.deb

Kura should now be installed. Note: If you see the below failure messages during installation you probably installed Kura with networking support.

Kura installed with errors

Great, now let’s reboot the Pi (Kura starts on the target platform after reboot):

sudo reboot

You might receive a warning message the next time you boot up your Pi since we are using the default Raspbian username and password, feel free to ignore this message for now (once you have CPaaS setup you might want to change the password for the ‘pi’ user).

ssh warning

Kura will setup a local web UI that is available using a browser via http://<device-ip>

You can navigate to the Kura Admin UI by navigating to this URL in the browser on your Pi (assuming your Raspbian OS has a desktop GUI): http://localhost

You should also be able to navigate to the Kura Admin UI from any machine with your network by navigating to the IP address of your Pi (for example I can navigate to http://192.168.20.16 from my MacBook to see the Kura Admin UI).

The default username and password is: admin

Great, now let’s actually do something with CPaaS.

If you are performing this step from your Pi then type in the below command:

cd /home/pi
wget https://blog.noob.pro/media/introduction-to-cpaas/Demo_polling_emulated.dp

If you are doing this from your computer then download this file.

In the Kura Admin UI, navigate to the Packages tab, click Install/Upgrade and choose the Demo_polling_emulated.dp file that we just downloaded. When it is installed, refresh the web page, you should see ‘DemoPollingService’ under the list of services.

Demo Polling Service

Replace the defaults with the values that are published in the My CPaaS section (note: you need a CPaaS account in the CPaaS Developer Portal for this step, you can get an account here). Device related values must match those specified during device provisioning. When you are done tap the Apply button.

Before we explore CPaaS any further (i.e. use CPaaS products) you should read the CPaaS overview.

Hints and Troubleshooting:

  • To restart CPaaS:
  • sudo /etc/init.d/kura stop; sudo /etc/init.d/kura start

  • The first time I attempted to modify the Demo Polling Service (e.g. I altered the Platform field from ‘Raspberry Pi’ to ‘Raspberry Pi Zero’) and tapped ‘Apply’ and ‘Yes’ in the confirmation popup. The request to http://192.168.20.16/denali/component failed (I received no response) and the Kura Admin UI suddenly stopped working.

    Kura service error

    The Kura log files can be found under /var/log/. I found this in the log files after attempting to modify the Demo Polling Service.

  • !ENTRY org.eclipse.equinox.ds 4 0 2018-07-14 23:48:39.757
    !MESSAGE [SCR] Exception while activating instance com.accenture.libs.mraa.MraaLoader@8585b1 of component com.accenture.libs.mraa.MraaLoader
    !STACK 0
    java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:497)
    	at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
    	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
    	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:347)
    	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
    	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
    	at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
    	at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
    	at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
    	at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
    	at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
    	at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
    Caused by: java.lang.UnsatisfiedLinkError: /tmp/libmraa.so.1.7.0: libjson-c.so.2: cannot open shared object file: No such file or directory
    	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
    	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    	at java.lang.Runtime.load0(Runtime.java:809)
    	at java.lang.System.load(System.java:1086)
    	at com.accenture.libs.mraa.MraaLoader.loadLib(MraaLoader.java:72)
    	at com.accenture.libs.mraa.MraaLoader.activate(MraaLoader.java:38)
    	... 15 more
    Root exception:
    java.lang.UnsatisfiedLinkError: /tmp/libmraa.so.1.7.0: libjson-c.so.2: cannot open shared object file: No such file or directory
    	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
    	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    	at java.lang.Runtime.load0(Runtime.java:809)
    	at java.lang.System.load(System.java:1086)
    	at com.accenture.libs.mraa.MraaLoader.loadLib(MraaLoader.java:72)
    	at com.accenture.libs.mraa.MraaLoader.activate(MraaLoader.java:38)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:497)
    	at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
    	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
    	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:347)
    	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
    	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
    	at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
    	at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
    	at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
    	at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
    	at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
    	at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)

    The Kura Admin UI stops working if there is an exception in a service (it appears that you can crash the Admin UI if there is an exception in a service, in my opinion that’s not a good thing).

    Kura exception browser

  • If you receive the below 404 error page when attempting to access the Kura Admin UI it’s probably because Kura is still starting up (wait 2 min and try again).
  • Kura 404 error

    Comments

    Loading comments...