XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
For #3, I wouldn't fool with Chron - just calculate number of seconds until next run and sleep() that long. That way if the system restarts, your process runs immediately and calculates the time until the next run time. That way there is no Chron file involved. You are reinventing the wheel here. cron does exactly that. Calculate the sleep time until the next job needs to run, and sleep. If it wakes up early, that almost certainly has happened because someone submitted changes to the job list (i.e. running crontab). Oh, and by the way, don't blindly run after sleep returns. sleep may be interrupted, so your process may have slept for a much shorter time than expected. There might be some startup race conditions after a power failure. I'm not sure about the Pi config options are when the Pi cannot get current date/time from the internet? Maybe Pi is "ready" before the router to the internet? That could be detected in startup scripts. Linux starts at unix time 0, i.e. 1970-01-01 00:00:00 UTC. So if the application detects a system time years before it was written (if (year < 2020) would be sane), it should assume a fresh boot and just wait for ntpd to do its job. Also, there are RTC chips for the Raspi, so that it adjusts the system clock very early in the boot process, before cron and other services run. Think about a status LED - perhaps blinking means good - stuck on(or off) means bad. Good idea, easy to implement. Add a cheap red LED (based on GaAs, voltage drop about 1.6 V) and a resistor to a GPIO pin. GPIO voltage level is about 3.3 V, LED current should be around 5 mA, so the resistor value is R = U / I = (3.3 V - 1.6 V) / 5 mA = 340 Ohm. Close standard values are 330 Ohm and 390 Ohm. Heat dissapation is P = U * I = 1.7 V * 5 mA = 8.5 mW for 5 mA. Any cheap resistor can easily heat away at least 125 mW. LED should be connected between GPIO pin and GND, with the resistor in series wih the LED. If the LED is too bright, decrease the current by increasing the resistor value. To get 1 mA, you need 1.7 kOhm, close standard value is 1.8 kOhm. Only very few LEDs are visible at less than 1 mA, so that's about the upper limit for the resistor. The Raspi can't sink or source significantly more than 15 mA, and has an additional limit of about 50 mA for the sum of all GPIO pins, so you don't want more that 5 to 10 mA for the LED, so the resistor should not be less than 170 Ohm. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) In reply to Re^2: Continuous or timed?
by afoken
|
|