cancel
Showing results for 
Search instead for 
Did you mean: 

SAP IoT : Unable to send message using arduino board

Former Member
0 Kudos

Hi All,

I am trying to send data from Arduino UNO R3 board attached to arduino ethernet shield but I am facing some issues.

Below is my code which I am using on arduino board.

#include <Ethernet.h>

#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

byte ip[] = { 192, 168, 0, 107 };

String data = "{\"mode\":\"async\", \"messageType\":\"1\", \"messages\":[{\"value\"=\"true\", \"timestamp\"=\"2015-06-30T01:30:30\"}]}";

const char Server[] = "https://iotmmss0014298301trial.hanatrial.ondemand.com";

const char Url[] = "/com.sap.iotservices.mms/v1/api/http/data/2f071193-41f9-4e2d-a0ee-108f7c797dde";

EthernetClient client;

void setup()

{

  Ethernet.begin(mac, ip);

  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  if (client.connect(Server, 80)) {

    client.println("POST " + String(Url) + " HTTP/1.1");

    client.println("Host: " + String(Server));

    Serial.println("connected");

    client.println("Authorization: Bearer a6af6518708c4f5d669eff8a2f34b44");

    client.println("Content-Type: application/json;charset=utf-8");

    client.print(data);

    client.println();

  } else {

    Serial.println("connection failed");

  }

}

void loop()

{

  if (client.available()) {

    char c = client.read();

    Serial.print(c);

  }

  if (!client.connected()) {

    Serial.println();

    Serial.println("disconnecting.");

    client.stop();

    for(;;)

      ;

  }

}

But there is arduino is unable to make connection to the IoT server link. (getting connection failed as error)

Please help me resolve this issue.

Regards,

Abhishek Bajaj.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi All,

I got the answer to the above question.

SSL is not forced by the IoT Services but by HANA Cloud Platform. Every application deployed in HCP is only available via SSL.

As arduino UNO R3 doesn't support SSL and if you want to use an Arduino on the edge, currently you probably need to stick to Arduino Yun. This board comes with an embedded Linux (OpenWRT) that can do SSL


Thanks and regards,

Abhishek Bajaj.



Former Member
0 Kudos

Hi Abhishek,

Is it possible for you to share code for Arduino Yun sending data to iotmms table. I tried your above code in Arduino Yun but not working, maybe its not meant for Yun.

Thanks

Former Member
0 Kudos

Hi Yogendra,
Above Code may not work. Find below the latest updated working code.

But before running below code you need to install openssl, Curl libraries in Arduino Yun.

Code:

  Process tempread;

  if (!tempread.running())

  {

    tempread.begin("curl");

    tempread.addParameter("-k");

    tempread.addParameter("-H");

    tempread.addParameter("Authorization: Bearer <OAuth Token>");

    tempread.addParameter("-X");

    tempread.addParameter("POST");

    tempread.addParameter("https://<Hana Cloud Platform>/com.sap.iotservices.mms/v1/api/http/data/<Device ID>");

    tempread.addParameter("-H");

    tempread.addParameter("Content-Type:application/json;charset=utf-8");

    tempread.addParameter("--data-binary");

    String titolo = "Arduino";

    String data = "{\"mode\":\"async\", \"messageType\":\"<Message ID>\", \"messages\":[{\"TIMESTAMP\":\"2015-10-07T17:30:30\", \"VALUE\":";

    data.concat(t); // Temperature reading

    data.concat("}]}");

    Serial.println(data);

    tempread.addParameter(data);

    tempread.run();

  }

Please try this code and let me know if you still face any issues

Thanks and regards,

Abhishek Bajaj

Former Member
0 Kudos

Hi Abhishek,

Thank you for sharing the code. Actually I am new in Arduino programming, is it possible for you to share full sketch.

Thanks

Answers (0)