[Flask] A headless PI3 with a Python3-Flask-program don't communicate through WiFi with a browser

R. Heijstek post at rheijstek.nl
Wed Mar 28 12:43:06 EDT 2018


Dear all,


There is a problem with a Python 3 program with Flask.
I want to run this program on a Raspberry PI3 and control the PI3 only via a WiFi connection with a browser.
BUT. Communication via the WIFI connection only works when there is a HDMI monitor AND / OR Ethernet is connected with the PI3!?

Summarizing:
PI3 connected with an HDMI monitor >> WiFi and browser communication works.
Pi3 connected with Ethernet connected >> WiFi and browser communication works.
(Of course) the PI3 connected with both an HDMI monitor and with Ethernet => Wifi and browser communication works.
HOWEVER, the PI3 without HDMI monitor and without Ethernet >> The WiFi connection works no longer.
The browser reports: "This site is not accessible".
The (same) IP address of the PI3 is still present on the network.


See the Python-flask program example.py


import os
from flask import Flask, render_template, request
app = Flask(__name__)


helptxt = "Information window"


def b_all():
global file_int
print ("b_all")
helptxt = "Button " + str(file_int)
templatetekst = {"help_txt" : helptxt}
return render_template('main.html', **templatetekst)


@app.route("/")
def main():
print("(main)")
templatetekst = {"help_txt" : helptxt}
return render_template('main.html', **templatetekst)


@app.route("/Button/0/")
def b0():
global file_int
file_int = 0
return b_all()


@app.route("/Button/1/")
def b1():
global file_int
file_int = 1
return b_all()


@app.route("/Button/2/")
def b2():
global file_int
file_int = 2
return b_all()


@app.route("/Button/3/")
def b3():
global file_int
file_int = 3
return b_all()


if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=False, threaded=True, use_evalex=False)


The HTML-file that belongs to the Flask-program example.py is main.html
Flask wants this program to be located in the map "templates".

<!DOCTYPE html>
<font size="10">
<body>
<a href="/Button/0">0</a>
<a href="/Button/1">1</a>
<a href="/Button/2">2</a>
<a href="/Button/3">3</a>
<font> ---- </font>
<font>{{ help_txt }}</font>
</body>
</html>

To start this program on the PI3 without a monitor, I have extended rc.local (between the lines:
"fi" and "exit 0")
with the line:
sudo python /home/pi/Desktop/example/example.py &

rc.local can be changed with the LXTerminal and the command line:
sudo nano /etc/rc.local.

I have tried every logical possibility I can imagine, but did not found a solution.

Thanks in advance.

R. Heijstek


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20180328/1c1b13e2/attachment-0001.html>


More information about the Flask mailing list