├── sensor-display-flask ├── .gitignore ├── requirements.txt ├── static │ ├── css │ │ └── app.css │ └── js │ │ └── app.js ├── sensor_app.py └── templates │ └── index.html ├── media ├── demo.gif ├── demo.mp4 ├── turbine.gif └── turbine.mp4 ├── Dockerfile ├── updater.py └── README.md /sensor-display-flask/.gitignore: -------------------------------------------------------------------------------- 1 | .venv -------------------------------------------------------------------------------- /sensor-display-flask/requirements.txt: -------------------------------------------------------------------------------- 1 | 2 | Flask-SocketIO==5.0.1 3 | Werkzeug==2.0.3 -------------------------------------------------------------------------------- /media/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Revisto/sensor-display/master/media/demo.gif -------------------------------------------------------------------------------- /media/demo.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Revisto/sensor-display/master/media/demo.mp4 -------------------------------------------------------------------------------- /media/turbine.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Revisto/sensor-display/master/media/turbine.gif -------------------------------------------------------------------------------- /media/turbine.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Revisto/sensor-display/master/media/turbine.mp4 -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8 2 | 3 | COPY sensor-display-flask /app 4 | WORKDIR /app 5 | 6 | RUN pip3 install -U setuptools 7 | RUN apt-get install -y libssl-dev libffi-dev 8 | RUN apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev 9 | RUN pip3 install -r requirements.txt 10 | 11 | CMD ["python3","sensor_app.py"] -------------------------------------------------------------------------------- /sensor-display-flask/static/css/app.css: -------------------------------------------------------------------------------- 1 | .hero { 2 | background: #eee; 3 | padding: 20px; 4 | border-radius: 10px; 5 | margin-top: 1em; 6 | } 7 | 8 | .hero h1 { 9 | margin-top: 0; 10 | margin-bottom: 0.3em; 11 | text-align: center; 12 | } 13 | 14 | 15 | .chart-container { 16 | max-width: 800px; 17 | margin: 0 auto; 18 | } 19 | 20 | .container { 21 | margin: auto; 22 | width: 49%; 23 | display: inline-block; 24 | } 25 | 26 | 27 | .killbtn { 28 | background-image: linear-gradient(to right, rgb(199 158 187) 0%, rgb(97 125 171) 100%) !important; 29 | width: -webkit-fill-available; 30 | height: 40px; 31 | } -------------------------------------------------------------------------------- /updater.py: -------------------------------------------------------------------------------- 1 | from random import randint, uniform 2 | import requests 3 | from time import sleep 4 | from os import getpid 5 | process_id = getpid() 6 | def sensor_data(): 7 | diesel_consumption = uniform(13, 14) 8 | tempreture = randint(480, 580) 9 | rpm = randint(2000, 4000) 10 | gas_mass = randint(250, 750) 11 | 12 | return { 13 | "diesel_consumption": diesel_consumption, 14 | "tempreture": tempreture, 15 | "rpm": rpm, 16 | "gas_mass": gas_mass, 17 | "process_id": process_id 18 | } 19 | 20 | while True: 21 | url = 'http://127.0.0.1:5000/update' 22 | data = sensor_data() 23 | requests.post(url, params = data) 24 | sleep(0.1) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sensor Tracker 2 | ## _Track and Display Turbine Sensors and Stop the Turbine!_ 3 | 4 | Sensor Tracker shows the 4 turbine sensors in different charts to be monitored and the agent would be able to stop the turbine if anything went wrong. 5 | 6 |  7 | 8 | 9 | ## ⚙️ Installation 10 | 11 | Sensor Tracker requires [Docker](https://www.docker.com/) to run. 12 | 13 | Run the updater.py and Install Docker and start the Sensor Tracker, docker takes care of other dependencies. 14 | 15 | ```sh 16 | apt install docker-ce 17 | ``` 18 | 19 | Now clone the repo: 20 | ```sh 21 | git clone https://github.com/revisto/sensor-display 22 | cd sensor-display 23 | ``` 24 |  25 | 26 | ## Docker 27 | 28 | ```sh 29 | docker build -t sensor_tracker . 30 | docker run -d sensor_tracker 31 | ``` 32 | 33 | ## Updater 34 | 35 | ```sh 36 | python3 updater.py 37 | ``` 38 | 39 | ## Show your support 40 | 41 | Please ⭐️ this repository if this project helped you! 42 | 43 | 44 | ## 📝 License 45 | 46 | GNUv2 47 | 48 | **Free Software, Hell Yeah!** -------------------------------------------------------------------------------- /sensor-display-flask/sensor_app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, make_response, jsonify 2 | from flask_socketio import SocketIO 3 | from datetime import datetime 4 | import os 5 | app = Flask(__name__) 6 | app.config['SECRET_KEY'] = 'donsky!' 7 | socketio = SocketIO(app, cors_allowed_origins='*') 8 | class ProcessId: 9 | def __str__(self): 10 | return self.process_id 11 | def update(self, PID): 12 | self.process_id = PID 13 | 14 | process_id = ProcessId() 15 | 16 | """ 17 | Get current date time 18 | """ 19 | def get_current_datetime(): 20 | now = datetime.now() 21 | return now.strftime("%m/%d/%Y %H:%M:%S") 22 | 23 | """ 24 | Generate random sequence of dummy sensor values and send it to our clients 25 | """ 26 | @app.route('/update', methods = ['POST']) 27 | def update(): 28 | diesel_consumption = request.args.get('diesel_consumption') 29 | tempreture = request.args.get('tempreture') 30 | rpm = request.args.get('rpm') 31 | gas_mass = request.args.get('gas_mass') 32 | process_id.update(request.args.get('process_id')) 33 | 34 | socketio.emit('updateSensorData', {'diesel_consumption': diesel_consumption, "tempreture": tempreture, "rpm": rpm, "gas_mass": gas_mass, "date": get_current_datetime()}) 35 | data = {'message': 'Done', 'code': 'SUCCESS'} 36 | return make_response(jsonify(data), 201) 37 | 38 | @app.route('/kill') 39 | def kill(): 40 | os.system(f"kill {process_id}") 41 | return "SUCCESS" 42 | 43 | @app.route('/') 44 | def index(): 45 | return render_template('index.html') 46 | 47 | """ 48 | Decorator for connect 49 | """ 50 | @socketio.on('connect') 51 | def connect(): 52 | pass 53 | """ 54 | Decorator for disconnect 55 | """ 56 | @socketio.on('disconnect') 57 | def disconnect(): 58 | print('Client disconnected', request.sid) 59 | 60 | if __name__ == '__main__': 61 | socketio.run(app) -------------------------------------------------------------------------------- /sensor-display-flask/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |