on 07-08-2015 7:23 PM
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
89 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.