Skip to content

Instantly share code, notes, and snippets.

@RenatoExpert
Created January 24, 2024 21:57
Show Gist options
  • Save RenatoExpert/ef781a8dff67321bc693a35a7f87b2fc to your computer and use it in GitHub Desktop.
Save RenatoExpert/ef781a8dff67321bc693a35a7f87b2fc to your computer and use it in GitHub Desktop.
A simple express webserver that simulates a sensor value
const express = require('express')
const app = express()
const port = 8081
var pressure = 25;
function noise() {
let max = 10;
let min = -10;
let factor = Math.random();
let range = max - min;
let gain = (factor * range) + min;
pressure += gain;
if (pressure < 0) {
pressure = 0;
}
}
setInterval(noise, 1000);
app.get('/', (req, res) => {
res.send(`init ${pressure} end`)
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment