Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By katappa
#75286 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?
User avatar
By jankop
#75304 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.
User avatar
By torntrousers
#75308 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.
User avatar
By torntrousers
#75312 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".