Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,087 Views

Controlling LED from Web

After /thread/98922?sr=stream blinking an LED the next thing an IoT newb wants to do is control an LED from the web. I wanted to share what I did in the event someone else wants to do this. The app runs on SSL and requires auth to control the LED. To install I stopped the lighttpd server first.

systemctl stop lighttpd

systemctl disable lighttpd

Then install flask and pyopenssl

pip install flask

pip install pyopenssl

Download or clone the files here: https://github.com/joemcmanus/GalileoPyServer GitHub - joemcmanus/GalileoPyServer: A sample web server using Flask that can read digital & analog sensors as well as c…

Change the line

pin = mraa.Gpio(12)

 

Top match your pin for your LED. If you have a TMP36 temp sensor wire it up to A1.

 

Start the server.

./server.py

There is a default SSL cert included so go to https://yourGalileoIP/ https://yourGalileoIP

Username is admin and password is galileo .

Sample wiring if you don't want to change any code.

Thanks for looking.

Cheers,

-Joe

3 Replies
JTurn12
New Contributor II
53 Views

Thanks Joe this is great.

Could this also be used to execute python script on the server?

Cheers

idata
Community Manager
53 Views

Absolutely. Since Flask is python you would just move your python script in to the server.py script.

i.e.

from flask import Flask

@app.route('/')

def index():

return(" /runScript Run my Script ")

@app.route('/runScript')

def runScript():

# Put all of your regular python code here.

# i.e. cut and paste your python script in to this section.

return("Ran Script")

if __name__ == '__main__':

app.run(host='0.0.0.0', port=80)

 

When you click on the link runScript it would execute your code. When it is done the text "Ran Script" would be returned to the screen. Flask is kind of amazing!

-Joe

 

JTurn12
New Contributor II
53 Views

Hey joe,

Where do I place the files at?

Nevermind I got it. I put everything in as is using git clone ...

Thanks

Reply