Я работаю над OpenPicus WiFi Pro, и я пытаюсь получить Xively с mqtt работает. Вот мой код:
Я просто получаю «SUBACK обнаружено», но когда данные изменяются на сервере, Picus ничего не запускает.
Больше информации здесь:
https://github.com/OpenPicus/lib_mqtt а также
http://wiki.openpicus.com/index.php/MQTT
#include "taskFlyport.h"#include "mqtt.h"
#define APIKEY "xxx"#define FEED_ID xxx
#define XIVELY_API "api.xively.com"#define XIVELY_PORT "1883"
void FlyportTask()
{
char buffer[250];
char str[250];
int len = 0;
TCP_SOCKET sock = INVALID_SOCKET;
WFConnect(WF_DEFAULT);
while(WFGetStat() != CONNECTED);
vTaskDelay(25);
while(WFGetStat() == CONNECTED)
{
UARTWrite(1,"Flyport Wi-fi G connected...hello world!\r\n");
sock = TCPClientOpen(XIVELY_API, XIVELY_PORT);
int cnt = 0;
while(!TCPisConn(sock))
{
if(cnt==30)
{
UARTWrite(1,"Xively timeout, try again in 5s..");
sock = INVALID_SOCKET;
vTaskDelay(500);
break;
}
vTaskDelay(25);
cnt++;
}
if(TCPisConn(sock))
{
UARTWrite(1,"TCP is connected to the Server, logging in..");
len = MQTT_Connect(buffer, FEED_ID, 120, APIKEY, NULL, NULL, NULL, 1, NULL, NULL);
TCPWrite(sock, buffer, len);
len = 0;
}
while(TCPisConn(sock))
{
switch (MQTT_Response_Sniffer(sock))
{
case MQTT_CONNACK:
UARTWrite(1,"\r\nCONNACK detected, subscribing datastreams..\r\n");
sprintf(str, "%s/v2/feeds/%d.json", APIKEY, FEED_ID);
len = MQTT_Subscribe(buffer, str, 50, MQTT_QOS_0);
TCPWrite(sock, buffer, len);
len = 0;
break;
case MQTT_PUBLISH:
{
UARTWrite(1,"\r\nPUBLISH detected\r\n");
QWORD lenmess=MQTT_Last_Response_Length();
char message[lenmess];
MQTT_Last_Response_Message(message);
QWORD i=0;
for(i=0;i<lenmess;i++)
UARTWriteCh(1,message[i]);
}
break;
case MQTT_PUBACK:
UARTWrite(1,"\r\nPUBACK detected\r\n");
break;
case MQTT_PUBREC:
UARTWrite(1,"\r\nPUBREC detected\r\n");
break;
case MQTT_PUBCOMP:
UARTWrite(1,"\r\nPUBCOMP detected\r\n");
break;
case MQTT_SUBACK:
UARTWrite(1,"\r\nSUBACK detected\r\n");
break;
case MQTT_UNSUBACK:
UARTWrite(1,"\r\nUNSUBACK detected\r\n");
break;
case MQTT_PINGRESP:
UARTWrite(1,"\r\nPINGRESP detected\r\n");
break;
}
}
}
}
Задача ещё не решена.