【发布时间】:2018-08-13 12:38:12
【问题描述】:
我目前正在使用这个作为学习示例:
https://os.mbed.com/teams/mqtt/code/MQTTPacket/file/aedcaf7984d5/samples/simple-publish.txt/
但是,某些代码特定于示例使用的任何嵌入式系统。
到目前为止我得到的是:
#include "hw_util.h"
#include "MQTTPacket.h"
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int main (void) {
int i;
float temperatura;
unsigned char buffer[50];
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
int rc = 0;
char buf[200];
int buflen = sizeof(buf);
MQTTString topicString = MQTTString_initializer;
char* payload = "I'm Alive";
int payloadlen = strlen(payload);
int len = 0;
data.clientID.cstring = "Testing";
data.keepAliveInterval = 20;
data.cleansession=1;
data.MQTTVersion=3;
len = MQTTSerialize_connect(buf,buflen,&data);
topicString.cstring="SampleTopic";
len += MQTTSerialize_publish(buf + len, buflen - len, 0, 0, 0, 0, topicString, payload, payloadlen);
printf("Hello world");
rc = 0;
while(1)
{
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
}
}
我下载了 HiveMQ,它是一个代理并且它正在运行:
2018-03-05 19:28:08,195 INFO - 在地址 0.0.0.0 和端口 1883 上启动 TCP 侦听器
现在我想做的是向此代理或 Putty 发送类似“Hello World”的内容,或者发送显示整个 MQTT 有效负载的内容。 C如何处理这个?该文档帮助我了解发生了什么,但并没有真正帮助我编写 C 代码,因为我对它还是很陌生。
【问题讨论】: