Skip to Content
Author's profile photo Prashantha H J

ESP8266 and HCP Internet Of Things Services (BETA) – Part 1

Motivation

I was working on a low cost option to connect some sensors to Hana Cloud Platform. HCP Internet Of Things Services (BETA) helped me realize this quicker and in standardized way. On searching internet for possibilities, I came across wifi modules using SoC called ESP8266 from Espressif Systems. I was able to connect DHT11 (Temperature and Humidity sensor) via ESP8266 to HCP IOT Services (BETA). This blog is just to share my experience.

What is ESP8266

ESP8266 is a low cost Wifi Chip from Espressif Systems. Some vendors have used this chip and provided various WiFi modules. All ESP8266 WIFI Modules come with built in TCP/IP Stack. They have a programmable 32bit Microcontroller and it can be programmed as an internet router to which other devices can connect to or it can be programmed to act as WiFi Client to connect to other servers or both at the same time.

Depending on the modules (ESP-1 to ESP-12) you purchase, There are several GPIOs (General Purpose I/O pins) along with SPI, UART and more which enables connecting many types of devices with this module.

Some advantages

  • Low cost device for IOT applications. (1/10th of Raspberry Pi)
  • Community support. You need not go through pages of data sheet.
  • Small size.

Some limitations that bothered me

      

More information on the module can be found here

Programming ESP8266

Espressif has released their SDK to program this module. It is complex and needs a fair amount of learning effort to use the SDK. Open source communities have made this simple by providing two easy ways to do it.

  1. A Development Kit and a open source firmware called NodeMCU is available which can be used to program ESP8266 easily with few lines of LUAScript. More details here
  2. Arduino IDE for ESP8266 which provides familiar Arduino Environment. For those are who have worked on Arduino, this will be a peice of cake. We will use this option for our project.

Setting up HCP IOT Services for our project

We have to create Device Type, Message Type and Device in IOT cockpit which we will use while sending messages from a device.

Following are the links where you get more information on HCP IoT Services.

Try out SAP HANA Cloud Platform Internet of Things (IoT) Services (BETA) and Starter Kit

I assume you already have Hana Cloud Platform Account. If not, you can follow this link to create one.

Enable Internet of Things Services (BETA) and Go to the service.

  1. Click on Services
  2. Click on Enable
  3. Click on Go to Service -> This will take you to Internet of Things Services Cockpit (BETA)

/wp-content/uploads/2015/05/01_710046.png

Install Message Management Service from Internet of Things Services Cockpit (BETA)

  1. Click on Install Message Management Service.

/wp-content/uploads/2015/05/02_710047.png

Provide

  1. username,
  2. password and
  3. Install the service. Once the service is successfully installed, iotmms dashboard link is displayed.
  4. The link (4) to the dashboard will not work as you have not assigned the role to access the dashboard. We will do it in next step.

/wp-content/uploads/2015/05/03_710057.png

Add user to the role Iot-MMS-User.

Go to the Java Applications in Hana Cloud Platform Cockpit and select “iotmms” from the list of java applications.

  1. Select Roles
  2. Click on Assign (This is accessible before the popup is shown)
  3. Provide User ID
  4. Click on Assign

/wp-content/uploads/2015/05/04_710058.png

  1. Click on Overview
  2. Click on Application URL

/wp-content/uploads/2015/05/05_710059.png

In the resulting screen as shown below, you can go to Internet of Services Cockpit by clicking on the tile ‘View registered devices and device types’.

/wp-content/uploads/2015/05/06_710063.png

Now It is time to configure our device. Follow the steps mentioned in the images below.

/wp-content/uploads/2015/05/07_710064.png

Add a device type

/wp-content/uploads/2015/05/08_710065.png

Add a Message Type as shown in the image below

/wp-content/uploads/2015/05/09_710067.png

Create a Device as shown in the picture below.

/wp-content/uploads/2015/05/10_710068.png

Copy the Device ID and token and save it somewhere. We will be using it while sending message from the device.

/wp-content/uploads/2015/05/11_710078.png

This completes the configuration steps we need to do before actually sending sensor data to HCP.

Testing our Device and Message configuration


We have a Device called ESP8266_DHT11 with ID (90c8ca3d-b1a7-4496-889f-f9305b2892e2) which is of type TemperatureAndHumidity. We can send message from this device to Hana Cloud Platform IoT services using HTTP POST with JSON string as payload. We have to send OAuth token along with message to HCP.


A HTTP Client is provided in the iotmms application itself. We can also use an external http client to test our configuration. I used a Chrome App called Advanced Rest Client to send messages to HCP to mock the message is from a device.

Request

/wp-content/uploads/2015/05/12_710079.png

Response for first request

/wp-content/uploads/2015/05/13_710080.png

Response for next requests

/wp-content/uploads/2015/05/14_710081.png

You can view the messages that were automatically stored in HCP by going to iotmms application

/wp-content/uploads/2015/05/15_710082.png

/wp-content/uploads/2015/05/16_710083.png

Hardware setup

ESP8266 can be programmed by connecting it to a computer via USB 2.0 to TTL Converter. I used CP2102 converter.

ESP8266_Pinout.png

Connecting ESP8266 to CP2102 converter.

ESP8266 CP2102
RX TX
TX RX
CH_PD 3.3V
GPIO0 GND
VCC 3.3V
GND GND

Connect DHT11 Data pin to GPIO2 and VCC and GND of the ESP8266.

