HTTP GET Request
Hi,
I am able to send my Sensor data to Thingworx using REST calls from ESP8266 ,
but not able to fetch a property value from Thingworx using GET request instead getting 401 error(Unauthorised)
even though there is correct appKey. I can fetch data using Python but in "C " am getting problem.
Please help me where i went wrong.
Thank you!
Here is the code:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include<arduino.h>
#include <ESP8266HTTPClient.h>
#define ACCEPT_TYPE "application/json"
const char* ssid = "D-Link_DIR-615";
const char* password = "cadoptiot@123";
const char TWPlatformBaseURL[] = "http://xxx.ngrok.io:80";
const char appKey[] = "axxxxxxxxxxxxxxxxx8";
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());;
}
void loop()
{
HTTPClient http;
int httpCode = -1;
String response = "";
Serial.print("[httpGetPropertry] begin...");
String fullRequestURL = String(TWPlatformBaseURL) + "/Thingworx/Things/Capacity/Properties/hour?appKey=" + String(appKey);
http.begin(fullRequestURL);
http.addHeader("Accept",ACCEPT_TYPE,false,false);
Serial.println("GET URL>" + fullRequestURL +"<");
// start connection and send HTTP header
httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0)
{
response = http.getString();
Serial.printf("[httpGetPropertry] response code:%d body>",httpCode);
Serial.println(response + "<\n");
} else
{
Serial.printf("[httpGetPropertry] failed, error: %s\n\n", http.errorToString(httpCode).c_str());
}
http.end();
}

