2015-03-13 57 views
0

我想在PIC单片机中使用SIM 900 gprs调制解调器实现MQTT协议,已经阅读过mqtt文档版本3.1。成功,我可以能够使从GPRS调制解调器连接到MYSERVER使用以下命令IP(117.218.81.15)...在PIC单片机中实现MQTT

  1. AT
  2. AT + CPIN?
  3. AT + CREG?
  4. AT + CGATT?
  5. AT + CIPSHUT
  6. AT + CIPSTATUS
  7. AT + CIPMUX = 0
  8. AT + CSTT = \ “INTERNET \” \ “\” \ “\”
  9. AT + CIICR
  10. AT + CIFSR
  11. AT + CIPSTART = \ “TCP \”,\ “117.218.81.15 \” \ “1883 \”

    作为每MQTT协议我写连接数据包功能的文档。 建立一个tcp连接后,我试图发送connect_packet()函数,我没有得到任何经纪人的确认..请帮我解决这个问题 我检查了wireshark网络分析工具我的数据到达1883 tcp端口,但我不明白为什么我没有得到任何确认?该connect_packet代码为 unsigned char topiclen = 0,time_out1=0,time_out2=0; unsigned char connectdatalen,packetlen; memset(buffer,0,sizeof(buffer)); time_out1 = (time_out >>8) & 0XFF; time_out2 = (time_out & 0XFF); topiclen = strlen(sacketid); connectdatalen = 2 + 6 + 1 + 1 + 2 + 2 + topiclen;
    packetlen = 2 + connectdatalen;
    buffer[0] = 0X10; buffer[1] = connectdatalen; buffer[2] = 0x00; buffer[3] = 0X06; buffer[4] = 'M'; buffer[5] = 'Q'; buffer[6] = 'I'; buffer[7] = 's'; buffer[8] = 'd'; buffer[9] = 'p'; buffer[10] = 0x03; buffer[11] = 0x02; buffer[12] = time_out1; buffer[13] = time_out2; buffer[14] = (topiclen >> 8); buffer[15] = topiclen & 0XFF; for(i=0;i<packetlen;i++) { buffer[(i+16)] = sacketid[i]; } uart_puts(buffer); uart_puts("\x1A");
    在无效的主要函数的代码是 uart_init(9600,16); DelayMs(100); gprs_init(); gprs_tcpconnect(); DelayMs(200); connect_packet("MQTT",180); memset(buffer,0,sizeof(buffer));

+0

您使用哪个经纪商?您是否曾尝试在代理上启用详细日志记录? – hardillb 2015-03-13 09:02:09

+0

蚊子经纪人....亚我已打开详细日志@ hardillb – 2015-03-13 10:07:28

回答

0

希望你已经找到了解决方案,因为它的旧帖子。

您应该检查协议名称“MQIsdp”如果您遵循MQTT-3.1.1规范,我认为它必须是“MQTT”。 MQTT规范说

Blockquote协议名称是一个UTF-8编码的字符串,表示协议名称“MQTT”,如图所示大写。字符串,其偏移量和长度不会被未来版本的MQTT规范所改变。

如果您的协议名称与规范不匹配,代理将会以静默方式丢弃您的数据包。 另外,您必须更新缓冲区数组,因为MQTT在MQTT协议的变量头中占用2 + 4个字节。

谢谢