Add MQTT control #1
8
index.js
8
index.js
@@ -66,13 +66,18 @@ function displayImage(filename) {
|
||||
}
|
||||
|
||||
function displayWifi() {
|
||||
console.log('Displaying wifi connection information for 10 minutes')
|
||||
console.log('Displaying wifi connection information for 10 minutes...')
|
||||
clearTimeout(ticker)
|
||||
frame.display_png('img/wifi.png')
|
||||
frame.show()
|
||||
ticker = setTimeout(displayAlbum, 600000)
|
||||
}
|
||||
|
||||
function skipToNext() {
|
||||
clearTimeout(ticker)
|
||||
displayAlbum()
|
||||
}
|
||||
|
||||
// Subscribe to our MQTT topic...
|
||||
mqttclient.on('connect', () => {
|
||||
mqttclient.subscribe('pictureframe/command')
|
||||
@@ -83,6 +88,7 @@ mqttclient.on('message', (topic, message) => {
|
||||
message = message.toString()
|
||||
console.log('MQTT command received: ' + message)
|
||||
|
||||
if (message == 'skip') skipToNext()
|
||||
if (message == 'wifi') displayWifi()
|
||||
if (message == 'reset') {
|
||||
clearTimeout(ticker)
|
||||
|
||||
16
mqtt-test.js
16
mqtt-test.js
@@ -1,16 +0,0 @@
|
||||
const mqtt = require('mqtt')
|
||||
const client = mqtt.connect('mqtt://mqtt.srv.jnf.me', {
|
||||
clientId: 'pictureframe_' + Math.random().toString(16).substr(2, 8),
|
||||
username: 'pictureframe',
|
||||
password: 'pictureframe'
|
||||
})
|
||||
|
||||
client.on('connect', () => {
|
||||
client.subscribe('pictureframe/#', (err) => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.on('message', (topic, message) => {
|
||||
console.log(topic + ' : ' + message.toString())
|
||||
})
|
||||
Reference in New Issue
Block a user