MySketch_SCN_Finished.png

Once these connections are made, You are ready to program the ESP8266.

Part-2 describes Overcoming limitations of ESP8266 Modules.

Assigned Tags

      17 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Gregor Wolf
      Gregor Wolf

      Dear Prashantha H J,


      great to see that others are also playing with the ESP8266. I've created this Fritzing  Project – Breakout board for ESP8266 with DS18B20 temperature sensor. I'm using the nodemcu/nodemcu-firmware. Unfortunately it does not support HTTPS. So I'm using a Node-RED as my middleware. Looking forward to see your approach.

      Best regards

      Gregor

      Author's profile photo Prashantha H J
      Prashantha H J
      Blog Post Author

      Dear Gregor Wolf

      Thanks for your interest. I will have a look into your project soon. I posted Part-2 of this blog which explains my approach to handle HTTPS limitation.

      Regards,

      Prashanth

      Author's profile photo Basar Ozgur Kahraman
      Basar Ozgur Kahraman

      Hi Prashantha!

      Very nice blog at an advanced topic for Sap community people.

      i also plan to use esp8266 and your blog will be one of my guides..

      Thanks alot for your effort

      Regards

      Basar Ozgur

      Author's profile photo Former Member
      Former Member

      Very Nice Blog Prashantha..

      Thank you

      Srivatsan

      Author's profile photo Naga Prakash
      Naga Prakash

      Hi Prashantha,

      Do we need to change the Token Id for the every time we do POST call ? For me for first call token is working when i am doing to the same POST again i got an error saying CSRF token is not valid.

      Thanks,

      Naga

      Author's profile photo Anton Levin
      Anton Levin

      Hello Naga, could you re-recheck if you have the */internal/* prefix in your MMS endpoint URL? If yes, replace it with */api/*

      Regards,

      Anton

      Author's profile photo Naga Prakash
      Naga Prakash

      Hi Anton,

      Thanks. i have replaced with "/api/" now it is working fine. I am unable to get the messages pushed from a device through URL,GET method though status is 200. is there also any change in the URL

      Thanks,

      Naga

      Author's profile photo Anton Levin
      Anton Levin

      So, you use IoT MMS Push API, right? That one is protected with Basic Auth. Please, ensure that you enabled the "custom" authentication configuration for you MMS instance like described in the documentation SAP HANA Cloud Platform Internet of Things (IoT) Services

      Regards,

      Anton

      Author's profile photo Naga Prakash
      Naga Prakash

      Hi Anton,

      Found out the way to get the device messages here SAP HANA Cloud Platform Internet of Things (IoT) Services

      Thanks,

      Naga

      Author's profile photo Anton Levin
      Anton Levin

      Ok. And what is the body of your 200 response? Does that mean that problem is solved?

      P.S. OData API is also protected with Basic same to Push API.

      Author's profile photo Naga Prakash
      Naga Prakash

      Hi Anton,

      I am trying to access the oData service in an SAP UI5 application. I am getting the below error.

      "XMLHttpRequest cannot load https://iotmmsp1715266236trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/app.svc/$metadata. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s8hanaxs.hanatrial.ondemand.com' is therefore not allowed access."

      Regards,

      Naga.

      Author's profile photo Anton Levin
      Anton Levin

      Hi Naga, this is a standard CORS problem. See Wiki for more details https://en.wikipedia.org/wiki/Cross-origin_resource_sharing To make a HTTP call from one domain to another you have to configure a destination. But if you have your XS app on Trial this will not be possible, since Trial only supports HTTP destinations and not HTTP. See  SAP HANA Cloud Platform

      I would suggest to create HTML5 app on HCP and call MMS from there. HTTPS destinations are available for HTML5 apps on HCP.

      Anton

      Author's profile photo Gregor Wolf
      Gregor Wolf

      Hi Naga,

      to use a XSODATA Service on the HCP trial a solution is my hanatrial-auth-proxy on GitHub. Then you can use the XSODATA Service via a destionation.


      Best regards

      Gregor

      Author's profile photo Former Member
      Former Member

      Hi Prashantha,

      Nice Blog, i just want to ask you one thing, is there a way by which we send/push data received in iotmms tables  to SAP backend?

      Thanks

      Author's profile photo Prashantha H J
      Prashantha H J
      Blog Post Author

      Hi Yogendra,

      Though I have not done it, but it should be possible using Hana Cloud Integration (HCI). I found following blog: http://scn.sap.com/community/cloud-for-customer/blog/2014/03/27/sap-cloud-for-customer-integration-with-erp-and-crm-how-to-guides-and-e-learning

      Please have a look.

      Regards,

      Prashanth

      Author's profile photo William Terceiro
      William Terceiro

      Hi Prashantha,

       

      I am using ESP8266 with Arduino IDE. I have setup my accounting in the SAP HCP. However, when I try to connect the HCP to send a message from my ESP, the HCP is returning a error 401 not authorized.

      I am using the command “client.print” instruction with HTTP POST. Do you know what the reason I receiving this error and how can I solve it ?

      I will really appreciate any help.

       

      Thanks

      William

      Author's profile photo Former Member
      Former Member

      Hi Prasantha,

       

      I am getting a 400 Bad Request error in the Postman. I have re-checked the message-type id, outh token and all other stuffs several times.

      Can you help me out please ? What is this issue exactly about ?

       

      Regards,

      Souvik