Created
January 24, 2024 21:57
-
-
Save RenatoExpert/ef781a8dff67321bc693a35a7f87b2fc to your computer and use it in GitHub Desktop.
A simple express webserver that simulates a sensor value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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