Sending a file via MQTT C [message #1326478] |
Thu, 01 May 2014 15:30  |
Eclipse User |
|
|
|
Hello everyone,
I am trying to send a file (rather than a string; see the example) via MQTT to my broker, however I'm not sure if I'm going about this in the right way:
long GetFileSize(std::string absoluteFile)
{
FILE * myFile;
long size = 0;
myFile = std::fopen(absoluteFile.c_str(), "rb");
if(myFile == NULL)
{
std::cout << "Error opening file/file not found." << std::endl;
}
else
{
std::fseek(myFile, 0, SEEK_END);
size = ftell(myFile);
fclose(myFile);
}
return size;
}
// Add file to the payload.
FILE * pFile = fopen(myFile.c_str(), "rb");
pubmsg.payload = pFile;
pubmsg.payloadlen = GetFileSize(myFile); // Assuming I shouldn't be using sizeof(pFile) here.
pubmsg.qos = g_QOS;
pubmsg.retained = 0;
Is this an acceptable implementation of sending a file using synchronous MQTT?
The broker receives a byte array of the file in unreadable ASCII characters, so I will have to figure out how to interpret this data on the other side as well. Any tips on how to reconstruct this file on the other end for other subscribers to the topic?
Thanks,
Brandon
|
|
|
|
Powered by
FUDForum. Page generated in 0.04198 seconds