Green Building Bible, Fourth Edition |
![]() |
These two books are the perfect starting place to help you get to grips with one of the most vitally important aspects of our society - our homes and living environment. PLEASE NOTE: A download link for Volume 1 will be sent to you by email and Volume 2 will be sent to you by post as a book. |
Vanilla 1.0.3 is a product of Lussumo. More Information: Documentation, Community Support.
#!/usr/bin/python
import datetime
# ....
temperature = 42.5 # Dummy
tfile = open("/home/pi/Desktop/tempdata.txt","w")
#writes the temperature data to the tempdata/txt file
tfile.write("%s: Temp C,%s" % (datetime.datetime.utcnow(), temperature) +'\n')
#closes the tempdata.txt file
tfile.close()
Posted By: SteamyTeaAnd the final thing for now is how do I force a new line in my tempdata.txt file so that I do not overwrite the data I have in there.
2013-01-24 23:28:41.030513: Temp C,42.5
2013-01-24 23:37:23.421996: Temp C,42.5
2013-01-24 23:37:35.034155: Temp C,42.5
Posted By: SteamyTeaIs it possible to put the modprode w1-gpio and modprobe w1-therm commands into the Python script at the very begining?
from subprocess import check_call
check_call(["modprobe", "w1-gpio"])
Posted By: SteamyTeaThe other thing is that when it writes to the tempdata.txt file a terminal window telling me that it all went alright opens up which has to be closed before I can read the file (or reload it). What is that about?
Posted By: SteamyTeaFound out that indenting is not always indenting (4 spaces is better than a tab apparently).
Posted By: Ed DaviesPosted By: SteamyTeaIs it possible to put the modprode w1-gpio and modprobe w1-therm commands into the Python script at the very begining?
Yes, use the subprocess.call function to run an external program.
Posted By: SteamyTeaI am starting it from Geany, if I want to start if from the .py file, do I have to compile it first (whatever that does)
and do I have to make it executable?
Does either of them stop me editing it after?
Posted By: SteamyTeaWith this subprocess thingy I should be able to look at the w1/devices directory and get the unique ID for each sensor and somehow put that into my scrip as a variable so save having to manually edit the scrip each time I change a sensor. Is that and easy thing to do?
>>> import os
>>> os.listdir('/sys/bus')
['platform', 'pci', 'rapidio', 'spi', 'i2c', 'eisa', 'MCA', 'acpi', 'pnp', 'scsi', 'mdio_bus', 'usb', 'serio', 'mmc', 'sdio', 'event_source', 'pci_express', 'isa', 'ssb', 'hid', 'pcmcia']
>>> import glob
>>> glob.glob('/sys/bus/*')
['/sys/bus/platform', '/sys/bus/pci', '/sys/bus/rapidio', '/sys/bus/spi', '/sys/bus/i2c', '/sys/bus/eisa', '/sys/bus/MCA', '/sys/bus/acpi', '/sys/bus/pnp', '/sys/bus/scsi', '/sys/bus/mdio_bus', '/sys/bus/usb', '/sys/bus/serio', '/sys/bus/mmc', '/sys/bus/sdio', '/sys/bus/event_source', '/sys/bus/pci_express', '/sys/bus/isa', '/sys/bus/ssb', '/sys/bus/hid', '/sys/bus/pcmcia']
Posted By: borpinI wish I had the time to fiddle with my Pi......I would say fiddle with mine but would only get you into trouble.
Posted By: Nick ParsonsSplendid piece on Woman's Hour last weekWatch my video if your interested in my comments about Woman' Hour: