Skip to content

Instantly share code, notes, and snippets.

@SvizelPritula
Created May 18, 2020 11:47
Show Gist options
  • Save SvizelPritula/ccbca35cf42c3141f1256ca3363813dd to your computer and use it in GitHub Desktop.
Save SvizelPritula/ccbca35cf42c3141f1256ca3363813dd to your computer and use it in GitHub Desktop.
#include <DHT.h>
DHT dht(3, DHT11);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
Serial.print(temperature);
Serial.print('\t');
Serial.print(humidity);
Serial.print('\n');
delay(1000);
}
<!DOCTYPE html>
<html>
<head>
<title>Humidity volume control</title>
<style>
html,
body {
height: 100%;
margin: 0;
}
body {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.text {
font-size: 30vh;
}
.emoji {
width: 2em;
text-align: center;
}
</style>
<script>
var steam = new EventSource('/events');
steam.onmessage = function (event) {
var data = JSON.parse(event.data);
var { temperatue, humidity } = data;
document.getElementById("humidity").innerText = `${humidity}%`;
};
</script>
</head>
<body>
<div class="text emoji">🔊</div>
<div id="humidity" class="text">--%</div>
<div class="text emoji">💧</div>
</body>
</html>
{
"name": "dht-volume",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Benjamin Swart",
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"express-sse": "^0.5.3",
"serialport": "^9.0.0",
"win-audio": "^2.0.2"
}
}
const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');
const audio = require('win-audio').speaker;
const express = require('express');
const SSE = require('express-sse');
const port = new SerialPort("COM3", { baudRate: 9600 });
const app = express();
const sse = new SSE();
const parser = new Readline();
port.pipe(parser);
parser.on('data', line => {
var values = line.split('\t');
var temperature = parseFloat(values[0]);
var humidity = parseFloat(values[1]);
audio.set(humidity);
sse.send({ temperature, humidity });
});
app.get("/", (req, res) => {
res.sendFile(__dirname + "/display.html");
});
app.get("/events", sse.init);
app.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment