Hamish,
Can you spare a bit of time to look at my implementation of the code in my Flask App to fetch the System Status from the Music Player program? I pushed a version of the code a few days ago, so you can look at it on GitLab if you need to. I raised a query on this on the Raspberry Pi Forums (see
https://www.raspberrypi.org/forums/view ... 2&t=303229), but unfortunately, some of the answers have confused me more than they help.
To summarise the current situation, if I leave out my additional functions then the pages render satisfactorily, but they do not do anything
As soon as I add the sockets code and my fetch_system_status() function, the pages no longer render.
I suspect that the structure of my App is wrong because I think that maybe the program can't find its way to the default Route after the Status List variable has been populated; one of the people on the RPi Forums has suggested a suitable structure. Unfortunately, it is totally different to what I've seen elsewhere (it doesn't even have any Routes), so I'm somewhat lost.
The same guy has suggested that the sockets code may be blocking the App. His reasoning for this is that when I put the Flask Development Server into Debug Mode, I get this:
Code: Select all
pi@minster-music:~/html $ export FLASK_DEBUG=1
pi@minster-music:~/html $ flask run
* Serving Flask app "statusmonitor.py" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
About to run Startup
Minster Webserver Software Version0.2.1 (26/01/2021)
System startup sequence initiated.
System startup sequence initiated.
Waiting 20 seconds for the Music Player to start
* Debugger is active!
* Debugger PIN: 172-504-382
About to run Startup
Minster Webserver Software Version0.2.1 (26/01/2021)
System startup sequence initiated.
System startup sequence initiated.
Waiting 20 seconds for the Music Player to start
Sockets._create_and_connect(): (Music Pi Client Socket): Error connecting:
Traceback (most recent call last):
File "/home/pi/html/Tools/sockettools.py", line 432, in _create_and_connect
self._create_socket()
File "/home/pi/html/Tools/sockettools.py", line 550, in _create_socket
self.server_socket.bind(('', self.port_number))
OSError: [Errno 98] Address already in use
Sockets._create_and_connect(): (Music Pi Client Socket): Unknown error, possibly address already in use?
Sockets._create_and_connect(): (Music Pi Client Socket): Retrying in 10 seconds...
Connection Timed Out (Music Pi Client Socket): [Errno 98] Address already in use. Retrying in 10 seconds...
Connected to peer (Music Pi Client Socket).
Sockets._create_and_connect(): (Music Pi Client Socket): Error connecting:
Traceback (most recent call last):
File "/home/pi/html/Tools/sockettools.py", line 432, in _create_and_connect
self._create_socket()
File "/home/pi/html/Tools/sockettools.py", line 550, in _create_socket
self.server_socket.bind(('', self.port_number))
OSError: [Errno 98] Address already in use
which repeats ad infinitum.
Can you comment on that aspect of the problem?