0

I an using Raspberry PI zero W and connected 5 sensors to getting reading from sensors. i used services for start the sensors scripts and i installed python apscheduler for time sequence.

Sometime working, suddenly raise issue like "python[2132]: WARNING:apscheduler.scheduler:Execution of job " (trigger: interval[0:01:00], next run at: 2019-10-04 10:18:01 EDT)" skipped: maximum number of running i"

Oct 04 10:19:01 RPZ-3 python[2132]: WARNING:apscheduler.scheduler:Execution of job " (trigger: interval[0:01:00], next run at: 2019-10-04 10:19:01 EDT)" skipped: maximum number of running i Oct 04 10:20:01 RPZ-3 python[2132]: WARNING:apscheduler.scheduler:Execution of job " (trigger: interval[0:01:00], next run at: 2019-10-04 10:20:01 EDT)" skipped: maximum number of running i Oct 04 10:21:01 RPZ-3 python[2132]: WARNING:apscheduler.scheduler:Execution of job " (trigger: interval[0:01:00], next run at: 2019-10-04 10:21:01 EDT)" skipped: maximum number of running i Oct 04 10:22:01 RPZ-3 python[2132]: WARNING:apscheduler.scheduler:Execution of job " (trigger: interval[0:01:00], next run at: 2019-10-04 10:22:01 EDT)" skipped: maximum number of running i Oct 04 10:23:01 RPZ-3 python[2132]: WARNING:apscheduler.scheduler:Execution of job " (trigger: interval[0:01:00], next run at: 2019-10-04 10:23:01 EDT)" skipped: maximum number of running i

Every time after reboot Sometime working. Please give me the solution for this issue.

Please find below code for Barometer Sensor job creation.

#!/usr/bin/python
import os
import time
import datetime
import MySQLdb
import sys
import logging

from apscheduler.schedulers.blocking import BlockingScheduler

logging.basicConfig()
scheduler = BlockingScheduler()

def EnterLog(text):
    print("[" + datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S.%f') + "] [SaveBarometerSensorData.py]: " + text)

def WaitForZeroSecond():
    flag = True
    while flag:
        sec = int(datetime.datetime.utcfromtimestamp(time.time()).strftime('%S'))
        time.sleep(1)
        delay = 56 #for raspberry pi zero board
        #delay = 59 #for raspberry pi III model B
        if (sec == delay):
            flag = False

def getToleratedDateTime(interval):
    tempDateTime = datetime.datetime.utcfromtimestamp(time.time())
    sec = int(datetime.datetime.utcfromtimestamp(time.time()).strftime('%S'))

    if (interval < 60):
        addSec = 0
        tol = sec % interval
        if (tol > (interval / 2)):
            tempDateTime = tempDateTime + datetime.timedelta(seconds=interval)
        else:
            tempDateTime = tempDateTime - datetime.timedelta(seconds=tol)

    strTime = tempDateTime.strftime('%Y-%m-%d %H:%M:%S')

    return strTime

def SaveJob(pythonScriptPath, model, pin, state, interval, id):
    if (state == 1):
        strTime = getToleratedDateTime(interval)
        fileName = '/home/pi/projects/logs/PythonJobs_Log_' + datetime.datetime.now().strftime('%Y_%m_%d_%H') + '.log'
        if not os.path.isfile(fileName):
            os.mknod(fileName)
        os.system("sudo chmod 777 " + fileName)
        command = "python " + pythonScriptPath + " " + str(pin) + " '" + strTime + "' " + str(id) + " >> " + fileName + " 2>&1"
        #Here calling sensor script with parameters.
        os.system(command)

try:
    sensorName = 'Barometer'
    # DB parameters
    hostname = 'localhost'
    port = 3306
    username = 'pi'
    password = 'password'
    database = 'SensorInformation'
    query = "SELECT ID, Name, PythonScriptPath, Model, Pins, MeasurementInterval, State FROM SensorSettings where Name='" + sensorName + "'"

    db = MySQLdb.connect(host = hostname, port=port, user = username, passwd = password, db = database)
    if (db):
        # print('Connected to MySQL database')
        cur = db.cursor()
        cur.execute(query)
        WaitForZeroSecond()
        for id, name, pythonScriptPath, model, pin, measurementInterval, state in cur.fetchall() :
            # Python schedular initialize 
            if (measurementInterval > 0) :
                scheduler.add_job(lambda: SaveJob(pythonScriptPath, model, pin, state, measurementInterval, id), "interval", seconds=measurementInterval,  id=sensorName + "SensorSaveDataJobId_" + str(id))
        cur.close()
        db.close()
        # Start the initialize.
        scheduler.start()
    else:
        EnterLog("Failed to connect database, " + e.message)
except Exception as e:
    EnterLog("Error: " + e.message)


5
  • Why not have 1 Python program running constantly checking all 5 sensors at periodic intervals - much simpler?
    – CoderMike
    Oct 4, 2019 at 15:25
  • i need to get readings at a same time.
    – Nagaraj
    Oct 4, 2019 at 15:29
  • Maybe one of answers at stackoverflow.com/questions/34020161/… is helpful?
    – Dirk
    Oct 4, 2019 at 15:50
  • Add your Python code to your post.
    – CoderMike
    Oct 4, 2019 at 16:17
  • I added my code also, the code only for one type of sensor. i am using 5 different types of sensors on single RPi device.
    – Nagaraj
    Oct 7, 2019 at 10:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.