Adding mqtt control
This commit is contained in:
33
index.js
33
index.js
@@ -3,10 +3,18 @@ const schedule = require('node-schedule')
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const sharp = require('sharp')
|
const sharp = require('sharp')
|
||||||
const inky = require('@aeroniemi/inky')
|
const inky = require('@aeroniemi/inky')
|
||||||
|
const mqtt = require('mqtt')
|
||||||
|
|
||||||
const frame = new inky.Impression73()
|
const frame = new inky.Impression73()
|
||||||
const folder = './gallery/'
|
const folder = './gallery/'
|
||||||
|
|
||||||
|
// Connect to MQTT
|
||||||
|
const mqttclient = mqtt.connect('mqtt://mqtt.srv.jnf.me', {
|
||||||
|
clientId: 'pictureframe_' + Math.random().toString(16).substr(2, 8),
|
||||||
|
username: 'pictureframe',
|
||||||
|
password: 'pictureframe'
|
||||||
|
})
|
||||||
|
|
||||||
var ticker = false
|
var ticker = false
|
||||||
var filelist = false
|
var filelist = false
|
||||||
|
|
||||||
@@ -57,6 +65,31 @@ function displayImage(filename) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function displayWifi() {
|
||||||
|
console.log('Displaying wifi connection information for 10 minutes')
|
||||||
|
clearTimeout(ticker)
|
||||||
|
frame.display_png('img/wifi.png')
|
||||||
|
frame.show()
|
||||||
|
ticker = setTimeout(displayAlbum, 600000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to our MQTT topic...
|
||||||
|
mqttclient.on('connect', () => {
|
||||||
|
mqttclient.subscribe('pictureframe/command')
|
||||||
|
})
|
||||||
|
|
||||||
|
// Listen for MQTT command messages
|
||||||
|
mqttclient.on('message', (topic, message) => {
|
||||||
|
message = message.toString()
|
||||||
|
console.log('MQTT command received: ' + message)
|
||||||
|
|
||||||
|
if (message == 'wifi') displayWifi()
|
||||||
|
if (message == 'reset') {
|
||||||
|
clearTimeout(ticker)
|
||||||
|
downloadImgs()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// We start by downloading images. Other functions will be called if this is successful...
|
// We start by downloading images. Other functions will be called if this is successful...
|
||||||
downloadImgs()
|
downloadImgs()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user