Community
cancel
Showing results for 
Search instead for 
Did you mean: 
AUne
Beginner
1,484 Views

ADC Data to WebServer

Jump to solution

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!

Tags (1)
1 Solution
AUne
Beginner
70 Views

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):

tornado.options.parse_command_line()

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)

http_server.listen(options.port)

tornado.ioloop.IOLoop.instance().start()

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 %}
    • SIGNAL: Analogsignal_1 = {{item[0]}} || Analogsignal_2 ={{item[1]}}
    {% 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!

    Anderson

    View solution in original post

    5 Replies
    FTinetti
    Honored Contributor I
    70 Views

    Hi,

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

    Fernando.

    idata
    Community Manager
    70 Views

    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: https://github.com/joemcmanus/GalileoPyServer 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

     

    .....

     

    @app.route('/tmp')

    def tmp():

    try:

    # Initialize the MRAA pin

    pin = mraa.Aio(1)

    # Set it to a 12 bit value

    pin.setBit(12)

    except Exception,e:

    print("Error: {:s}". format(e))

    sys.exit()

    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 http://flask.pocoo.org/docs/0.10/quickstart/# quickstart

    -Joe

    idata
    Community Manager
    70 Views

    Hi tbastosjp,

     

     

    Along with the suggestions from the other users, I would also suggest you to check this thread /thread/49467 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.

     

     

    Regards,

     

    Pablo
    idata
    Community Manager
    70 Views

    Hi tbastosjp,

     

     

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

     

     

    Regards,

     

    Pablo
    AUne
    Beginner
    71 Views

    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):

    tornado.options.parse_command_line()

    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)

    http_server.listen(options.port)

    tornado.ioloop.IOLoop.instance().start()

    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 %}
      • SIGNAL: Analogsignal_1 = {{item[0]}} || Analogsignal_2 ={{item[1]}}
      {% 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!

      Anderson

      View solution in original post

      Reply