Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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
in thread Continuous or timed? by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found