Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask,render_template,request
- from subprocess import PIPE, Popen
- from flask_socketio import SocketIO
- import threading
- import time
- import os
- temp = 0
- app = Flask(__name__)
- app.config['SECRET_KEY'] = 'secret!'
- socketio = SocketIO(app)
- def get_temp():
- while(1):
- process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
- output, _error = process.communicate()
- socketio.emit('temp',{'temp',output})
- temp=output
- time.sleep(2000)
- print("DID")
- x = threading.Thread(target=get_temp)
- x.start()
- print("START")
- @app.route('/')
- def hello_world():
- return render_template('st.html',raspi_model='3',raspi_temp=9)
- <html>
- <body>
- <h1>Raspberry Pi Control Page</h1>
- <hr>
- <p>Raspberry Pi Model : {{raspi_model}}</p>
- <p id="asd">Current Tempreature : {{raspi_temp}}</p>
- <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
- <script type="text/javascript" charset="utf-8">
- var socket = io();
- document.getElementById(id).innerHTML = socket.data
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement