int main(int argc, char *argv[])
{
	int rc;
	int tmp;
	struct mosquitto *mosq;

	int port = atoi(argv[1]);

	mosquitto_lib_init();

	mosq = mosquitto_new("prop-test", true, NULL);
	mosquitto_connect_callback_set(mosq, on_connect);
	mosquitto_publish_callback_set(mosq, on_publish);
	tmp = MQTT_PROTOCOL_V5;
	mosquitto_opts_set(mosq, MOSQ_OPT_PROTOCOL_VERSION, &tmp);

	rc = mosquitto_connect(mosq, "localhost", port, 60);

	while(run == -1){
		rc = mosquitto_loop(mosq, -1, 1);
	}

	mosquitto_lib_cleanup();
	return run;
}
Example #2
0
int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg)
{
    int rc;

    if(cfg->will_topic && mosquitto_will_set(mosq, cfg->will_topic,
            cfg->will_payloadlen, cfg->will_payload, cfg->will_qos,
            cfg->will_retain)) {

        if(!cfg->quiet) fprintf(stderr, "Error: Problem setting will.\n");
        mosquitto_lib_cleanup();
        return 1;
    }
    if(cfg->username && mosquitto_username_pw_set(mosq, cfg->username, cfg->password)) {
        if(!cfg->quiet) fprintf(stderr, "Error: Problem setting username and password.\n");
        mosquitto_lib_cleanup();
        return 1;
    }
#ifdef WITH_TLS
    if((cfg->cafile || cfg->capath)
            && mosquitto_tls_set(mosq, cfg->cafile, cfg->capath, cfg->certfile, cfg->keyfile, NULL)) {

        if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS options.\n");
        mosquitto_lib_cleanup();
        return 1;
    }
    if(cfg->insecure && mosquitto_tls_insecure_set(mosq, true)) {
        if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS insecure option.\n");
        mosquitto_lib_cleanup();
        return 1;
    }
#  ifdef WITH_TLS_PSK
    if(cfg->psk && mosquitto_tls_psk_set(mosq, cfg->psk, cfg->psk_identity, NULL)) {
        if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS-PSK options.\n");
        mosquitto_lib_cleanup();
        return 1;
    }
#  endif
    if(cfg->tls_version && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)) {
        if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS options.\n");
        mosquitto_lib_cleanup();
        return 1;
    }
#endif
    mosquitto_max_inflight_messages_set(mosq, cfg->max_inflight);
#ifdef WITH_SOCKS
    if(cfg->socks5_host) {
        rc = mosquitto_socks5_set(mosq, cfg->socks5_host, cfg->socks5_port, cfg->socks5_username, cfg->socks5_password);
        if(rc) {
            mosquitto_lib_cleanup();
            return rc;
        }
    }
#endif
    mosquitto_opts_set(mosq, MOSQ_OPT_PROTOCOL_VERSION, &(cfg->protocol_version));
    return MOSQ_ERR_SUCCESS;
}
Example #3
0
int mosquittopp::opts_set(enum mosq_opt_t option, void *value)
{
	return mosquitto_opts_set(m_mosq, option, value);
}