show instant data on webpage

David Palao dpalao.python at gmail.com
Tue Jan 26 11:38:28 EST 2016


2016-01-26 17:10 GMT+01:00 mustang <mustang at nomail.it>:
> I've built a sensor to measure some values.
> I would like to show it on a web page with python.
>
>
> This is an extract of the code:
>
> file  = open("myData.dat", "w")
>
> while True:
>         temp = sensor.readTempC()
>         riga = "%f\n" % temp
>         file.write(riga)
>         time.sleep(1.0)
>
> file.close()
>
> Until this all ok.
> Then in PHP I read the file and show it on internet. It works ok but...
> First problem. I've to stop the streaming with CTRl-C to load the PHP file
> because if I try to read during measurement I cannot show anything (I think
> because the file is in using).
> How can I show time by time in a webpage the output?
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Is this an option?

open("myData.dat", "w").close()

while True:
    temp = sensor.readTempC()
    riga = "%f\n" % temp
    with open("myData.dat", "a") as f:
        f.write(riga)
    time.sleep(1)

Best



More information about the Python-list mailing list