Notifications
Clear all

[Solved] crontab job - Witty Pi board not connected

2 Posts
2 Users
0 Likes
295 Views
(@cknivu)
Posts: 4
Active Member
Topic starter
 

Hello,

 

I have written a python script which enables / disable a schedule script, depending on an external Pin. If the Pin is not set, then the schedule script isn't activated an the rasperry pi stays on.

When I start this script in the terminal, everything works fine 

python /home/pi/Python_Projects/NLR/gpio_test.py 

I want to start this script after reboot via crontab:

@reboot sleep 60 && cd /home/pi && python Python_Projects/NLR/gpio_test.py >> /home/pi/output_file.txt 2>&1

 

I get the following Error:

Start gpio_test.py
LOG_MODE =  True
Activate WittiPy Module
================================================================================

|                                                                              |

|   Witty Pi - Realtime Clock + Power Management for Raspberry Pi              |

|                                                                              |

|            < Version 4.13 >     by Dun Cat B.V. (UUGear)                     |

|                                                                              |

================================================================================



Seems Witty Pi board is not connected? Quitting...

 

I also added a 60seconds sleep after reboot but it didn't make a difference. Maybe can you help me?

 

My script looks like this:

import RPi.GPIO as GPIO
import os
import subprocess
import time
import re

log_mode_switch = 26
wittipycmd = '/home/pi/wittypi/wittyPi.sh'

def get_log_mode():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(log_mode_switch, GPIO.IN)
    return not GPIO.input(log_mode_switch)

def set_wittipy_module(enable=False):
    p = subprocess.Popen(wittipycmd,
                         stdout=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         shell=True,
                         bufsize=0)
    if enable:
        print('Activate WittiPy Module')
        # activate script
        scriptnum = 4
        options = '6 \n '+str(scriptnum)+' \n 13 \n' 
    else:
        print('Disable WittiPy Module')
        # disable script + startup timers
        options = '12 \n 1 \n  12 \n 2 \n  12 \n 3 \n  13 \n'
    p.stdin.write(options.encode())
    out = p.stdout.readline().decode('utf-8')
    while out:
        print(out)
        out = p.stdout.readline().decode('utf-8')



if __name__ == '__main__':

    log_mode = get_log_mode()
    print('LOG_MODE = ', log_mode)

    if log_mode:
        set_wittipy_module(enable=True)
    else:
        set_wittipy_module(enable=False)

 

 

 

 
Posted : 01/06/2023 8:53 am
(@admin)
Posts: 285
Member Admin
 

Could not tell the actual reason by reviewing the provided information. The Witty Pi board detection is done by using the "i2cdetect -y 1" command and 0x08 address should show up if the board is connected. Maybe you want to run that command first in your script to collect more debugging information in log.

However, the approach you are using to change the schedule script is not the most straightforward one. As suggested in the user manual, you can just copy the correct schedule script file to schedule.wpi file and then execute the "runScript.sh" to let it take effect. There is no need to deal with wittyPi.sh script.

In stead of running your Python script with crontab job, maybe it is better to call your Python script in the "beforeScript.sh" file, which will run before executing the schedule script.

 

 

 
Posted : 01/06/2023 9:14 am
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.