Compare commits
3 Commits
63807747cd
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5684e7e9e4 | |||
|
|
e8502519e4 | ||
|
|
be56a5f791 |
39
index.js
39
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,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...
|
// We start by downloading images. Other functions will be called if this is successful...
|
||||||
downloadImgs()
|
downloadImgs()
|
||||||
|
|
||||||
|
|||||||
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