abreuma677
Posts: 7
Joined: Thu Dec 27, 2018 12:49 pm

Pi Serving Webpage to Change Pi Python App Settings

Sat Jan 12, 2019 1:56 am

I expect to be pointed to some new technology I need to learn. I'm having a hard time searching for information on this topic. I know it's out there but I must not know the correct words to search with.

I have a headless Pi running python code that runs speedtest-cli and sends the results to an InfluxDB instance on a Unbuntu server running in a VM somewhere else. It's all sort of cobbled together more as an educational project at this point. My python code has a section at the top where I define the values of several configuration constants. Things like the address of the InfluxDB server, credentials for that connection, timing values for how often I collect the data, etc. I consider these things to be application settings or preferences. Now I want to build at least 2 more of these things for other family member homes so I can get a historical look at their internet speed performance too. I'd rather not customize the code every time I do this so I want the Pi to serve a web page that lets me changes these settings. Like pointing a browser at my router to change it's settings. I have no idea how these web-based forms are built or work. What keywords do I use for guidance on how to do this?

Side note. My python code already creates a static html file that shows the speed test results for the last 10 tests. I have Apache running on the Pi to serve this page. That's about the limit of my html/web page experience at this point.

Andyroo
Posts: 1492
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Pi Serving Webpage to Change Pi Python App Settings

Sat Jan 12, 2019 3:19 am

Rather than change the code create a web page that collects the data and save it to a file.

Then change your python code to read the file.

To create a form https://www.w3schools.com/html/html_forms.asp

Write data to a file in php https://www.w3schools.com/PHP/php_file_create.asp

Reading files in Python https://www.pythonforbeginners.com/file ... -in-python

One thing to remember is file security. Web services run under the user www-data so you may have to change the folder security or the user security your python program runs under.

Just be aware speedtest-cli is not very accurate on Pi computers and even the author warns you that the Speedtest company has moved away from the method in the code. My testing showed significant difference between the Pi, a dual core Intel box and an iPad running the website code - all within seconds of each other to the same server. I ran these tests over a series of nights when traffic would be low (and my son was asleep :lol: )
Need Pi spray - these things are breeding in my house...

abreuma677
Posts: 7
Joined: Thu Dec 27, 2018 12:49 pm

Re: Pi Serving Webpage to Change Pi Python App Settings

Sat Jan 12, 2019 3:31 am

Thank you!

Yes I realize that speed tests are subjective. I remember doing a similar set of tests with various flavors of Windows and at least one Linux distribution on the same box (via a multi-boot Windows setup and Linux live CD) and the differences were interesting. I'm more interested in getting some sort of baseline/history so when they call me I might be able to see some change that might be causing some problems. In one house they have no wired devices and I'd rather have some wired device data.

Return to “General programming discussion”