HarrisonA
Posts: 25
Joined: Tue Mar 19, 2019 5:48 pm

Controlling GPIO pins from a webpage (using flask)

Thu Apr 11, 2019 8:11 pm

Hello,

I have a program that controls GPIO pins from a web page. The web page will also open a data file and update the status of the GPIO pins In order for this status to be up to date, the webpage automatically reloads every 3 seconds.

The problem I am having is due to the GPIO control using @app.route("/<devicename>/<action>"). Because of this, when the page is reloaded after a GPIO is turned on, it will reload and turn it on again.

Is there a better way to control GPIO pins from a web page? and if not how do I solve this problem?

Thanks!

ankith26
Posts: 92
Joined: Mon Mar 25, 2019 11:08 am
Location: Earth
Contact: Website

Re: Controlling GPIO pins from a webpage (using flask)

Wed Apr 17, 2019 2:17 pm

Try requests module(I have not tried it yet)

Code: Select all

import requests

link = "http://www.somerandomwebsite.com"
page = requests.get(link)
print(page.text)
#you get the web page contents hopefully
My website is at https://pratt.ml
Hope it runs (which it wont)

HarrisonA
Posts: 25
Joined: Tue Mar 19, 2019 5:48 pm

Re: Controlling GPIO pins from a webpage (using flask)

Wed Apr 17, 2019 2:45 pm

Thanks for the response! I ended up using return redirect('homepageadress', 302) after each GPIO action, this worked perfectly.

Return to “Python”