Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » unable to authenticate bluemix connection(Cannot access bluemix cloud device with c++ application)
unable to authenticate bluemix connection [message #1770494] Sat, 12 August 2017 17:24 Go to next message
Mohammed Ubaid is currently offline Mohammed UbaidFriend
Messages: 4
Registered: August 2017
Junior Member
Hello all,

I am using the eclipse paho mqtt c library to connect to bluemix. Have done my part on the bluemix cloud and created an IoT device and registered the same, have generated API keys.

I am writing my raspberry pi cpu temperature on bluemix cloud, But when i try to connect to the device using the below code, my code exits with an rc state of 5.

And i see log messages on the cloud saying "Closed connection, unable to authenticate" .

I have tried a lot, but rc is always 5.

Appreciate your assistance.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string.h>
#include "MQTTClient.h"
#define CPU_TEMP "/sys/class/thermal/thermal_zone0/temp"
using namespace std;

#define ADDRESS "tcp://<org_ID>.messaging.internetofthings.ibmcloud.com:1883" //have used organization ID
#define CLIENTID "d:<org_ID>:<Device_type>:<space_ID>" //have used organization ID, Device type field and my space ID.
#define AUTHMETHOD "use-token-auth"
#define AUTHTOKEN "<authentication_token>"
#define TOPIC "iot-2/evt/status/fmt/json"
#define QOS 1
#define TIMEOUT 10000L

float getCPUTemperature(){
int CPUTemp;
fstream fs;
fs.open(CPU_TEMP, fstream::in);
fs >> CPUTemp;
fs.close();
return (((float)CPUTemp)/1000);
}

int main(int argc, char* argv[]) {
MQTTClient client;
MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;
MQTTClient_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_NONE, NULL);

opts.keepAliveInterval = 20;
opts.cleansession = 1;
opts.username = AUTHMETHOD;
opts.password = AUTHTOKEN;
int rc;
if ((rc = MQTTClient_connect(client, &opts)) != MQTTCLIENT_SUCCESS)
{
cout<<"Failed to connect "<<rc<<endl; // Here my code exits with rc=5
return -1;
}


stringstream message;

message <<"{\"d\":{\"Temp\":"<<getCPUTemperature()<<"}}";
pubmsg.payload = (char*) message.str().c_str();
pubmsg.payloadlen = message.str().length();
pubmsg.qos = QOS;
pubmsg.retained = 0;
MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token);
cout<< "Waiting for " << (int) (TIMEOUT/1000) << "seconds for pub of"<<message.str()<<"\non topic"<<TOPIC<<"for ClientID:"<<CLIENTID<<endl;
rc = MQTTClient_waitForCompletion(client, token, TIMEOUT);
cout<<"Message with token"<< (int)token<<"delivered"<<endl;
MQTTClient_disconnect(client,10000);
MQTTClient_destroy(&client);
return rc;
}
Re: unable to authenticate bluemix connection [message #1770568 is a reply to message #1770494] Mon, 14 August 2017 15:01 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Did you mean to post to the Paho group? https://www.eclipse.org/forums/index.php/f/247/

This group is for using the C/C++ IDE.
Re: unable to authenticate bluemix connection [message #1770616 is a reply to message #1770568] Tue, 15 August 2017 07:47 Go to previous message
Mohammed Ubaid is currently offline Mohammed UbaidFriend
Messages: 4
Registered: August 2017
Junior Member
Yeah, posting on paho group.
Previous Topic:Specifying the c++11 standard in Eclipse Luna
Next Topic:Qt integration into Eclipse CDT Neon 2
Goto Forum:
  


Current Time: Tue Apr 23 15:28:02 GMT 2024

Powered by FUDForum. Page generated in 0.03326 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top