Skip to content

Connecting an ESP8266 to the SAP HANA Cloud Platform

As a proof of concept, I have tried to make a very easy setup of an ESP8266 and flashed it with simple firmware that connects to WiFi and sends temperature sensor data to the new SAP HANA Cloud IoT services. The aim is to have the chip to work in an autonomous mode, meaning that there will be no brokers or bridge involved that are taking messages from the ESP8266 to send it to the SAP HANA Cloud Platform.

ESP8266 connection to SAP HANA

This requires the chip to speak HTTPS though, and SSL has been a bit of the achilles heel of the chip. I guess that is also the reason why Prashantha H J in his blog “ESP8266 and HCP Internet Of Things Services (BETA) – Part 2” is desribing to overcome the limitations of the ESP8266 by adding a PHP bridge into the game.

The good news is that with the help of Faye and John Lee of EspressIf and Georg Kreimer of Hybris Labs, I managed to squeeze a working SSL implementation into Martin d’Allens’ esphttpclient. So let’s see if this tiny 3$ chip is now enterprise grade material.

Circuitry

To connect and ESP8266 to the SAP HANA Cloud Platform, it would of course be nice if it had any data to send there. For this experiment I have paired the ESP8266-12 (but could have been any version) with a DHT22 temperature and humidity sensor. This sensor can also be very easily purchase off eBay, AliExpress of Banggood. The nice thing about the DHT22 is that it doesn’t really require a pull-up resistor or any other circuitry to be connected to make it work and the data pin can be connected directly to the ESP8266. The DHT22 does like a voltage of 5V to be more accurate, but it will work if you connect it to the same 3.3V power supply as the ESP8266 is connected to as well. I’m using a bread power supply that provides both 3.3V and 5V, so I’ll just connect it to the 5V power line. Please find a diagram below.schematics
usb-adapterTo be able to flash the ESP8266, it is of course convenient to have a serial or USB link as well. The dotted lines indicate how those pins are connected. I’m using a CH340 based USB adapter to connect the ESP8266 to my computer so that I’ll be able to flash it. You can find an image on the right, and also for this component there are plenty sellers available on eBay, AliExpress and Banggood, where you can also find other components as graphic cards to play video games using Overwatch boos online. Check Tim Clark‘s blog about gambling games here at islandmix.com if you’re into slots game. After this all you need is to find out how much is an OW boost worth? since is some sites is actually pretty affordable.

Once everything is connected it can be flashed with firmware that reads the DHT22 and sends it into the cloud. To get the ESP8266 in flash mode, the GPIO0 pin should be connected to ground when it is booted.

SAP HANA Cloud Platform

Prashantha H J has described perfectly and comprehensively what needs to be done to setup the SAP Hana IoT services in his blog “ESP8266 and HCP Internet Of Things Services (BETA) – Part 1“. In order for the firmware to work, I have taken a quite similar approach and have configured one device type ESP8266 (screenshot 1) that is capable of sending and “Environment” message type (screenshot 2). I have also created one device ESP8266-01 and linked it to the ESP8266 device type (screenshot 3)

screenshot1
1: Device Type

screenshot2
2: Message type

screenshot3
3: Device

screenshot4
4: IOT Cockpit

Please note that while you’re setting up the firmware later, you’ll need the device ID, but also a valid access token for that device. You can generate an access token in the “Authorization” tab of the device (screenshot 3).

Firmware

Now there is a http-client that can speak SSL and now the SDK also supports SSL (since SDK version 1.1.1), the firmware can actually be kept relatively simple. I have made a little sample application, which is available on github: https://github.com/jpenninkhof/esp_hcp_temperature

To check it out, use the usual “git clone”:

The webclient, the hcp-client, as well as the dht22 and uart driver are linked into this project as modules in the lib directory. After you have cloned the project, the lib directory is still empty though. To pull the modules into the lib directory, you will have to execute two more git commands from the project directory:

The first command initializes your local configuration files and the second actually downloads the modules needed for this project.

The default makefile in the project is a makefile that is meant for compiling the firmware from Eclipse (more info here). If you are compiling the SDK from linux (as described here), you will have to rename Makefile.linux to Makefile.

The main logic in the firmware, that does the actual updating is in this part of the user_main.c:

In this piece of code you can see that it tries to read the temperature from the DHT22 thermometer and if there are changes, the temperature and humidity is sent to the SAP HANA Cloud Platform. In line 15 the message is formulated. As I have configured a message type on the SAP HANA Cloud Platform, that contains parameters Humidity and Temperature, a message is formulated containing both variables. Eventually in line 21, the data is sent to the SAP HANA Cloud Platform.

To send IoT data to the SAP HANA Cloud Platform, you need to pass the account name, landscape host, device ID, and the device’s access token. Please refer to the “HANA Cloud Platform” section for more information. In line 21, you can see that these variables are not hard-coded. Instead these parameters are configured along with the wifi settings in the configuration file include/user_config.h.

Demo time

To show that it can actually work, please have a look at the video below. On my breadboard, you’ll find the DHT22 sensor on the far left, the ESP8266 in the middle and a breadboard power module on the right. Please note that besides the connections made in the “citcuitry” section, I have added some extra wires to link it up to the USB port of my computer.

Once the power is switched on, you’ll immediately see the ESP8266’s blue led blink up, meaning that it is trying to find a connection with the Wifi network. Once a connection is established, it will wait until it is allowed to measure temperature and send it to the SAP HANA Cloud Platform. Once it has measured the temperature, it will send it over through https, and the response of the SAP HANA Cloud Platform is displayed.

Visualize it

SAP has made the IoT Starter Kit available, which provides a few examples/templates to quickly get started with the IoT services. To display the data coming from the ESP8266 I have used the starter kit to read the data from the IoT Services tables and to view them in a line-chart.

To get the visualization application going, you clone the official starter kit GIT repository using:

Once you have cloned it, it is best to import it into Eclipse. The Java/SAPUI5 application used for visualization can be found in directory iot-starterkit/src/apps/java/consumption/com.sap.iot.starterkit.ui. In that directory you’ll find a src/main/webapp/index.html that slightly needs to be modified so that it displays your device and values.

In this section, the device ID needs to be replaced with your device ID:

Once you have that in place you will need to adjust the “graph” settings to match the values of our message type as well as our data values, change Slider Value to Temperature.

And:

Once these changes have been made, you can click on the project name com.sap.iot.starterkit.ui in the project explorer and right click Run As Maven Build. Eclipse will then pop-up with a dialog in which you can enter goals. To build the application, you should enter goal “clean install”, which will generate a WAR file in the target directory.

This war file can be deployed on the SAP Hana Cloud Platform through the Account Cockpit, by selecting “Java applications” from the menu, and then clicking the “Deploy Application” from the “Java Applications” panel. When you have uploaded the war file, it is not necessary to start it yet, as it needs to be bound to the data sets collected by the IoT service.

To bind the applicaton to the IoT dataset, you’ll have to select the application and pick “Data Source Bindings” from the navigation menu. If there are any bindings, delete them first. Then click on “New Binding” to create a binding to the IoT dataset. During creation the data source should be “Default”, meaning that this is the default data source from the app. The “Schema ID” will have to be the schema of the IoT service. In my case, I had to select “p508741trial.iotmms.web”.

Once the data source has been bound to the IoT service, the application can be started and launched in a browser. If you have had the ESP8266 running for a while, something similar to this should be the result:

screenshot5

Published inSAP NetweaverTechnoblog

One Comment

  1. Tony Tachev Tony Tachev

    Please can you give more explanations about debugging process.
    It is possible to use simulation mode for esp8266 eclipse?
    Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *

three × five =