/wp-content/uploads/2016/05/1_956255.png

What is WioLink

WioLink is a Kickstarter funded, ESP8266 based open-source Wi-Fi development board to create IoT applications by virtualizing plug-n-play modules to RESTful APIs with mobile APPs.

Kickstarter campaign

What is the BBGW


The BeagleBone Green Wireless is a joint effort by BeagleBoard.org and Seeed Studio. Based on the open-source hardware design of BeagleBone Black, the newest BBGW has added two Grove connectors, making it easier to connect to the large family of Grove sensors. It is the first Wi-Fi + Bluetooth Low Energy (BLE) board from BeagleBone community.

More information you can find here: http://seeedstudio.com/item_detail.html?p_id=2650

Preparing the BBGW

Install the WioLink Server on the BBGW

You may have read my instructions on how to install the WioLink Server on a Raspberry Pi3 already. In the meantime, I’ve received the brand new Beagle Bone Green Wireless (BBGW in short) and I’ve managed to install the server also on this nice piece of hardware.

You can use the same instructions like described in the mentioned post above but you have to change the ports, because the port 8080 is already in use on the BBGW:

See Chapter 2:

Change the ports from 8080 to for example 8088

            ProxyPass /v1/node/event ws://127.0.0.1:8088/v1/node/event

            ProxyPassReverse /v1/node/event ws://127.0.0.1:8088/v1/node/event

            ProxyPass /v1 http://127.0.0.1:8088/v1

            ProxyPassReverse /v1 http://127.0.0.1:8088/v1

And in the /opt/WioLink/server.py you also have to change the port in line 542 from 8080 to the same port as above.

Now hopefully you can connect your WioLink with the Mobile App to the WioLink server (with the BBGW IP and 8088 as port).

/wp-content/uploads/2016/05/2_956270.png

For our example we need the “Temperature & Humidity” and the “Barometer (BMP180)” Grove sensors. Hint: for the Barometer sensor use the BMP085 driver in the Mobile App (not the BMP280!). Test them with the API page http://<BBGW IP>:8088/v1/node/resources?access_token=<WioLink access token>

Update openSSL on the BBGW

Unfortunately, the Python openSSL library is a bit outdated and has some bugs on the BBGW and we have to upgrade it to the newest one.

On the command line with root privileges enter:

apt-get install libffi-dev

apt-get install libssl-dev

pip install pyopenssl –upgrade

Preparing the SAP HANA Cloud Platform

Register a developer account

If you don’t have a user on the SAP HANA Cloud Platform (short “HCP”) yet, go to https://hcp.sap.com/developers.html and Sign-up for your free SAP HANA Cloud Platform, developer edition. The register process is pretty straight forward and doesn’t need a further explanation IMHO.

Activate the Internet of Things Services

After you have activated your account you will be forwarded directly to the “SAP HANA Cloud Platform Cockpit”. On the left side select “Services” and click on the “Internet of Things Services” and enable it.

/wp-content/uploads/2016/05/3_956271.png

After the service is enabled and started, press “Go to service”. The “Internet of Things Services Cockpit” will start.

Configure Device Types, Message Type and Device

In our example we only use one Device Type, Message Type and Device.

/wp-content/uploads/2016/05/4_956272.png

Click on “Device Type” and with “+” add a new Device Type and enter a description. Save and go back with “<-“.

Click on “Message Types” and with “+” add a new Message Type. Enter a name, select the Device Type we’ve created in the last step and delete the field “timestamp” in the field list.


For our Message Type we create three new fields: temperature, humidity and pressure. Each of type “double”. Save and go back with “<-“.

/wp-content/uploads/2016/05/5_956273.png

The last step is to create the real physical device. If you have more than one WioLink with the same sensors plugged in you would create a device for each WioLink. In our case we only create one.

Click on “Devices” and with “+” add a new device. Enter a name and the correct Device Type and press “Create”. In the following dialog box copy the created OAuth access token and save it somewhere. We need this token later. This is the only chance to see this token! If you lose the token, you are always able to create a new one for this device, but the old one is lost and you may have to change all the programs you’ve created yet for this device.

/wp-content/uploads/2016/05/6_956274.png

Read the sensor data and push the measures to HCP

Call the build-in Cloud9 Editor of your BBGW: http://<BBGW IP>:3000

Via context menu (right click) create a new folder under “cloud9”.

/wp-content/uploads/2016/05/7_956275.png

In this folder create a new file “weather.py” and paste the following code (I’ll explain the code later):


import requests
import time
wioHost   = 'http://<BBGW IP>:8088'
wioToken  = '<token of your WioLink>'
hcpWio1Device             = '<device ID>'
hcpOAuthToken             = 'Bearer <OAuth access toke>'
hcpMessageTypeWeather    = '<message type ID>'
if __name__ == '__main__':
    wioURLHumidity    = wioHost + '/v1/node/GroveTempHumD0/humidity?access_token=' + wioToken
    wioURLTemperature = wioHost + '/v1/node/GroveBaroBMP085I2C0/temperature?access_token=' + wioToken
    wioURLPressure    = wioHost + '/v1/node/GroveBaroBMP085I2C0/pressure?access_token=' + wioToken
    hcpURL = 'https://iotmmsp471996trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/' + hcpWio1Device
    hcpHeaders = {'Content-Type': 'application/json', 'Authorization': hcpOAuthToken}
    humidity = 0.0
    temperature = 0.0
    light = 0
    pressure = 0.00
    while 1 :
        response = requests.get(wioURLHumidity)
        
        if not response.ok :
            print('Wio error: ' + wioURLHumidity)
            print(response)
            break
    
        else :
        
            print(response.text)
            humidity = response.json()['humidity']
        response = requests.get(wioURLTemperature)
        
        if not response.ok :
            print('Wio error: ' + wioURLTemperature)
            print(response)
            break
        else :        
        
            print(response.text)
            temperature = response.json()['temperature']
    
        response = requests.get(wioURLPressure)
        
        if not response.ok :
            print('Wio error: ' + wioURLPressure)
            print(response)
            break
        
        else :
        
            print(response.text)
            pressure = response.json()['pressure']
        messages  = '{ "temperature": ' + str(temperature) + ','
        messages += ' "humidity": ' + str(humidity) + ','
        messages += ' "pressure": ' + str(pressure) + '}'
                
        body = '{ "mode":"sync", "messageType": "' + hcpMessageTypeWeather + '", "messages":[ ' + messages + ']}'
        print body
    
        response = requests.post(hcpURL,data=body, headers=hcpHeaders)
        if not response.ok :
            print('HCP error: ' + hcpURL)
            print(response.text + response.reason)
            break
    
        print(response.text)
    
        time.sleep(600)


