adapted index.html to reflect websocket changes
This commit is contained in:
parent
fc45bf95af
commit
0d63c7cc4b
@ -8,6 +8,20 @@ const char *INDEX_HTML = R"(<!DOCTYPE html>
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-size: 4vw;
|
font-size: 4vw;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
text-align: left;
|
||||||
|
font-weight: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1200px) {
|
@media (min-width: 1200px) {
|
||||||
@ -18,9 +32,10 @@ const char *INDEX_HTML = R"(<!DOCTYPE html>
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<pre id="content"></pre>
|
<table id="content"></table>
|
||||||
<pre id="time"></pre>
|
<pre id="time"></pre>
|
||||||
<script>
|
<script>
|
||||||
|
const map = new Map();
|
||||||
const time = document.getElementById("time");
|
const time = document.getElementById("time");
|
||||||
const content = document.getElementById("content");
|
const content = document.getElementById("content");
|
||||||
|
|
||||||
@ -48,10 +63,17 @@ const char *INDEX_HTML = R"(<!DOCTYPE html>
|
|||||||
socket.addEventListener('open', _ => console.log('websocket connected'));
|
socket.addEventListener('open', _ => console.log('websocket connected'));
|
||||||
socket.addEventListener('message', event => {
|
socket.addEventListener('message', event => {
|
||||||
last = Date.now();
|
last = Date.now();
|
||||||
updateTime();
|
|
||||||
const parsed = JSON.parse(event.data);
|
const parsed = JSON.parse(event.data);
|
||||||
console.log("websocket received", parsed);
|
map.set(parsed.name, parsed);
|
||||||
content.innerText = JSON.stringify(parsed, null, 2);
|
const innerHTML = `<th>${parsed.name}</th><td>${parsed.value?.toFixed(1) || '-'}</td>`;
|
||||||
|
let tr = document.getElementById(parsed.name);
|
||||||
|
if (!tr) {
|
||||||
|
tr = document.createElement("tr");
|
||||||
|
tr.setAttribute("id", parsed.name);
|
||||||
|
content.appendChild(tr);
|
||||||
|
}
|
||||||
|
tr.innerHTML = innerHTML;
|
||||||
|
updateTime();
|
||||||
});
|
});
|
||||||
socket.addEventListener('close', _ => {
|
socket.addEventListener('close', _ => {
|
||||||
console.log('websocket disconnected');
|
console.log('websocket disconnected');
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#ifndef DALLAS_H
|
#ifndef DALLAS_H
|
||||||
#define DALLAS_H
|
#define DALLAS_H
|
||||||
|
|
||||||
#include "../log.h"
|
|
||||||
#include "OneWire.h"
|
|
||||||
#include "DallasTemperature.h"
|
#include "DallasTemperature.h"
|
||||||
|
#include "OneWire.h"
|
||||||
|
#include "../log.h"
|
||||||
|
|
||||||
#define DALLAS_INTERVAL_MILLISECONDS 2000
|
#define DALLAS_INTERVAL_MILLISECONDS 2000
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public:
|
|||||||
const auto count = sensors.getDeviceCount();
|
const auto count = sensors.getDeviceCount();
|
||||||
if (count != 0) {
|
if (count != 0) {
|
||||||
uint64_t address;
|
uint64_t address;
|
||||||
for (int index = 0; index < count; ++index) {
|
for (auto index = 0; index < count; ++index) {
|
||||||
sensors.getAddress(reinterpret_cast<uint8_t *>(&address), index);
|
sensors.getAddress(reinterpret_cast<uint8_t *>(&address), index);
|
||||||
info("Dallas %d/%d 0x%016llX = %5.1f^C", index + 1, count, address, sensors.getTempC(reinterpret_cast<uint8_t *>(&address)));
|
info("Dallas %d/%d 0x%016llX = %5.1f^C", index + 1, count, address, sensors.getTempC(reinterpret_cast<uint8_t *>(&address)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,8 +58,9 @@ public:
|
|||||||
const auto dueToTime = sentInterval != 0 && sentInterval != now / overdueSeconds;
|
const auto dueToTime = sentInterval != 0 && sentInterval != now / overdueSeconds;
|
||||||
const auto changed = dueToNAN || dueToThreshold || dueToTime;
|
const auto changed = dueToNAN || dueToThreshold || dueToTime;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
info("%s = %f", name.c_str(), currentValue);
|
||||||
mqttPublish(name + "/retain", String(currentValue), RETAIN);
|
mqttPublish(name + "/retain", String(currentValue), RETAIN);
|
||||||
websocketSendAll(toJson(false));
|
websocketSendAll(toJson(true));
|
||||||
sentValue = currentValue;
|
sentValue = currentValue;
|
||||||
sentInterval = now / overdueSeconds;
|
sentInterval = now / overdueSeconds;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user