schoolpost / PiDNG

Create Adobe DNG RAW files using Python. Works with any Bayer RAW Data including native support for Raspberry Pi cameras.
MIT License
199 stars 37 forks source link

Trouble calling PyDNG from script #36

Closed Schaggo closed 3 years ago

Schaggo commented 3 years ago

This might be a total noob error, but I'm banging my head against the keyboard for some hours now.

Here's what I am trying to do: I have a script "listen.py" that waits for user input via GPIO or UDP command - then takes an image via raspistill(), converts it via PyDNG and uploads it via ftp.

When I launch said listen.py via ssh everything behaves as intended. But when I launch the script via a script that updates listen.py through systemd service I get a ValueError and exit code 1 for PyDNG.

Does anybody have a clue why this is happening?

listen.py:


if  isTakingImage == False:
        isTakingImage = True
        GPIO.remove_event_detect(BUTTON)
        shutter = 1000000 / fractor       #in microseconds / 1s = 1000000us
        timea = datetime.utcnow()
        print("taking image...")

        subprocess.call(['raspistill -o /home/pi/startup/current.jpg --raw -md 3 -awb flash -q 100 -ex spotlight --timeout 2 --nopreview --shutter ' + str(shutter) +' --ISO 100'], shell=True)

        gc.collect()
        time.sleep(1)
        print("extracting dng...")
      #  subprocess.check_call(['python3.7 /home/pi/PyDNG/examples/utility.py current.jpg'], shell=True)

      # use file string input to the jpeg+raw file. 
        d = RPICAM2DNG()
        d.convert('current.jpg')
        timeb = datetime.utcnow()
        print("uploading image")
        from ftplib import FTP

        [ftp stuff]

start.py:

print("updateing scripts")
try:
    ftp = ftplib.FTP("192.168.178.34", "Medusa", "Medusa")
    ftp.login("Medusa", "Medusa")
    lf = open("/home/pi/startup/listen.py", "wb")
    ftp.retrbinary("RETR " + "listen.py", lf.write, 8*1024)
    lf.close()
    lf = open("/home/pi/startup/focus.py", "wb")
    ftp.retrbinary("RETR " + "focus.py", lf.write, 8*1024)
    lf.close()
    ftp.quit()
except ftplib.all_errors as e:
    print('FTP error:', e)

print("done")

print ("starting listen script")

os.system("sudo python3 /home/pi/startup/start.py")`

systemd service start.service:


[Unit]
Description=My Sample Service
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStartPre=/bin/sh -c 'until ping -c1 google.com; do sleep 1; done;'
ExecStart=/usr/bin/python3.7 /home/pi/startup/start.py > /home/pi/start.log 2>&1

[Install]
WantedBy=multi-user.target`
Schaggo commented 3 years ago

Never mind. I'm simply an idiot. I forgot to change the working directory. d.convert('/home/pi/startup/current.jpg')