I'd like to send (jpeg) image-data from an arduino to a mosca-host using MQTT. On the arduino I use PubSubClient-library. The image-data is stored on a SPI-connected FIFO.
Arduino Sketch:
size_t len = myMemory.read_fifo_length();
static const size_t bufferSize = 2048;
static uint8_t buffer[bufferSize] = {0xFF};
while (stuff) {
size_t copy = (stuff < bufferSize) ? stuff : bufferSize;
myMemory.transferBytes(&buffer[0], &buffer[0], copy);
client.publish("transfer", &buffer[0], will_copy);
stuff -= copy;
}
And on the server-side I use NodeJS with mosca:
var image;
server.on('published', function(packet, client) {
if(packet.topic == "transfer")
image+=packet.payload;
if (packet.topic == "eof")
{
fs.writeFile(client.id+".jpg", image, (err) => {
if (err) throw err;
console.log('It\'s saved!');
});
}
});
The Data that arrives has, when it's saved to a file, even the right JFIF-header but it's rubbish.
any suggestions?