The following lines you have to change:

wioHost   = ‘http://<BBGW IP>:8088′

<BBGW IP> The IP address of your BBGW

wioToken  = ‘<token of your WioLink>’

The access token of your WioLink (you can find the token in the API page)

hcpWio1Device             = ‘<device ID>’

You can find the device ID on the Devices page of the IoT Service Cockpit

/wp-content/uploads/2016/05/8_956288.png

hcpOAuthToken             = ‘Bearer <OAuth access toke>’

The OAuth access toke you hopefully saved in the last chapter…

hcpMessageTypeWeather    = ‘<message type ID>’

The Message Type you can find on the Message Types page of the IoT Service Cockpit

/wp-content/uploads/2016/05/9_956289.png

If you are finished with the changes you can run the script by pressing “Run” in the Cloud9 editor.

Display messages

If everything is going well, the sensor data is collected, the message is created and sent to the HCP IoT service every 10 minutes.

Go to the IoT cockpit and press “Send and view messages,..”, the “Message Management Service Cockpit” will start.

/wp-content/uploads/2016/05/10_956291.png

Press “Display stored messages”.

/wp-content/uploads/2016/05/11_956292.png

You will see (at least) four tables where the one with the cryptic name is the one with our messages:

/wp-content/uploads/2016/05/12_956294.png

Click on this table and we’ll see the created messages:

/wp-content/uploads/2016/05/13_956295.png

Now, what can we do now with these messages?

OData

Well, exactly here is the advantage of the SAP HCP IoT service: the messages can be exposed as OData service. In the message overview (on the right side above the messages) click on

/wp-content/uploads/2016/05/14_956296.png

and you’ll get a link to the XML representation of the messages. Click on this link.

Hopefully you’ve installed an XML viewer extension like “XML Tree” on Chrome to see the messages in a readable format.

If you add “?$format=json” to the URL you’ll get the messages as JSON.

Other OData queries:

Count the measurements:

/$count

Order by temperature / get the top 5 highest temperatures

?$orderby=C_TEMPERATURE

?$orderby=C_TEMPERATURE%20desc&$top=5

Get the measurements from day x until today

?$filter=G_CREATED%20ge%20datetime%272016-05-17T00:00:00%27

Get the measurements of day x

?$filter=G_CREATED%20ge%20datetime%272016-05-17T00:00:00%27%20and%20G_CREATED%20lt%20datetime%272016-05-18T00:00:00%27

More information on OData you can find on the homepage of OData: http://www.odata.org/getting-started/basic-tutorial

Import the messages to Excel

Because Microsoft is one of the sponsors of OData it is part of, for example, Excel.

First of all, make sure, that the decimal separator in Excel is a decimal point. Have a look in the options of Excel:

/wp-content/uploads/2016/05/15_956300.png

In an empty Excel sheet goto “DATA -> Get External Data -> From Other Sources -> From OData Feed”

/wp-content/uploads/2016/05/16_956301.png

Paste here the Link to the messages, select “Use this name and password” and enter user and password of your SAP HCP account. Press “Next”. On the next screens select the table and press “Finish” and “OK”.

You should now see the stored messages. Unfortunately, (I think) there is a bug in Excel: the values are not recognized as numbers. But there is a nice solution:

  • Enter a “1” somewhere in an empty cell
  • Copy this “1” into the clipboard (mark and <ctrl>+c)
  • Mark all values (really only the values, not the whole columns!) and call the context menu (right click)
  • Click on “Paste Special…”)
  • Select “Multiply” and “OK”
  • Repeat this with “0.01” and the “Pressure” values.

Now we can create nice charts with this values:

Select the columns “CREATED” and “TEMPERATURE”. Via “Insert -> See All Charts” you can go to an overview of all charts

/wp-content/uploads/2016/05/17_956302.png

Select “Line” in tab “All Charts” and “OK”

/wp-content/uploads/2016/05/18_956306.png

You may repeat this with columns “HUMIDITY” and “PRESSURE”.

You can save the Excel sheet now. The data source is saved also. After a couple of hours open the sheet again, right click on the data and select “Refresh”. You have to enter user and password again -> new data is imported. After you did the trick with “1” and “0.01” again, the charts get updated automatically.

What’s next?

With such kind of OData services, you can create easily whole applications, for example an IoT monitor.

On OpenSAP a free online course about building such applications just starts this week (Mid May 2016). But you can always enter this course later, too.

Link to the course: https://open.sap.com/courses/ui51


Disclosure: at time of writing the author was beta tester for Seeed Studio and got the tested BBGW board for free.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply