From 6871da1380fa7f9fe64d232fbb4e4932427987da Mon Sep 17 00:00:00 2001 From: StratosKarvounis Date: Mon, 25 Jan 2021 12:08:32 +0000 Subject: [PATCH] Upload files to '' --- index.js | 22 ++++++++++++++++++++++ seriaport.ino | 21 +++++++++++++++++++++ stratos.py | 34 ++++++++++++++++++++++++++++++++++ thermokrasia.ino | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 index.js create mode 100644 seriaport.ino create mode 100644 stratos.py create mode 100644 thermokrasia.ino diff --git a/index.js b/index.js new file mode 100644 index 0000000..e1408f6 --- /dev/null +++ b/index.js @@ -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'); diff --git a/seriaport.ino b/seriaport.ino new file mode 100644 index 0000000..026108b --- /dev/null +++ b/seriaport.ino @@ -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 + } + } + } + diff --git a/stratos.py b/stratos.py new file mode 100644 index 0000000..fb2b9f9 --- /dev/null +++ b/stratos.py @@ -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")) + + + + + + + diff --git a/thermokrasia.ino b/thermokrasia.ino new file mode 100644 index 0000000..069512d --- /dev/null +++ b/thermokrasia.ino @@ -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 +}