Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 

Part-1 touched upon ESP8266, it's advantages and limitations. We also prepared HCP IoT Services to accept and store sensor data from ESP8266.

Overcoming Limitations of ESP8266

There are two limitations that need to be addressed.

Connecting to office/corporate network if your office/corporate network is enabled with WPA2-Enterprise security. This device is not yet capable of connecting to such networks. Easiest solution I found was to use my cellular network 3G connection and enabling hotspot in the phone.

ESP8266 cannot use https hence it cannot POST message to Hana Cloud Platform IOT services on its own. To overcome this, I used a PHP web server in an Android tablet and written a small PHP script to accept HTTP GET/POST request from ESP8266 and relay it to HCP IoT Services over HTTPS.

UPDATE: PLEASE NOTE THIS LIMITATION IS NOW POSSIBLE TO OVERCOME Without this PHP Webserver bridge. Please read through the blogs below.

Note: This is just one way of doing this. You might take a different approach to handle this limitation. If you do not have access to an Android device, you can still use your computer to host a PHP web server and follow the steps mentioned below. Or you might use a tomcat server and write a Servlet to do the same.


Download PHP Webserver from Google Play Store. I downloaded a free application Palapa Web Server.

Download Certificate: We have to use certificate from HCP in PHP Script.


     Go to using google chrome.


      Download it as Base 64 certificate in your computer. Let's call it as hana64.cer.


Write a PHP Script to accept GET/POST request from ESP8266:


     ESP8266 will send request to this PHP script with following parameters.


               device: This the device id to which the message has to be sent.

               message: Message in JSON format.

               token: OAuth token that has to be used to send message to HCP.

$device  = "";
$message = "";
$token   = "";
if ($_REQUEST["device"] || $_REQUEST["message"] || $_REQUEST["token"]) {
    $device  = $_REQUEST["device"];
    $message = $_REQUEST["message"];
    $token   = $_REQUEST["token"];
$url = "" . $device;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$array_data  = json_decode($message);
$data_string = json_encode($array_data, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/hana64.cer");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36',
    'Authorization: Bearer ' . $token,
    'Content-Type:  application/json;charset=UTF-8'
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
// Get the response and close the channel.
$response = curl_exec($ch);

    Copy Certificate and PHP file to the PHP Server root location. (Note: Please change the URL to point to your host)

    For Palapa Web Server I used, the root location is Device/pws/www.

Now you can call HCP_IOT_HTTPS_Relay.php hosted in PHP Web Server from ESP8266 with device id, message and token.

You can get the host and port of the server from web server Admin page

You can use chrome app Advanced REST Client to test our HTTPS Relay. Your payload will be like

token=4da8eb85cc10bd5499612899b85c4e7c8&device=90c8ca3d-b1a7-4496-889f-f9305b2892e2&message={"mode":"sync", "messageType":"1", "messages":[{"temperature":34, "humidity":42}]}

Now our HTTPS Relay is ready.

Next Steps:

We have to program ESP8266 to read temperature and humidity from the sensor and fill those values in the message json. To do this we need Arduino IDE and some configuration which will do in Part-3.