I'm currently using this as a learning example:
https://os.mbed.com/teams/mqtt/code/MQTTPacket/file/aedcaf7984d5/samples/simple-publish.txt/
However, some of the code is specific to whatever embedded system the example is using.
What I got so far is:
#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);
}
}
I downloaded HiveMQ, which is a Broker and it's running:
2018-03-05 19:28:08,195 INFO - Starting TCP listener on address 0.0.0.0 and port 1883
Now what I want to do, is send something like "Hello World" to this Broker or to Putty or something that would display the entire MQTT payload. How does C handle this? The documentation helped me understand what's going on but didnt really help me write C code, since I am still very new to it.