Websockets
WebSocket is een netwerkprotocol dat full-duplex communicatie biedt over een enkele TCP-verbinding. Het WebSocketprotocol is gestandaardiseerd door de Internet Engineering Task Force in 2011 als RFC 6455 en de WebSocketAPI gemaakt in Web IDL is gestandaardiseerd door het World Wide Web Consortium.
HTTP
roger that... lekker.
over
ik heb koekjes.... over
wie is Rogér?
Websockets
ik ga maandagmiddag
iot spijbelen
Goed idee Chantal,
ik ga GTA spelen
tssss... sloebers...
ik ben flink
en ga wel
Websockets
een samenstelling
Sense HAT
The Sense HAT is an add-on board that gives your Raspberry Pi an array of sensing capabilities. The on-board sensors allow you to monitor pressure, humidity, temperature, colour, orientation, and movement. The bright 8×8 RGB LED matrix allows you to visualise data from the sensors, and the five-button joystick lets users interact with your projects.
sudo apt-get install sense-hat
# or
pip install sense-hat
python3 -m venv venv --system-site-packages
source venv/bin/activate
💡__init__.py ?
wat is dat?
zie volgende slide
In elke map waarin je Python-modules wil plaatsen, moet een leeg bestand genaamd __init__.py aanwezig is.
Dit bestand geeft aan dat de map een Python-pakket is. Als je dit bestand niet hebt, zal Python de map niet als een module herkennen.
Je moet dit bestand niet vullen met inhoud, alleen het bestaan ervan is voldoende.
Test met deze code
from sense_hat import SenseHat
sense = SenseHat()
sense.set_imu_config(False, True, False)
sense.show_message("Flash.... aaaaah!", text_colour=[255, 0, 0])
Probeer de temperatuur uit te lezen,
door de docs zelf te lezen 👀
https://sense-hat.readthedocs.io/en/latest/api/
Websockets
Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.
It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.
However, Flask supports extensions that can add application features as if they were implemented in Flask itself.
pip install Flask
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
Websockets
pip install flask-socketio
socketio.run()
function encapsulates the start up of the web server and replaces the app.run()
standard Flask development server start up.
socketio.run()
function encapsulates the start up of the web server and replaces the app.run()
standard Flask development server start up.
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
if __name__ == '__main__':
socketio.run(app)
var socket = io('http://localhost:6060');
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
// listen to temperature_change
socket.on('temperature_change', function(data) {
const temp = data.temperature;
document.getElementById('temperature').innerText = temp;
});