Started wather station
This commit is contained in:
@@ -1,41 +1,21 @@
|
|||||||
// Include the libraries we need
|
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
// Data wire is plugged into port 2 on the Arduino
|
#define HIGH_PIN 12
|
||||||
#define ONE_WIRE_BUS 2
|
#define ONE_WIRE_BUS 13
|
||||||
|
|
||||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
|
||||||
OneWire oneWire(ONE_WIRE_BUS);
|
OneWire oneWire(ONE_WIRE_BUS);
|
||||||
|
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
|
|
||||||
/*
|
void setup() {
|
||||||
* The setup function. We only start the sensors here
|
pinMode(HIGH_PIN, OUTPUT);
|
||||||
*/
|
digitalWrite(HIGH_PIN, HIGH);
|
||||||
void setup(void)
|
Serial.begin(115200);
|
||||||
{
|
|
||||||
// start serial port
|
|
||||||
Serial.begin(9600);
|
|
||||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
|
||||||
|
|
||||||
// Start up the library
|
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void loop() {
|
||||||
* Main function, get and show the temperature
|
sensors.requestTemperatures();
|
||||||
*/
|
|
||||||
void loop(void)
|
|
||||||
{
|
|
||||||
// call sensors.requestTemperatures() to issue a global temperature
|
|
||||||
// request to all devices on the bus
|
|
||||||
Serial.print("Requesting temperatures...");
|
|
||||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
|
||||||
Serial.println("DONE");
|
|
||||||
// After we got the temperatures, we can print them here.
|
|
||||||
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
|
|
||||||
Serial.print("Temperature for the device 1 (index 0) is: ");
|
|
||||||
Serial.println(sensors.getTempCByIndex(0));
|
Serial.println(sensors.getTempCByIndex(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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