Mqtt消息未从C发布到Siddhi

时间:2018-08-07 14:00:26

标签: c mqtt paho siddhi

我正在尝试将mqtt消息发布到Siddhi Stream处理器。我可以从C程序发送消息,并且rc为0。没有连接问题,但是消息没有发布到Siddhi。

我要发布mqtt消息的C代码是:

#define ADDRESS     "tcp://test.mosquitto.org:1883"
#define CLIENTID    "mqttClient"
#define TOPIC       "mqttTopic"
#define PAYLOAD     "Hello World!"
#define QOS         0
#define TIMEOUT     30000L

int main(int argc, char* argv[])
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;
int rc;
int success;

MQTTClient_create(&client, ADDRESS, CLIENTID,MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 60;
conn_opts.cleansession = 1;

rc = MQTTClient_connect(client, &conn_opts);

if (rc!= MQTTCLIENT_SUCCESS)
{
    printf("Failed to connect, return code %d\n", rc);
    exit(EXIT_FAILURE);
}
if(rc == 0){
    pubmsg.payload = PAYLOAD;
    pubmsg.payloadlen = strlen("hello");
    pubmsg.qos = QOS;
    pubmsg.retained = 0;
    success=MQTTClient_publish(client,TOPIC,pubmsg.payloadlen,"hello",pubmsg.qos,pubmsg.retained,NULL);  
    printf("%d\n", success); 
}
//MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token);
rc = MQTTClient_waitForCompletion(client, token, TIMEOUT);
if(rc==0){
    printf("Message with delivery token %d delivered\n", token);
}else{
    printf("Message not delivered");
}
MQTTClient_disconnect(client, 10000);
MQTTClient_destroy(&client);
return rc;
}

我不明白iam在犯什么错误。任何建议都会对我有帮助。

0 个答案:

没有答案