Switch from socket.io to REST for cadence streaming in attempt to fix timeout issue

This commit is contained in:
Peter Stockings
2023-01-26 21:53:54 +11:00
parent ef3de84621
commit 9ec6693031
4 changed files with 35 additions and 11 deletions

View File

@@ -24,6 +24,7 @@ async function connect(props) {
console.log("> Notifications started");
characteristic.addEventListener("characteristicvaluechanged", props.onChange);
console.log("> Characteristic value changed event listener added");
/*
socket = io({
reconnection: true,
reconnectionDelay: 1000,
@@ -43,6 +44,7 @@ async function connect(props) {
}
// else the socket will automatically try to reconnect
});
*/
}
async function disconnect() {
@@ -88,7 +90,15 @@ function parseCSC(e) {
if (prevRes) {
let rpm = revsToRPM(prevRes, res);
if (rpm > 0)
socket.emit("message", { rpm: parseFloat(rpm.toFixed(2)), id: 1 });
//socket.emit("message", { rpm: parseFloat(rpm.toFixed(2)), id: 1 });
fetch("/cadence", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify({ rpm: parseFloat(rpm.toFixed(2)), id: 1 }),
});
}
prevRes = res;
return res;