SHARE
TWEET

Untitled

a guest Aug 17th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from flask import Flask,render_template,request
  2. from subprocess import PIPE, Popen
  3. from flask_socketio import SocketIO
  4. import threading
  5. import time
  6. import os
  7. temp = 0
  8. app = Flask(__name__)
  9. app.config['SECRET_KEY'] = 'secret!'
  10. socketio = SocketIO(app)
  11.  
  12. def get_temp():
  13.     while(1):
  14.         process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
  15.         output, _error = process.communicate()
  16.         socketio.emit('temp',{'temp',output})
  17.         temp=output
  18.         time.sleep(2000)
  19.         print("DID")
  20.  
  21. x = threading.Thread(target=get_temp)
  22. x.start()
  23. print("START")
  24. @app.route('/')
  25. def hello_world():
  26.     return render_template('st.html',raspi_model='3',raspi_temp=9)
  27.      
  28. <html>
  29. <body>
  30. <h1>Raspberry Pi Control Page</h1>
  31. <hr>
  32. <p>Raspberry Pi Model : {{raspi_model}}</p>
  33.  
  34. <p id="asd">Current Tempreature : {{raspi_temp}}</p>
  35. <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
  36. <script type="text/javascript" charset="utf-8">
  37.     var socket = io();
  38.     document.getElementById(id).innerHTML = socket.data
  39.  
  40. </script>
  41. </body>
  42. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top