cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Hana with Sensor network

Former Member
0 Kudos

Hello Everyone,

I am trying to connect different sensors and sensor networks to HCP. I have started with the blog ESP8266 and HCP Internet of Things by Prashantha H J. Firstly, Thanks for his efforts. Secondly, I am able to create token and device id successfully and I am able to send data from Chrome plugin Advanced Rest Client. As I am Embedded Systems Developer, I am not able to understand completely about POST request and GET request.

My Questions are:

1. I am trying to send request through AT commands. Below is the command

AT+CIPSTART="TCP","iotmmss000944X510trial.hanatrial.ondemand.com",80

AT+CIPSEND=309

POST /com.sap.iotservices.mms/v1/api/http/data/feffb77c-ad07-4ab2-b70b-fe2b0c5705Xd HTTP/1.0\r\n

Host: iotmmss000944X510trial.hanatrial.ondemand.com\r\n

Content-Type: application/json;charset=utf-8\r\n

{"mode":"sync","messageType":"7a2f26b89f04c5fX5cff","messages":[{"value":"22", "timestamp":"201509030334"}]}

I get SEND OK from my device. But Nothing I can see from Server side. Can any one help me to identify the problem in command. what I am missing.

2. Is it possible to Use GET Command instead of POST command? I am not using any PHP files.

Finally, I would like to implement complete commands and requests in C only.

Thanks in advance.

Naveen

Accepted Solutions (1)

Accepted Solutions (1)

anton_levin
Advisor
Advisor
0 Kudos

Hello Naveen,

1. After sending the data and getting HTTP Ok, do you see your table T_IOT_<MESSAGE_TYPE_ID> in embedded MMS UI (Application Data tile on top left)?

2. No, GET is used for different purposes. MMS expects POST requests when sending the data.

Regards,

Anton

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Naveen,

I am trying to send data to HCP through AT+CIPSTART but getting below error. and the data is not getting posted. could you please check Post method below  and let me know where is the error in the code. If you could also share me your running code for reference, it would be of great help.

Response

AT+CIPSEND=

OK

>

Recv 291 bytes

SEND OK

+IPD,220:HTTP/1.0 302 Found

Loc

Code :


#define DST_IP "iotmmsp*******trial.hanatrial.ondemand.com"

void post()

{

  String data;

 

data += "{\"mode\":\"async" "\" , \"messageType\":\"40ea546692723af52262\", \"messages\":\[{\"Temperature\":\"15\"}]}";

    String uri = "/com.sap.iotservices.mms/v1/api/http/data/<device-id>";

    String port = "80";

 

//  String http_req = "POST " + uri + " HTTP/1.1\r\n" + "Host: " + DST_IP + ":" + port + "\r\n" + "Accept: *" + "/" + "*\r\n" + "Content-Length: " + data.length() + "\r\n" ;

  String http_req = "POST " + uri + " HTTP/1.1\r\n" + "Host: " + DST_IP + ":" + port + "\r\n" +  "Content-Length: " + data.length() + "\r\n" ;

  String http_req1 = "Content-Type: application/json\r\n\r\n" ; // form the headder to post the WiFi      data

//  String http_req2 = "Authorization: Bearer f1e789b5bdf5313f6eaea8dea379a6" ;

 

  Serial.println(data);

  Serial.println(http_req);

  Serial.println(http_req1);

//  Serial.println(http_req2);

 

  int len_hedder1 = (http_req.length());

  int len_hedder2 = (http_req1.length());

//  int len_hedder3 = (http_req2.length()); 

  int len_data    = data.length();

 

  int Total_req_data_Length = (len_hedder1 + len_hedder2  + len_data); // total length of headder and data

 

  Serial.println();

  String cmd = "AT+CIPSTART=\"TCP\",\""; //

  cmd += DST_IP;

  cmd += "\",80";

 

  Serial.println(cmd);

  WiFi_Serial.println(cmd);

  delay(5000);

  if (WiFi_Serial.available())

  {

    String RES_input = "";

    while (WiFi_Serial.available()) // read the data into a variable as long as the

    {

      RES_input += (char)WiFi_Serial.read();

    }

    Serial.println(RES_input);

    Serial.print("AT+CIPSEND="); // start sending data to opened TCP port

    WiFi_Serial.print("AT+CIPSEND=");

    WiFi_Serial.println(Total_req_data_Length); //specify the total length of data

    delay(100);

    if (WiFi_Serial.available());

    RES_input = "";

    while (WiFi_Serial.available()) // read the data into a variable as long as the

    {

      RES_input += (char)WiFi_Serial.read();

    }

    Serial.println(RES_input);

    {

      if (WiFi_Serial.find(">")); // when ">" is response from WiFi that means it is ready to receive the total length of data

      {

        WiFi_Serial.print(http_req); //Send headder first

        WiFi_Serial.print(http_req1);

//        WiFi_Serial.print(http_req2);

        WiFi_Serial.print(data); //later send data

        delay(2000);

      }

    }

    if (WiFi_Serial.available()) // wait for response and print the same to terminal

    {

      delay(100);

      String RES_input = "";

      while (WiFi_Serial.available()) // read the data into a variable as long as the

      {

        RES_input += (char)WiFi_Serial.read();

      }

      lcd.clear();

      Serial.println(RES_input);

      Serial.println();

      Serial.println();

    }

  }

}

