0

I work on a raspberry Pi. I did a small html page with 2 buttons calling executables via CGI and doing things. I would like to add a temperature display on the same page.

I have a small python script that reads the temperature of a sensor and I can successfully display it on console or via direct CGI (typing the url, the only thing displayed is the temperature). I would like to see the temperature directly on my html page, and be able to refresh the value by clicking a button.

I can't find any answer that might help me returning a value from the python script and displaying it in a textbox or something. Do you have any track for me to follow ?

2
  • A simple way is to make your CGI re-write the whole HTML page with the updated data. Commented Jul 29, 2016 at 11:16
  • normally you are better off with using WSGI instead of CGI - also frameworks like cherrypy or bottle make things easier Commented Jul 29, 2016 at 11:59

1 Answer 1

0

You can write out a complete html page with CGI

A simple CGI script would be

temp=100
print("Content-Type: text/html")    # HTML is following
print()                             # blank line, end of headers
print("<!doctype html>")
print("<html><head><title>Example</title></head><body>")
print("<p>Temperature is:",temp)
print("</p>")
peint('<a href="#">Reload<a>')
print("</body></html>")

you can also use javascript in a page to (re)load the value with Ajax - there are examples on the page (only replace the php-script with your python-cgi)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.