Started wather station
This commit is contained in:
22
JavaScript/Weather Station/Tempsensor/Tempsensor.ino
Normal file
22
JavaScript/Weather Station/Tempsensor/Tempsensor.ino
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
#define HIGH_PIN 12
|
||||
#define ONE_WIRE_BUS 13
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
void setup() {
|
||||
pinMode(HIGH_PIN, OUTPUT);
|
||||
digitalWrite(HIGH_PIN, HIGH);
|
||||
Serial.begin(115200);
|
||||
sensors.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensors.requestTemperatures();
|
||||
Serial.println("VALID" + String(sensors.getTempCByIndex(0)));
|
||||
delay(100);
|
||||
}
|
||||
|
||||
28
JavaScript/Weather Station/index.js
Normal file
28
JavaScript/Weather Station/index.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const SerialPort = require('serialport');
|
||||
const parsers = SerialPort.parsers;
|
||||
const fs = require('fs');
|
||||
let express = require('express');
|
||||
let app = express();
|
||||
|
||||
|
||||
const parser = new parsers.Readline({
|
||||
delimiter: '\r\n'
|
||||
});
|
||||
|
||||
const port = new SerialPort('COM3', {
|
||||
baudRate: 115200
|
||||
});
|
||||
|
||||
port.pipe(parser);
|
||||
|
||||
let temperature;
|
||||
|
||||
port.on('data', async (data) => {
|
||||
if (data.toString().startsWith('VALID')) {
|
||||
if (parseFloat(data.toString().substring(5)) % 1) {} else return;
|
||||
|
||||
let temp = parseFloat(data.toString().substring(5));
|
||||
temperature = temp;
|
||||
console.log(temp);
|
||||
}
|
||||
});
|
||||
1865
JavaScript/Weather Station/package-lock.json
generated
Normal file
1865
JavaScript/Weather Station/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
8
JavaScript/Weather Station/package.json
Normal file
8
JavaScript/Weather Station/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "",
|
||||
"version": "",
|
||||
"dependencies": {
|
||||
"express": "^4.16.3",
|
||||
"serialport": "^6.2.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user