add more code
parent
2d655e4115
commit
610ca471dc
|
|
@ -16,4 +16,6 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./src/:/flask/
|
- ./src/:/flask/
|
||||||
env:
|
env:
|
||||||
- FLASK_APP=server.py
|
- FLASK_APP=server.py
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
|
|
@ -2,4 +2,5 @@ from python:3-alpine
|
||||||
RUN pip install Flask
|
RUN pip install Flask
|
||||||
WORKDIR /flask
|
WORKDIR /flask
|
||||||
ENV FLASK_APP server.py
|
ENV FLASK_APP server.py
|
||||||
|
EXPOSE 5000
|
||||||
CMD ["flask", "run"]
|
CMD ["flask", "run"]
|
||||||
|
|
@ -117,8 +117,9 @@ Cooler: \href{https://micropython.org/}{MicroPython}
|
||||||
\item Basiert auf Python 3
|
\item Basiert auf Python 3
|
||||||
\item Frei \& Open Source
|
\item Frei \& Open Source
|
||||||
\item Einige Funktionalität eingeschränkt (z.B. Multithreading)
|
\item Einige Funktionalität eingeschränkt (z.B. Multithreading)
|
||||||
\item Verscheidene Boards/Controller unterstützt
|
\item Verscheidene Boards/Controller unterstützt: PyBoard, ESP32, \dots
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
Lowlevel: C, Arduino Studio
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
\section{Setup}
|
\section{Setup}
|
||||||
|
|
@ -222,7 +223,6 @@ import webrepl_setup
|
||||||
\begin{lstlisting}[caption={C\&C Server},label=cnc]
|
\begin{lstlisting}[caption={C\&C Server},label=cnc]
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello():
|
def hello():
|
||||||
return "Hello ESP8266!"
|
return "Hello ESP8266!"
|
||||||
|
|
@ -232,22 +232,81 @@ def log(id):
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
Starten:
|
Starten:
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
|
\item[!] pip install Flask
|
||||||
\item python server.py
|
\item python server.py
|
||||||
\item docker-compose up (server.py in src/)
|
\item docker-compose up (server.py in src/)
|
||||||
\item FLASK\_APP=server.py flask run
|
\item FLASK\_APP=server.py flask run
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
\end{frame}
|
||||||
|
\begin{frame}[fragile]{Daten übertragen}
|
||||||
|
\begin{lstlisting}[caption={HTTP Requests},label=http]
|
||||||
|
import urequests
|
||||||
|
host = "http://your.host.ip.here:5000"
|
||||||
|
response = urequests.get(host)q
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
import machine
|
||||||
|
board_id = int.from_bytes(machine.unique_id(), 'little')
|
||||||
|
payload = '{"board": "{id}"}'.format(id=board_id)
|
||||||
|
json_header = {'Content-Type': 'application/json'}
|
||||||
|
post_url = "{host}/id/{id}".format(host=host, id=board_id)
|
||||||
|
urequests.post(post_url, data=data, headers=json_header)
|
||||||
|
\end{lstlisting}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
|
|
||||||
\section{Basteln}
|
\section{Basteln}
|
||||||
\subsection{Blinkende LED}
|
\subsection{Blinkende LED}
|
||||||
\begin{frame}{LEDs}
|
\begin{frame}{LED anschließen}
|
||||||
|
TODO schema
|
||||||
|
\end{frame}
|
||||||
|
\begin{frame}[fragile]{LEDs}
|
||||||
|
\begin{lstlisting}[caption={LED},label=led]
|
||||||
|
import machine, time, math
|
||||||
|
pin = machine.Pin(0, machine.Pin.OUT)
|
||||||
|
pin.on()
|
||||||
|
pin.off()
|
||||||
|
|
||||||
|
pwm = machine.PWM(pin)
|
||||||
|
pwm.duty(512)
|
||||||
|
pwm.deinit()
|
||||||
|
|
||||||
|
def pulse(l, t):
|
||||||
|
for i in range(20):
|
||||||
|
l.duty(int(math.sin(i / 10 * math.pi) * 500 + 500))
|
||||||
|
time.sleep_ms(t)
|
||||||
|
led = machine.PWM(machine.Pin(2), freq=1000)
|
||||||
|
pulse(led, 50)
|
||||||
|
for i in range(10):
|
||||||
|
pulse(led, 20)
|
||||||
|
\end{lstlisting}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
\subsection{Schalter und Taster}
|
\subsection{Schalter und Taster}
|
||||||
|
\begin{frame}[fragile]{Input}
|
||||||
|
TODO: schema
|
||||||
|
\begin{lstlisting}[caption={Input},label=input]
|
||||||
|
import machine
|
||||||
|
pin = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)
|
||||||
|
status = pin.value()
|
||||||
|
|
||||||
|
def callback(p):
|
||||||
|
print('changed', p)
|
||||||
|
|
||||||
|
pin.irq(trigger=machine.Pin.IRQ_RISING | machine.Pin.IRQ_FALLING, handler=callback)
|
||||||
|
\end{lstlisting}
|
||||||
|
\end{frame}
|
||||||
\subsection{Sensoren}
|
\subsection{Sensoren}
|
||||||
\subsection{Push}
|
\begin{frame}[fragile]{Sensoren}
|
||||||
|
TODO: schema
|
||||||
|
\begin{lstlisting}[caption={Sensoren},label=senors]
|
||||||
|
import dht
|
||||||
|
import machine
|
||||||
|
d = dht.DHT22(machine.Pin(4))
|
||||||
|
d.measure()
|
||||||
|
d.temperature()
|
||||||
|
d.humidity()
|
||||||
|
\end{lstlisting}
|
||||||
|
\end{frame}
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
@ -262,4 +321,14 @@ Starten:
|
||||||
\normalsize
|
\normalsize
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
|
\section*{Ausblick}
|
||||||
|
\begin{frame}{Was geht noch?}
|
||||||
|
\begin{itemize}
|
||||||
|
\item \url{https://learn.adafruit.com/micropython-hardware-i2c-devices/overview}
|
||||||
|
\item \url{http://luftdaten.info/}
|
||||||
|
\item \url{https://micropython-on-esp8266-workshop.readthedocs.io/en/latest/index.html}
|
||||||
|
\item MQTT, \href{http://nsq.io/}{nsq.io}
|
||||||
|
\end{itemize}
|
||||||
|
\end{frame}
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue