StratosKarvounis
4 years ago
4 changed files with 113 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||
var path = require('path'); |
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var io = require('socket.io')(http); |
|||
|
|||
|
|||
|
|||
const cors = require('cors') |
|||
app.use(cors()); |
|||
|
|||
io.on('connection', s => { |
|||
console.error('socket connection'); |
|||
|
|||
io.on('data', function(s) { |
|||
console.log('Got', s); |
|||
}) |
|||
|
|||
}); |
|||
|
|||
|
|||
http.listen(5000, () => console.error('listening on http://localhost:5000/')); |
|||
console.error('socket.io example'); |
@ -0,0 +1,21 @@ |
|||
int analogPin = A3; |
|||
|
|||
int meas = 0; |
|||
|
|||
void setup() { |
|||
Serial.begin(9600); // setup serial
|
|||
} |
|||
|
|||
void loop() |
|||
{ |
|||
meas = analogRead(analogPin); // read the input pin
|
|||
|
|||
if (Serial.available()) |
|||
{ |
|||
if (Serial.read() == '1') |
|||
{ |
|||
Serial.println(meas); // debug value
|
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,34 @@ |
|||
import serial |
|||
from datetime import datetime |
|||
from time import sleep |
|||
import socketio |
|||
|
|||
sio = socketio.Client() |
|||
now = datetime.now() |
|||
|
|||
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) |
|||
ser.flush() |
|||
|
|||
|
|||
@sio.event |
|||
def connect(): |
|||
print('connection established') |
|||
|
|||
|
|||
flag = 0 |
|||
while True: |
|||
if flag != 1: |
|||
sio.connect('http://localhost:5000/') |
|||
flag += 1 |
|||
if ser.in_waiting > 0: |
|||
data = ser.readline().decode('utf-8').rstrip() |
|||
print(data) |
|||
sio.emit('data', data) |
|||
print(now.strftime("%Y-%m-%d %H:%M")) |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,36 @@ |
|||
//TMP36 Pin Variables
|
|||
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
|
|||
//the resolution is 10 mV / degree centigrade with a
|
|||
//500 mV offset to allow for negative temperatures
|
|||
|
|||
/*
|
|||
* setup() - this function runs once when you turn your Arduino on |
|||
* We initialize the serial connection with the computer |
|||
*/ |
|||
void setup() |
|||
{ |
|||
Serial.begin(9600); //Start the serial connection with the computer
|
|||
//to view the result open the serial monitor
|
|||
} |
|||
|
|||
void loop() // run over and over again
|
|||
{ |
|||
//getting the voltage reading from the temperature sensor
|
|||
int reading = analogRead(sensorPin); |
|||
|
|||
// converting that reading to voltage, for 3.3v arduino use 3.3
|
|||
float voltage = reading * 5.0; |
|||
voltage /= 1024.0; |
|||
|
|||
// print out the voltage
|
|||
Serial.print(voltage); Serial.println(" volts"); |
|||
|
|||
// now print out the temperature
|
|||
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
|
|||
//to degrees ((voltage - 500mV) times 100)
|
|||
Serial.print(temperatureC); |
|||
Serial.println(" degrees C"); |
|||
|
|||
|
|||
delay(1000); //waiting a second
|
|||
} |
Loading…
Reference in new issue