3 Replies Latest reply on Mar 5, 2016 1:30 PM by BMEJ

    Controlling LED from Web


      After 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: 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.





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


      Username is admin and password is galileo .


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


      Thanks for looking.




        • 1. Re: Controlling LED from Web

          Thanks Joe this is great.


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



          • 2. Re: Controlling LED from Web

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



            from flask import Flask                                                                          
            def index():                                                                                     
                    return("<html> <body> <a href=/runScript> Run my Script </a> </body </html>")            
            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='', 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!




            • 3. Re: Controlling LED from Web

              Hey joe,


              Where do I place the files at?


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