Задание Cron работает, но вывод файла не выполняется [дубликат]

cronjob работает отлично, но не создается,! !! когда я запускаю свой скрипт python вручную, он дает результат, но в задании cron он не генерировал результат

Dec 23 15:10:01 raspberrypi CRON[3265]: (pi) CMD (/home/pi/Desktop/sensor_baloon.py >/dev/null 2>&1)
Dec 23 15:11:01 raspberrypi CRON[3334]: (pi) CMD (/home/pi/Desktop/sensor_baloon.py >/dev/null 2>&1)
Dec 23 15:12:01 raspberrypi CRON[3355]: (pi) CMD (/home/pi/Desktop/sensor_baloon.py >/dev/null 2>&1)
Dec 23 15:13:01 raspberrypi CRON[3482]: (pi) CMD (/home/pi/Desktop/sensor_baloon.py >/dev/null 2>&1)
Dec 23 15:14:01 raspberrypi CRON[3569]: (pi) CMD (/home/pi/Desktop/sensor_baloon.py >/dev/null 2>&1)

это мой рабочий код без каких-либо ошибок ..!

import RPi.GPIO as GPIO
import time,os

import datetime


TRIG = 24
ECHO = 23
ALARM = 17

# Speed of sound in cm/s at temperature
temperature = 20
speedSound = 34326 + (0.6*temperature)

print("Ultrasonic Measurement")
print("Speed of sound is",speedSound/100,"m/s at ",temperature,"deg")

GPIO.setmode(GPIO.BCM)

GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG, False)

GPIO.setup(ALARM,GPIO.OUT)
GPIO.output(ALARM, True)

print ("Waiting For Sensor To Settle")
time.sleep(1) #settling time 

def get_distance():
    dist_add = 0
    k=0
    for x in range(30):
        try:
            GPIO.output(TRIG, True)
            time.sleep(0.00001)
            GPIO.output(TRIG, False)

            while GPIO.input(ECHO)==0:
                pulse_start = time.time()

            while GPIO.input(ECHO)==1:
                pulse_end = time.time()

            pulse_duration = pulse_end - pulse_start
            
            distance = pulse_duration * speedSound

            distance = round(distance, 1)
            distance = distance/2
            print (x, "distance: ", distance)
        
            if(distance > 125):# ignore erroneous readings (max distance cannot be more than 125)
                k=k+1
                continue
        
            dist_add = dist_add + distance
            #print "dist_add: ", dist_add
            time.sleep(.1) # 100ms interval between readings
        
        except Exception as e: 
        
            pass
    
    
    print ("x: ", x+1)
    print ("k: ", k) 
    avg_dist=dist_add/(x+1 -k)
    dist=round(avg_dist,2)
    #print ("dist: ", dist)
    return dist

def sendData_to_remoteServer(url,dist):
    url_full=url+str(dist)
    urlopen(url_full)
    print("sent to url: ",url_full)
    
def low_level_warning(dist):
    level=114-dist
    if(level<40):
        print("level low : ", level)
        GPIO.output(ALARM, False)
    else:
        GPIO.output(ALARM, True)
        print("level ok")
        
from urllib.request import urlopen



#local web server is running 
url_remote="http://localhost/web_host/watertank/insert_data_baloon.php?level="

distance=get_distance()

print ("distance: ", distance ,"cm") 

sendData_to_remoteServer(url_remote,distance)

low_level_warning(distance)

print ("---------------------")
1
задан 23 December 2020 в 13:05

0 ответов

Другие вопросы по тегам:

Похожие вопросы: