I am running into a problem using my enviro pHat from a daemon process. I am hoping that someone here can help me figure out what I am missing. I am trying to read the light sensor. The daemon dies w/ the following error:
pi@enviro0:~/src cat /var/tmp/tst03.err Traceback (most recent call last): File "tst03", line 32, in <module> createDaemon() File "tst03", line 29, in createDaemon doIt() File "tst03", line 15, in doIt lux = light.light() File "/usr/lib/python2.7/dist-packages/envirophat/tcs3472.py", line 71, in light return self.raw()[CH_CLEAR] File "/usr/lib/python2.7/dist-packages/envirophat/tcs3472.py", line 83, in raw c = self.i2c_bus.read_word_data(ADDR, REG_CLEAR_L) IOError: [Errno 25] Inappropriate ioctl for device pi@enviro0:~/src
The source is this:
pi@enviro0:~/src $ cat tst03
#!/usr/bin/env python
import daemon, sys, datetime
from envirophat import light
def doIt():
file = open (’/var/tmp/tst03.out’, ‘w+’)
while True:
lux = 0
tstamp = datetime.datetime.now().isoformat()
file.write("%30s %5d\n" % (tstamp, lux))
file.flush()
tstamp = datetime.datetime.now().isoformat()
lux = light.light()
file.write("%30s %5d\n" % (tstamp, lux))
file.flush()
time.sleep(10)
file.close()
def createDaemon():
dae = daemon.DaemonContext()
dae.stdout = open (’/var/tmp/tst03.out’, ‘w+’)
dae.stderr = open (’/var/tmp/tst03.err’, ‘w+’)
with dae:
doIt()
if name==“main”:
createDaemon()
pi@enviro0:~/src $
I have no problems if I do not try to daemonize the process; the pHat works as expected. What is it about my daemon process that causes the read failure from the i2c bus? FWIW, I am running jessie and obviously using python 2.7.
pi@enviro0:~/src lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 8.0 (jessie)
Release: 8.0
Codename: jessie
pi@enviro0:~/src uname -a
Linux enviro0 4.9.35+ #1014 Fri Jun 30 14:34:49 BST 2017 armv6l GNU/Linux
pi@enviro0:~/src $
Thanks,