Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- // function to create file from base64 encoded string
- function base64_decode(base64str, file) {
- // create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
- var bitmap = new Buffer(base64str, 'base64');
- // write buffer to file
- fs.writeFileSync(file, bitmap);
- }
- var mqtt = require('mqtt');
- var options = {
- username: 'JackRoboticS',
- password:'tlXrjyglDSg69lQxaENkqTX5I6SsBC0ZFSSbBFS8',
- port: 1883,
- host: 'service.anto.io',
- clientId: 'JackRoboticS_API'+Math.random()
- };
- var client = mqtt.connect(options);
- client.on('connect', function () {
- client.subscribe('channel/JackRoboticS/image/image'); // < เลือก subscribe ข้อมูลจาก mqtt
- });
- client.on('message', function (topic, message) {
- var MSG = message.toString();
- base64_decode(MSG, 'savefilename.png'); //< บันทึกไฟล์ลง disk
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement