Compare commits

..

3 Commits

Author SHA1 Message Date
5684e7e9e4 Merge pull request 'Add MQTT control' (#1) from mqtt into main
Reviewed-on: #1
2025-05-16 20:55:57 +00:00
Jason Williams
e8502519e4 Adding command to skip to the next image, and removing mqtt test code 2025-05-16 14:53:21 -06:00
Jason Williams
be56a5f791 Adding mqtt control 2025-05-16 14:37:44 -06:00
2 changed files with 39 additions and 16 deletions

View File

@@ -3,10 +3,18 @@ const schedule = require('node-schedule')
const fs = require('fs')
const sharp = require('sharp')
const inky = require('@aeroniemi/inky')
const mqtt = require('mqtt')
const frame = new inky.Impression73()
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 filelist = false
@@ -57,6 +65,37 @@ 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)
}
function skipToNext() {
clearTimeout(ticker)
displayAlbum()
}
// 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 == 'skip') skipToNext()
if (message == 'wifi') displayWifi()
if (message == 'reset') {
clearTimeout(ticker)
downloadImgs()
}
})
// We start by downloading images. Other functions will be called if this is successful...
downloadImgs()

View File

@@ -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())
})