Hi, i am trying to upload sensor's data to HCP, in this setup I am using Arduino and ESP8266 and LM35 temperature sensor. when i try to connect to HCP it works and when I try to do a POST to HCP it gives timeout error.
Below is my circuit and Code.
(plz ignore the led)
#include <SoftwareSerial.h> #include <WiFiEsp.h> // ========== start configuration ========== // WiFi configuration const char* ssid = "XXXX"; const char* pass = "XXXXXXXXXXX"; // SAP HCP specific configuration const char* host1 = "iotmmsXXXXXXXXXXtrial.hanatrial.ondemand.com"; String device_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; String message_type_id = "XXXXXXXXXXXXXXXXXXXX"; String oauth_token="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; float temperature = 0.0; // ========== end configuration ============ String url = "/com.sap.iotservices.mms/v1/api/http/data/" + device_id; <br>const int ledPin = 13; const int TSPin = A0; const int httpsPort = 8443; //80//443//13 int status = WL_IDLE_STATUS; WiFiEspClient client; SoftwareSerial Serial1(2,3); //RX,TX void setup() { Serial.begin(9600); Serial1.begin(9600); WiFi.init(&Serial1); // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); // don't continue while (true); } // attempt to connect to WiFi network while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); } // I GET TO CONNECT THE NETWORK Serial.println("You're connected to the network"); Serial.print("connecting to "); Serial.println(host1); if (!client.connect(host1, httpsPort)) { Serial.println("connection failed"); return; } else if(client.connect(host1, httpsPort)) { Serial.println("connected to host"); } } void loop() { int sensorVal = analogRead(TSPin); digitalWrite(ledPin,HIGH); delay(200); digitalWrite(ledPin,LOW); float voltage = (sensorVal/1024.0)*5.0; //print new value to serial monitor Serial.print("Volts: "); Serial.print(voltage); //convert the voltage to temperature in degrees temperature = (voltage)*100; // Serial.print(", degrees C: "); Serial.println(temperature); Serial.println(); String post_payload = "{\"mode\":\"async\", \"messageType\":\"" + message_type_id + "\", \"messages\":[{\"Temprature\":"+temperature+"}]}"; int Payload_length = post_payload.length(); Serial.print("requesting URL: "); Serial.println(url); Serial.print("post_payload: "); Serial.println(post_payload); Serial.print("Payload_length:"); Serial.println(Payload_length); if (client.connect(host1,httpsPort)) { Serial.println("Connecting...");///////I GET THE CLIENT IS CONNECTED//// client.print(String("POST ") + url + " HTTP/1.0\r\n" + "Host: " + host1 + "\r\n" + "Connection: close\r\n" + "Content-Type: application/json;charset=utf-8\r\n" + "Authorization: Bearer " + oauth_token + "\r\n" + "Content-Length: " + post_payload.length() + "\r\n\r\n" + post_payload + "\r\n\r\n"); //////////// GET ERROR TIME OUT OVER HERE ON POST////////////////////// } else { // if you couldn't make a connection Serial.println("Connection failed"); } Serial.println("request sent"); Serial.println("reply was:"); Serial.println("=========="); while(client.connected()) { // There is a client connected. Is there anything to read? while(client.available() > 0) { char c = client.read(); Serial.print(c); } Serial.println(); Serial.println("Waiting for more data..."); delay(100); // Have a bit of patience... } Serial.println("=========="); Serial.println("Closing connection and waiting 15 seconds"); delay(15000); }