I'm looking for the simplest possible way for a script (or any sort of program, can be C, Python, whatever you like within reason) to check whether mains power is on.
The computer which is going to check this is running off batteries so will still be running (I'm not quite that stupid!).
The easiest way I can think of at the moment is to have some sort of hardware with a presence on the LAN powered by mains so that one can ping it to check that mains power is there. However the 'simplest' device I have at the moment is an old router which seems rather overkill for such a simple requirement.
Can anyone think of any better way of doing this for which I am likely to have the hardware available or which will cost very little? I'm quite happy to build simple bits of electronics. The computer running the check is an old eeePc so has only USB and ehternet connections as far as I remember.
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
Peter.
On 26 January 2011 15:51, samwise samwise@bagshot-row.org wrote:
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
Peter
No need for such complexities, use a web cam pointing at the little red power light.... I'll get my coat..... :-)
On Wed, Jan 26, 2011 at 04:05:42PM +0000, John Woodard wrote:
On 26 January 2011 15:51, samwise samwise@bagshot-row.org wrote:
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
Peter
No need for such complexities, use a web cam pointing at the little red power light.... I'll get my coat..... :-)
I do already have a webcam, and it's just about working. However it's not very clever for a programmatic check on mains power! :-)
You could get one of these and wire it to the mains http://www.youtube.com/watch?v=lTzByQTeyJQ
On Wed, Jan 26, 2011 at 4:46 PM, Chris G cl@isbd.net wrote:
On Wed, Jan 26, 2011 at 04:05:42PM +0000, John Woodard wrote:
On 26 January 2011 15:51, samwise samwise@bagshot-row.org wrote:
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
Peter
No need for such complexities, use a web cam pointing at the little red power light.... I'll get my coat..... :-)
I do already have a webcam, and it's just about working. However it's not very clever for a programmatic check on mains power! :-)
-- Chris Green
main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
On Wed, Jan 26, 2011 at 03:51:14PM +0000, samwise wrote:
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
I thought someone would say that, I should have explained better. :-)
The eeePc is running from an *external* battery supply, not from its own internal battery. Hence, from its point of view, 'mains' power will always be available and /proc/acpi/battery/BAT0/state won't change.
I don't want to run it from a mains power supply and rely on its internal battery to last over any mains power failures. A mains power failure where it is might last for a day or two because it will probably be caused by local circuit breakers tripping and they will need someone to go and reset them.
On 26 Jan 16:16, Chris G wrote:
On Wed, Jan 26, 2011 at 03:51:14PM +0000, samwise wrote:
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
I thought someone would say that, I should have explained better. :-)
The eeePc is running from an *external* battery supply, not from its own internal battery. Hence, from its point of view, 'mains' power will always be available and /proc/acpi/battery/BAT0/state won't change.
I don't want to run it from a mains power supply and rely on its internal battery to last over any mains power failures. A mains power failure where it is might last for a day or two because it will probably be caused by local circuit breakers tripping and they will need someone to go and reset them.
Please define "external battery". Is this "external battery" a UPS unit? If so, why not just query the UPS?
On Thu, Jan 27, 2011 at 10:33:59AM +0000, Brett Parker wrote:
On 26 Jan 16:16, Chris G wrote:
On Wed, Jan 26, 2011 at 03:51:14PM +0000, samwise wrote:
Chris,
Shouldn't you be able to get this info from your computer itself?
Something like:
cat /proc/acpi/battery/BAT0/state
Or maybe google for acpi or acm ... ?
The battery widgets which show you whether your battery is in use or charging, must make use of this info.
I thought someone would say that, I should have explained better. :-)
The eeePc is running from an *external* battery supply, not from its own internal battery. Hence, from its point of view, 'mains' power will always be available and /proc/acpi/battery/BAT0/state won't change.
I don't want to run it from a mains power supply and rely on its internal battery to last over any mains power failures. A mains power failure where it is might last for a day or two because it will probably be caused by local circuit breakers tripping and they will need someone to go and reset them.
Please define "external battery". Is this "external battery" a UPS unit? If so, why not just query the UPS?
No, the "external battery" is simply the 400 Ah 'Leisure' battery on the boat. Come to think of it though you may have pointed me at a possibility, the battery charger that maintains the leisure battery has a remote display which has presumably some sort of interface to drive it. It could well be that I can get information from there into the computer.
On 27-Jan-11 10:40:14, Chris G wrote:
[snip] The eeePc is running from an *external* battery supply, not from its own internal battery. Hence, from its point of view, 'mains' power will always be available and /proc/acpi/battery/BAT0/state won't change.
I don't want to run it from a mains power supply and rely on its internal battery to last over any mains power failures. A mains power failure where it is might last for a day or two because it will probably be caused by local circuit breakers tripping and they will need someone to go and reset them.
Please define "external battery". Is this "external battery" a UPS unit? If so, why not just query the UPS?
No, the "external battery" is simply the 400 Ah 'Leisure' battery on the boat. Come to think of it though you may have pointed me at a possibility, the battery charger that maintains the leisure battery has a remote display which has presumably some sort of interface to driveit. It could well be that I can get information from there into the computer.
-- Chris Green
A slightly "hands dirty" thought which occurred to me earlier in this thread may possibly be becoming relevent ...
Since the eeePc already has the external battery plugged into its "mains" socket, it can't monitor the mains. But perhaps you have something like one of those old "dictaphone" type mini cassette recorders lying around unused, where you could connect the mains to the recorder, and connect say the headphone output of the recorder to an input socket on the eeePc, leaving the recorder switched on, which could then be monitored by the eeePc.
That way, if mains power failed, the signal on the recorder output would drop and the eeePc would know.
Or maybe some similar bit of kit which produces a low output voltage when connected to a live mains.
Any mileage in that? Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 27-Jan-11 Time: 10:59:24 ------------------------------ XFMail ------------------------------
On Thu, Jan 27, 2011 at 10:59:28AM -0000, Ted Harding wrote:
On 27-Jan-11 10:40:14, Chris G wrote:
[snip] The eeePc is running from an *external* battery supply, not from its own internal battery. Hence, from its point of view, 'mains' power will always be available and /proc/acpi/battery/BAT0/state won't change.
I don't want to run it from a mains power supply and rely on its internal battery to last over any mains power failures. A mains power failure where it is might last for a day or two because it will probably be caused by local circuit breakers tripping and they will need someone to go and reset them.
Please define "external battery". Is this "external battery" a UPS unit? If so, why not just query the UPS?
No, the "external battery" is simply the 400 Ah 'Leisure' battery on the boat. Come to think of it though you may have pointed me at a possibility, the battery charger that maintains the leisure battery has a remote display which has presumably some sort of interface to driveit. It could well be that I can get information from there into the computer.
-- Chris Green
A slightly "hands dirty" thought which occurred to me earlier in this thread may possibly be becoming relevent ...
Since the eeePc already has the external battery plugged into its "mains" socket, it can't monitor the mains. But perhaps you have something like one of those old "dictaphone" type mini cassette recorders lying around unused, where you could connect the mains to the recorder, and connect say the headphone output of the recorder to an input socket on the eeePc, leaving the recorder switched on, which could then be monitored by the eeePc.
That way, if mains power failed, the signal on the recorder output would drop and the eeePc would know.
Or maybe some similar bit of kit which produces a low output voltage when connected to a live mains.
Any mileage in that?
Someone else suggested a similar approach, using a mains transformer to obtain a low level 50Hz signal and feeding that into the recorder input. I'm not quite sure how you detect presence/absence of an audio signal though - however I'm sure it can't be that difficult.
I've been following this from afar without the ability to reply, but it's been interesting reading!
Now that I'm back, the only suggestion I can add to the mix from the top of my head would be mains powered lamp pointing at a webcam, which given the contrast difference between light on and light off ought to be fairly possible to determine programatically whether it was on or off without being too clever. If there's an existing webcam (which I believe there is but I'm not sure it's available to the eeePC?) then this could probably be used but might be more fun to get working (eg if there's a light on in the room that the camera is monitoring and you have access to the images, then the contrast difference between light on/off should be detectable).
On 27 Jan 10:40, Chris G wrote:
On Thu, Jan 27, 2011 at 10:33:59AM +0000, Brett Parker wrote:
Please define "external battery". Is this "external battery" a UPS unit? If so, why not just query the UPS?
No, the "external battery" is simply the 400 Ah 'Leisure' battery on the boat. Come to think of it though you may have pointed me at a possibility, the battery charger that maintains the leisure battery has a remote display which has presumably some sort of interface to drive it. It could well be that I can get information from there into the computer.
If you've got a parallel port on the computer that's attached you could make a fairly simple circuit that puts one of the pins high on the parallel port and then read the status using some Evil Code (tm).
If there's no other way of interfacing with the charger, that'd probably be the way I'd go.
On 26 Jan 2011, at 15:41, Chris G wrote:
I'm looking for the simplest possible way for a script (or any sort of program, can be C, Python, whatever you like within reason) to check whether mains power is on.
The computer which is going to check this is running off batteries so will still be running (I'm not quite that stupid!).
The easiest way I can think of at the moment is to have some sort of hardware with a presence on the LAN powered by mains so that one can ping it to check that mains power is there. However the 'simplest' device I have at the moment is an old router which seems rather overkill for such a simple requirement.
Can anyone think of any better way of doing this for which I am likely to have the hardware available or which will cost very little? I'm quite happy to build simple bits of electronics. The computer running the check is an old eeePc so has only USB and ehternet connections as far as I remember.
Find a USB device that is powered by an external supply, plug that supply into the mains and check for it from the command line lsusb. E.g. an external hard disk, or an old hub, or some arduino-style project, or rip the guts out of a dumpster-dived usb printer.
For a more over-engineerd electronics solution I'm sure you can throw together some usb-bus-powered arduino with an optocoupler that checks the (down-transformed) supply explicitly, then communicate that back over usb to a custom program on your computer. Complex, and requires knowledge, skill, and money, but would be fun.
I'm not sure how the running costs compare, but pinging your router sounds like a fine idea. If you think that using your router is overkill, buy a cheap second hand one off ebay. You can probably find a faulty one where the adsl modem part has blown up, but the rest may still work well enough to ping.
-- Martijn
On Fri, 28 Jan 2011 12:12:08 +0000 Martijn Koster mak-alug@greenhills.co.uk allegedly wrote:
On 26 Jan 2011, at 15:41, Chris G wrote:
I'm looking for the simplest possible way for a script (or any sort of program, can be C, Python, whatever you like within reason) to check whether mains power is on.
The computer which is going to check this is running off batteries so will still be running (I'm not quite that stupid!).
The easiest way I can think of at the moment is to have some sort of hardware with a presence on the LAN powered by mains so that one can ping it to check that mains power is there. However the 'simplest' device I have at the moment is an old router which seems rather overkill for such a simple requirement.
Anything mains powered with an IP address will do . So your router would be fine. Or any of a large range of "home automation" devices which are networkable (http://home-automation.org/) if you actually want to spend money on gadgets.
Mick ---------------------------------------------------------------------
The text file for RFC 854 contains exactly 854 lines. Do you think there is any cosmic significance in this?
Douglas E Comer - Internetworking with TCP/IP Volume 1
http://www.ietf.org/rfc/rfc854.txt ---------------------------------------------------------------------
On 28/01/11 13:48, mick wrote:
Anything mains powered with an IP address will do . So your router would be fine. Or any of a large range of "home automation" devices which are networkable (http://home-automation.org/) if you actually want to spend money on gadgets.
Taking another sideways step, you can get a multimeter on eBay for about £30 that has a USB port, although no mention of drivers for Linux. You can also get USB-based dual channel oscilloscopes for not too much money. Something like that might allow you to monitor the power but also have other monitoring uses on the boat should you think up an application. If you're handy with a soldering iron I'd have thought it ought to be quite easy to knock together a monitoring circuit that would give you more information back for your money (start at Maplin, see what toys they have, then google for cheaper ways to do the same thing!)
Another thought is the variety of cheap boxes with current transformers for monitoring domestic power usage; sometimes given away by power companies, although one with a USB connection may cost you a bit more. But again, you might be able to get something more out of it than just the fact that power is available.
All this said, I think you'd be hard pushed to beat a cheap UPS with a USB port for which you'd find drivers and functionality galore in Linux.
On 28/01/11 14:15, Mark Rogers wrote:
Taking another sideways step, you can get a multimeter on eBay for about £30 that has a USB port, although no mention of drivers for Linux.
If you look at the Uni-T ones then there are perl and python scripts kicking around the net that will extract the data. However there is a problem.
All meters that meet a reasonable safety standard have an optical data connection which means they cannot be bus powered. My Uni-T running with the data connection enabled and the power save turned off manages a couple of weeks at best from high quality cells.
I think Brett's idea makes the most sense. Use a relay with a mains coil to pull a parallel port pin down (I'd suggest pins 12 and 13 are easiest to work with)
Load the pyParallel module http://pyserial.sourceforge.net/pyparallel.html
then use
getInPaperOut() or getInSelected() to read the status of pins 12 or 13 respectively
Shimples