-->
Page 1 of 1

HTTP Response 404, when trying to post to IBM Cloud

PostPosted: Wed Apr 11, 2018 9:06 am
by katappa
Hello,
I am trying to send data to IBM using the code explained here

When I try the same code, I was getting an error. So I have slightly modified the payload, but I am getting an HTTP POST Response 404. Could you please check what am I doing wrong?
My code is:

[code#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

//-------- Customise these values -----------
const char* ssid = "Connect";


//#define ORG "u7y3d9" // your organization or "quickstart"
//#define DEVICE_TYPE "ESP8266-YourDeviceName" // use this default for quickstart or customize to your registered device type
//#define DEVICE_ID "ESP8266" // use this default for quickstart or customize to your registered device id

#define ORG "quickstart" // your organization or "quickstart"
#define DEVICE_TYPE "ESP8266" // use this default for quickstart or customize to your registered device type
#define DEVICE_ID "Test1" // use this default for quickstart or customize to your registered device id


#define TOKEN "test-token" // not used with "quickstart"
#define EVENT "myEvent" // use this default or customize to your event type
//-------- Customise the above values --------

String url = "http://"ORG".internetofthings.ibmcloud.com/api/v0002/device/types/"DEVICE_TYPE"/devices/"DEVICE_ID"/events/"EVENT;

void setup()
{
Serial.begin(115200); Serial.println();
if (ORG != "quickstart") { // for POST URL doc see: https://docs.internetofthings.ibmcloud. ... evice.html
url.replace("http://", String("https://use-token-auth:") + TOKEN + "@");
}
Serial.print("IoT Foundation URL: "); Serial.println(url);

Serial.print("Connecting to: "); Serial.print(ssid);
WiFi.begin(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.print("nWiFi connected, IP address: "); Serial.println(WiFi.localIP());
}

void loop()
{
HTTPClient http;
http.begin(url);
http.addHeader("Content-Type", "application/json");

// a simple payload, for doc on payload format see: https://docs.internetofthings.ibmcloud. ... yload.html
// String payload = String("{ \"d\": {\"aMessage\": \") + millis()/1000 + \"} }\");

String payload = "{ \"d\": {\"aMessage\": \"4\"} }";

Serial.print("POST payload: "); Serial.println(payload);
int httpCode = http.POST(payload);
Serial.print("HTTP POST Response: ");
Serial.println(httpCode); // HTTP code 200 means ok
http.end();

delay(10000);
}][/code]

I am getting the same response of HTTP RESPONSE 404 whether using "quickstart" or not.

WiFi is getting connected but I am not able to send data. Can someone please share what am I doing wrong?

Re: HTTP Response 404, when trying to post to IBM Cloud

PostPosted: Thu Apr 12, 2018 1:51 am
by jankop
May be:

Code: Select allString url = "http://" + String(ORG) + ".internetofthings.ibmcloud.com/api/v0002/device/types/" + String(DEVICE_TYPE) + "/devices/" + String(DEVICE_ID) + "/events/" + String(EVENT);




No, you're good, the translator translates it correctly.

Re: HTTP Response 404, when trying to post to IBM Cloud

PostPosted: Thu Apr 12, 2018 4:51 am
by torntrousers
That article you reference is over two years old now, I don't work at IBM any longer and haven't kept the article updated. From a quick look at the Watson IoT doc it looks like the HTTP access to their IoT platform has changed a bit, the doc is here: https://console.bluemix.net/docs/servic ... i.html#api
I'll have a go at an updated sketch but it may take a few days before i have time.

Re: HTTP Response 404, when trying to post to IBM Cloud

PostPosted: Thu Apr 12, 2018 5:18 am
by torntrousers
From quick try with curl to the quickstart service - this updated url seems to work:

Code: Select allhttp://quickstart.messaging.internetofthings.ibmcloud.com/api/v0002/device/types/quickstart/devices/foo/events/myevent


So now includes the word "messaging" in the domain name and it looks like when using the quickstart service the device type must be "quickstart".