Closed the-mind closed 4 years ago
@the-mind A zip file is just an array of bytes (i.e. a 13.4 KB zip file is simply 13400 bytes that are structured in the zip file format). To send a zip file with MQTT-C I would do something like this:
void*
array that's at least 13400 bytes)void *
where you copied the zip file is your application message, and the application message size is 13400.The documentation of publishing with MQTT-C is here. Note that application_message
is a void*
(i.e. it's anything...it's just a series of bytes). Note that the application_message
is not a character array--it's a series of raw bytes.
Does that help? Let me know if I can clarify anything.
This is the snippet of my C code as it is. I'm honestly really not that good in C
FILE *filepointer;
void *buffer;
long filelen;
filepointer = fopen("mqtttest.zip", "rb"); // Open the file in binary mode
fseek(filepointer, 0, SEEK_END); // Jump to the end of the file
filelen = ftell(filepointer); // Get the current byte offset in the file
rewind(filepointer); // Jump back to the beginning of the file
buffer = (void *)malloc(filelen * sizeof(void)); // Enough memory for the file
fread(buffer, filelen, 1, filepointer); // Read in the entire file
fclose(filepointer);
mqtt_publish(&client, topic, buffer, filelen + 1, MQTT_PUBLISH_QOS_0);
Where could I be going wrong ? It's not successfully publishing data as it should. Could you also share a snippet that could work? Or help me debug mine?
I took a quick look at your snippet and nothing jumps out at me. Here are a couple suggestions that might help you troubleshoot:
Good luck!
How can I publish a file, like a zip file or a binary using mqtt-c ? Please help.