5 Replies Latest reply on Apr 20, 2016 11:13 PM by tbastosjp

    ADC Data to WebServer


      Hello, I am a beginner user of a Galileo Gen 2 and I am developing a program in which the it reads 2 (two) Analog inputs, perform calculations with it and throws the results in a website.

      For now I have the script made in python to read (through threads) the ADC inputs and perfoms the calculations. And I have a different script in which contains the html/css website (webserver is the board itself).

      The problem is: How can I send the said data (written in python) to the html/css website?


      PS: I am sorry if any info is missing. Should I send the scripts? Thank you!

        • 1. Re: ADC Data to WebServer



          I think communication through files could work... but maybe if you send the scripts yo have would help to figure out how...



          • 2. Re: ADC Data to WebServer

            Hello - This is an easy job for the galileo. What you want to do is install Flask. Then it will run your python code when you access a page.


            Here is a sample using Flask to read an analog pin and post the results online: GitHub - joemcmanus/GalileoPyServer: A sample web server using Flask that can read digital & analog sensors as well as c…


            Basically you would do something like:


            from flask import Flask, render_template, Markup, request, redirect, session
            import mraa
            def tmp():
                            #Initialize the MRAA pin
                            pin = mraa.Aio(1) 
                            #Set it to a 12 bit value
                    except Exception,e:
                            print("Error: {:s}". format(e))
                    rawReading = pin.read()
                    #Galileo voltage should be the raw reading divided by 819.0
                    #The reading is from 0-4095 to cover 0-5 volts
                    #Or 4095/5=819.0
                    galVoltage=float(rawReading / 819.0)
                    tempC= (galVoltage * 100 ) - 50 
                    tempF= (tempC * 9.0 / 5.0) + 32.0
                    bodyText="Current Temperature: " + str(round(tempF,2)) 
                    return render_template('template.html', bodyText=bodyText) 


            When you navigate to /tmp the temperature is displayed.


            This is a handy quickstart on using Flask: http://flask.pocoo.org/docs/0.10/quickstart/#quickstart



            • 3. Re: ADC Data to WebServer
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi tbastosjp,

              Along with the suggestions from the other users, I would also suggest you to check this thread https://communities.intel.com/thread/49467. It was a similar case where the user was trying to send a string to a php site. There are some good answers that you might find helpful.


              • 4. Re: ADC Data to WebServer
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi tbastosjp,

                Do you have updates on this case? Have you tried any of the suggestions?


                • 5. Re: ADC Data to WebServer

                  Thank you for your contributions. I realized that I was not specific on the request.

                  Joe`s suggestion may work, but instead, I used Tornado`s handlers because it was already well documented in other posts and it seemed easier.

                  Tornado`s handler is here (I don`t know how to copy codes like Joe did):



                      app = tornado.web.Application(

                          handlers=[(r'/', IndexHandler),

                                    (r'/confirm', confirmPageHandler),

                                    (r'/measure', measurePageHandler, dict(signal_1 = signal_1, signal_2 = signal_2))],

                          template_path=os.path.join(os.path.dirname(__file__), "templates")


                      http_server = tornado.httpserver.HTTPServer(app)




                  the page where I want to update the values from the analog input is located inside measure.html (inside "templates" folder, which is located in the same path as the main python program).


                  Inside the measure.html page I have this code:


                    {% for item in measures %}

                    <li>SIGNAL: Analogsignal_1 = {{item[0]}} || Analogsignal_2 ={{item[1]}} </li>

                          {% end %}



                  The code above receives the variables of signal_1 and signal_2  (inside measures.py file) and prints it on the measure.html


                  I used another user`s codes as a base so I am not quite sure if I am explaining it correctly. Please feel free to comment and correct me, please.

                  I am planning to up all the code here when I finish!


                  Thank you for the support!