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.