Mqtt- mosquitto basic function is not working

Asked by Gopal

Hai friends,
               i dont know what i do wrong.. am new in MQTT using mosquitto ... i need to develop client application ..but basic function is not working i compile that code means no error display and no printf including not working.pleae guide me...

 #include <stdio.h>
#include <mosquitto.h>
int main(int argc, char *argv[])
{
    char id[30];
    int i;
    char *host = "localhost";
    int port = 1883;
    int keepalive = 60;
    bool clean_session = true;
    struct mosquitto *mosq = NULL;
    int rc;
    rc = mosquitto_lib_init();
    printf("Connection Starting\n");
    return 0;
}

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

At the moment all your code does is run the library initialisation. The documentation states the following regarding mosquitto_lib_init(): "Must be called before any other mosquitto functions." It runs e.g. winsock initialisation on Windows and/or OpenSSL initialisation if required. That is all.

I would suggest that you go back to the documentation and examples.

Revision history for this message
andypiper (andypiperuk) said :
#2

Compiles and "works" for me:

$ gcc mqtt.c -l mosquitto -o mqttdemo
$ ./mqttdemo
Connection Starting

I would not expect to see anything more than this. All you do in the code is set some variables, and then initialise use of a library and print something to stdout. You never actually call any useful MQTT or mosquitto library code.

Can you help with this problem?

Provide an answer of your own, or ask Gopal for more information if necessary.

To post a message you must log in.