Update ui-test video

This commit is contained in:
Thomas Nordquist
2019-06-18 14:49:48 +02:00
parent d92ea0bad7
commit de7b461b4e
6 changed files with 95 additions and 15 deletions

View File

@@ -21,8 +21,8 @@ function connectMqtt(): Promise<mqtt.MqttClient> {
})
}
function temperature(base = 18, sineCoefficient = 2, offset = 0) {
const temp = base + Math.sin(Date.now() / 1000 / 5 + offset) * sineCoefficient + Math.random()
function temperature(base = 18, sineCoefficient = 2, offset = 0, speed = 1) {
const temp = base + Math.sin((Date.now() * speed) / 1000 / 5 + offset) * sineCoefficient + Math.random()
return String(Math.round(temp * 100) / 100)
}
@@ -81,6 +81,21 @@ function generateData(client: mqtt.MqttClient) {
}
})
const coffeeMaker = {
heater: 'on',
temperature: 92.5,
waterLevel: 0.5,
update: new Date(),
}
intervals.push(
setInterval(() => {
const newTemp = parseFloat(temperature(90.3, -5, 0, 3))
coffeeMaker.heater = newTemp > coffeeMaker.temperature ? 'on' : 'off'
coffeeMaker.temperature = newTemp
client.publish('kitchen/coffee_maker', JSON.stringify(coffeeMaker), { retain: true, qos: 2 })
}, 1500)
)
intervals.push(setInterval(() => client.publish('kitchen/temperature', temperature()), 1500))
intervals.push(setInterval(() => client.publish('kitchen/humidity', temperature(60, -5, 0)), 1800))