Thanks

0 Kudos

it would be good if you dump the whole response, so that we can see where it redirects to.

Try to dump it directly and not fill the variable

and also you can try to include a delay(1) between each WIFI_Serial.read();

Former Member
0 Kudos

Hello Vladimir,

Thanks you for taking time out to response .

After getting ">" I am sending header and data, below is the code.

Please note I am not sending "Authorization  Bearer f1e789b5bdf5313f6eaea8dea379a6", which consist of token.

>Try to dump it directly and not fill the variable - I am sorry but I dint understand how to do it.

Below is the full response from WIFI_Serial.read();

Recv 291 bytes

SEND OK

+IPD,220:HTTP/1.0 302 Found

Loc

Thanks

0 Kudos

i saw this in your original message, but

+IPD,220:HTTP/1.0 302 Found

Loc

means that there are 220 bytes, more

preciesely 302 Found is followed by

Location: <something here>

this is what is good to know.

So try to read it

Also if you want to do something productive with the ESP8266,i would strongly advice you to have a look on the Arduino ESP8266 port. https://github.com/esp8266/Arduino

You should be able to get it working in 15 minutes, and then there are ready examples that do HTTP requests with the built in HTTP client, so it makes it much easier

Former Member
0 Kudos

Hello Yogendra,

Please let me know some more information to send me my code.

1. What compiler your using.

2. Controller information.

3. What response your getting from server side.

4. currently what method your currently using to upload the data. I mean, are you trying to program ESP8266 directly to send your data or are your using any other controllers.

5. How are you trying to send data. Did you try your url with Google chrome Extension. please look into Prashanta H J Blog.

Former Member
0 Kudos

Hi Naveen,

I am using Arduino UNO with ESP8266 to send my sensors data like Temperature and humidity to HCP.

I am uploading my code on Arduino board, and ESP8266 is able to connect to given WiFi. Yes I have tried to send data from Chrome Postman and data is getting updated successfullly in IOTmms table in HCP.

First, I am sending command -  AT+CIPSEND and then total length of data

**Code

WiFi_Serial.print("AT+CIPSEND=");

WiFi_Serial.println(Total_req_data_Length); //specify the total length of data

**

Secondly, After getting ">" I am sending header and data, below is the code.

Please note I am not sending "Authorization  Bearer f1e789b5bdf5313f6eaea8dea379a6", which consist of token.

Below is the full response from WIFI_Serial.read();

Recv 291 bytes

SEND OK

