update
This commit is contained in:
parent
d3abe2eeda
commit
444e466762
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,6 +9,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cron": "^2.1.0",
|
||||
"dotenv": "^16.0.2",
|
||||
"easyimage": "^3.1.1",
|
||||
"express": "^4.18.1",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
@ -424,6 +425,14 @@
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.2",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.2.tgz",
|
||||
"integrity": "sha512-JvpYKUmzQhYoIFgK2MOnF3bciIZoItIIoryihy0rIA+H4Jy0FmgyKYAHCTN98P5ybGSJcIFbh6QKeJdtZd1qhA==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/easyimage": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/easyimage/-/easyimage-3.1.1.tgz",
|
||||
@ -2186,6 +2195,11 @@
|
||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
||||
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg=="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.0.2",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.2.tgz",
|
||||
"integrity": "sha512-JvpYKUmzQhYoIFgK2MOnF3bciIZoItIIoryihy0rIA+H4Jy0FmgyKYAHCTN98P5ybGSJcIFbh6QKeJdtZd1qhA=="
|
||||
},
|
||||
"easyimage": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/easyimage/-/easyimage-3.1.1.tgz",
|
||||
|
@ -16,6 +16,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cron": "^2.1.0",
|
||||
"dotenv": "^16.0.2",
|
||||
"easyimage": "^3.1.1",
|
||||
"express": "^4.18.1",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
|
@ -136,6 +136,7 @@
|
||||
<button onclick="client.emit('action', {action:'flash'})">flash</button>
|
||||
<br>
|
||||
<button onclick="client.emit('action', {action:'temp'})">temp</button>
|
||||
<div id="rpis"></div>
|
||||
|
||||
<script src="socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
@ -155,6 +156,14 @@
|
||||
}
|
||||
}
|
||||
})
|
||||
client.on('data', (data) => {
|
||||
rpis.innerHTML = ''
|
||||
data.forEach(rpi => {
|
||||
const p = document.createElement('p')
|
||||
p.innerHTML = `hostname: ${rpi.hostname}<br>cpu load: ${rpi.cpu.load}<br>cpu temperature: ${rpi.cpu.temperature}<br>memory total: ${rpi.memory.total}<br>memory available: ${rpi.memory.available}`
|
||||
rpis.appendChild(p)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
36
sensehat.js
36
sensehat.js
@ -1,12 +1,15 @@
|
||||
require('dotenv').config()
|
||||
const port = process.env.PORT || 3000
|
||||
const express = require('express')
|
||||
const socketio = require('socket.io')
|
||||
const CronJob = require('cron').CronJob
|
||||
const request = require('request')
|
||||
const sense = require('sense-hat-led').sync
|
||||
const app = express()
|
||||
const server = app.listen(3000, '0.0.0.0', () => console.log('server is running'))
|
||||
const server = app.listen(port, '0.0.0.0', () => console.log(`server is running on port ${port}`))
|
||||
const io = socketio(server)
|
||||
app.use(express.static('public'))
|
||||
sense.clear()
|
||||
sense.setRotation(180)
|
||||
sense.lowLight = true
|
||||
|
||||
@ -22,7 +25,6 @@ const leds = [
|
||||
[0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0],
|
||||
]
|
||||
read_all_leds(0)
|
||||
io.emit('leds', leds)
|
||||
|
||||
let zhao_server_errors = 0
|
||||
@ -52,6 +54,24 @@ const job = new CronJob(
|
||||
true
|
||||
)
|
||||
|
||||
// const rpistatus = new CronJob(
|
||||
// '*/5 * * * * *',
|
||||
// async () => {
|
||||
// request('http://zhao:4000', (err, res, body) => {
|
||||
// if (res.statusCode == 200) {
|
||||
// io.emit('data', body)
|
||||
// }
|
||||
// })
|
||||
// request('http://pi:4000', (err, res, body) => {
|
||||
// if (res.statusCode == 200) {
|
||||
// io.emit('data', body)
|
||||
// }
|
||||
// })
|
||||
// },
|
||||
// null,
|
||||
// true
|
||||
// )
|
||||
|
||||
io.on('connection', (client) => {
|
||||
client.emit('leds', leds)
|
||||
client.on('action', ({ action, x, y }) => {
|
||||
@ -81,6 +101,7 @@ io.on('connection', (client) => {
|
||||
break
|
||||
case 'temp':
|
||||
read_all_leds()
|
||||
get_rpis_info()
|
||||
break
|
||||
default:
|
||||
break
|
||||
@ -97,3 +118,14 @@ function read_all_leds(value = null) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function get_rpis_info() {
|
||||
const rpis = []
|
||||
request('http://zhao:4000', (err, res, body) => {
|
||||
if (res.statusCode == 200) rpis.push(JSON.parse(body))
|
||||
request('http://pi:4000', (err, res, body) => {
|
||||
if (res.statusCode == 200) rpis.push(JSON.parse(body))
|
||||
io.emit('data', rpis)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user