+IPD,220:HTTP/1.0 302 Found

Loc

Please let me know if you require any more information to understand my scenario.

Thanks

Former Member
0 Kudos

Hi

Two questions I would like to ask.

1. Is there anyway I can get the full string.....like Location: <something here>

2. HCP iot support http or https?

Thanks

anton_levin
Advisor
Advisor
0 Kudos

Without sending the Authorization header, you get HCP login page back (with HTTP code 302). Sending data to MMS requires OAuth authorization (bearer token)

0 Kudos

Aahhhh i think that was the problem... the AT Firmware does not support HTTPS, since it allocates quite some heap, and opening a HTTPS connection requires more heap than HTTP

So if you are doing it over HTTP, then most probbable the redirect is to the HTTPS url

Anyway to read the whole string - as i said

1. Do not collect stuff in a string, you may get into memory troubles. Just dump each character as it comes

2. Do not rely on .availalbe() to return you correct result... just dump the next N (e.g. 220) characters, this will help you to debug it easier...

But i believe it is indeed the HTTPS issue

in this case if you want to use it from the ARduino - it is best to develop some simple wrapper that communicates over Serial Port with the Arduino and does the calls to HCP.

I have such an example but currently it is in a very bad shape and i am currently fixing it.

But in any case you would need to move to using the Arduino IDE to program the ESP8266 for this

anton_levin
Advisor
Advisor
0 Kudos

SAP HANA Cloud Platform exposes applications only via HTTPS. See SAP HANA Cloud Platform

Former Member
0 Kudos

Ok. Nice. I can list possible errors.

1. ESP8266 commands should end with \r\n always. Eg: AT+RST\r\n

2. String length and string should match always. Anyways Arduino compiler is great and flexible. There are ready functions.

3. Please make sure your not working on your office network. Since ESP8266 is not able to work with https. I think Prashanta H J blog explains clearly.

4 you can use one Tom cat server to run one php to take care of your https problem. Which is again explained in Prashanta's blog.

5. Hopefully from your controller side looks ok for me. Anyway you need to make sure UART is working. That is already running perfect.

6. Maintain proper delay. If there is no delay sometimes ESP8266 becomes busy and it need Reset.

Former Member
0 Kudos

Hi Naveen,

Thanks for the response. Just one thing to ask, did you also used ESP8266 for your communication?

If yes, how did you managed the https issue?

Thanks

Former Member
0 Kudos

Hello Yogendra.

follow Above Blog. This blog got 3 parts. Please follow exactly.

1. You have to configure one Tomcat server and run the .php file which contains the code for handling Json script and POST command. SAP accepts the data in Json format only.

2. Simply execute Execute php file by calling GET command through your ESP8266.

3. you can download php file from the blog.

4. I have used ESP8266.

Former Member
0 Kudos

Hello Anton and Vladimir. You guys are correct. I have made my custom board for my sensors project. I am successfully uploading the data to SAP HANA.

Regards,

Naveen

0 Kudos

Hi Naveen,

Perhaps you've already resolved your problem, but anyway I would like to answer here for future reference.

HCP Internet of Things only accepts HTTPS calls. That is - calls on port 443. When you try from the Chrome REST client to call an HTTP:// url, what happens is that the remote server redirects to the HTTPS port, and then the call succeeds. Depending on which rest client you are using - this may be visible or hidden (with my version of Postman i could not understand that it is doing this redirect)

The trick with the AT Firmware of ESP8266 is that it does not support HTTPS, and most probably will not support it, due to the limited amount of memory available.

To overcome this, the best way is to develop a custom Firmware with the Arduino IDE (and the ESP8266 addon). I have just explained this in a . If  you need to control the ESP8266 via UART (e.g. from Arduino, RPI, etc), you can use the built in Serial support of the ESP8266 and create some kind of lightweight commands that you can send and let the ESP8266 do the dirty work

Hope this will help you or somebody else with similar problems

Regards, Vladimir