1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add UPS (APCUPSD) Support to Shibby/Toastman Builds

Discussion in 'Tomato Firmware' started by arrmo, Oct 27, 2011.

  1. arrmo

    arrmo Addicted to LI Member

    Hi,

    In case you're interested, here is how I added UPS support to Toastman builds. I can now see APCUPSD info in the web interface, and also receive email notifications of events (sent from the router).

    Yell if you have any questions or issues.
     

    Attached Files:

  2. occamsrazor

    occamsrazor Network Guru Member

    Your guide is a bit above my skills, but assuming this works I'd love to see it incorporated in e.g. Shibby's build. Can you post a screenshot of what is seen in the web interface?
     
  3. arrmo

    arrmo Addicted to LI Member

    Hi

    The attached picture is what it looks like. As for adding this in to a specific build, I'll leave that to the authors of those builds to comment.

    Thanks.
     

    Attached Files:

  4. shibby20

    shibby20 Network Guru Member

    nice work. Can you give me compressed sources to tar.gz? I think in pdf file patch is not completed. I dont see asp file and modified rc files (i think you created some of service or something like that, am i right?).

    Best Regards!
     
    occamsrazor likes this.
  5. arrmo

    arrmo Addicted to LI Member

    Hi,

    I can try to do that, or I can modify a copy locally - which makes more sense? Do you have RT (normal) support?

    Thanks!
     
  6. shibby20

    shibby20 Network Guru Member

    Yes i do. My tomato mod is based on tomato-RT. All i need is a fully patch or compressed files added or modified by you.
     
  7. arrmo

    arrmo Addicted to LI Member

    Hi,

    OK, I'll try to get this working with your branch. I'm tied up the next week or two, but should get to it after that.

    Does your branch build in the same manner as Toastman? Just so I know how to get it going.

    Thanks.
     
  8. occamsrazor

    occamsrazor Network Guru Member

    Thank you both for your work on this. I'm getting an APC BR1500GI in the next couple days and will be happy to test when a working build is ready. Currently I'm running Shibby's Tomato Firmware 1.28.0905 MIPSR2-079V K26 USB Mega-VPN on my Linksys E3000.
     
  9. arrmo

    arrmo Addicted to LI Member

    Hi,

    Well, I was able to get to this, and have a build to test ... but before starting the build for this I first built the stock Shibby build, but it seems to have taken my router down ... :-(. I can get in from the LAN interface, but the WAN port seems dead - no lights, no IP address via DHCP. Is this a known issue (on an Asus RT-N12)?

    I'm stuck until I can get this fixed ... :-(.

    Thanks.
     
  10. arrmo

    arrmo Addicted to LI Member

    BTW, I have cleared NVRAM (normal and thorough) ... no help ... :-(.
     
  11. occamsrazor

    occamsrazor Network Guru Member

    Hi Arrmo, did you manage to unbrick your router? I hope so...

    On a Tomato-unrelated note, I got my APC BR1500Gi UPS and it is sweet! Digital display, AVR, Master/Slave sockets, adjustable sensitivity, etc, for a quite reasonable price considering all that. The nice thing is you can adjust everything via the buttons - no need to plug into a Windows machine to set the advanced features (I use Macs). Now I've ordered the extended battery pack BP24BPG which basically ups the capacity from 1500va to 4500va.

    Anyway, all that a bit off-topic but figured anyone reading this thread might be interested. Any progress on implementing the apcusbd functionality?
     
  12. arrmo

    arrmo Addicted to LI Member

    Hi,

    Yep, all resolved. and I have the UPS build working locally. I have sent my changes to Shibby, hopefully he is getting a chance to integrate them.

    Thanks!
     
  13. occamsrazor

    occamsrazor Network Guru Member

    Good news, and thanks for the nice work...

    Shibby - don't know what extra size this adds to a build, but which are you planning to add it to? Am currently using Mega-VPN but think I'll have to switch to BT-VPN as I've realised I need the CIFS client.

    Just thinking out loud, but wondering what one might be able to do with the information retrieved from the UPS. Presumably one could write a script that monitors the time left on battery and at a certain low point initiate a router shutdown. What would be great would be to send commands to shutdown client computers too, but guess that might be more difficult.

    Anyway, looking forward to trying it, though think I'll need to get a USB hub first as my E3000 only has one USB port and that's currently being used by my USB 3G modem.
     
  14. occamsrazor

    occamsrazor Network Guru Member

    Saw [Release] 083V has been posted.... any word on when the UPS support might make it into a release build?
     
  15. shibby20

    shibby20 Network Guru Member

    Not yet, but will do this at the moment. When i finish i will give you test build.
     
  16. occamsrazor

    occamsrazor Network Guru Member

    No worries... appreciate all your work
     
  17. shibby20

    shibby20 Network Guru Member

    FINALLY :)

    [​IMG]
     
  18. Catalin

    Catalin Addicted to LI Member

    Great! Only missing a compatibility list. :p
     
  19. Rob Holub

    Rob Holub Networkin' Nut Member

    Awesome, I'm excited to get this functionality added to my WNR3500L. I hate having to leave a computer on all the time to monitor my old Back-UPS ES 550 when my router has the potential to do so.
     
  20. shibby20

    shibby20 Network Guru Member

    all APC UPS with USB serial port should works.
     
  21. were55

    were55 Addicted to LI Member

    Shibby20, excellent implementation, when will be available to test it?

    thanks and keep you great work
     
  22. shibby20

    shibby20 Network Guru Member

    should be in this week.
     
    occamsrazor likes this.
  23. shibby20

    shibby20 Network Guru Member

    3 test builds BTgui with UPS - K24, K26 R1 and K26 R2

    http://update.groov.pl/ups/

    How to activate apcupsd?
    TODO:
    - Settings page to enable ups via GUI
    - Send information via email

    Feedback welcome.
     
  24. occamsrazor

    occamsrazor Network Guru Member

    A few questions:

    1. The "activate apcupsd" script - does it only need to be run once, or every startup?

    2. When you say "Settings page to enable ups via GUI" - do you mean just to enable it? Or is there no GUI page for the actual data received from the UPS - as in the screenshot at top of this thread?

    Thanks
     
  25. shibby20

    shibby20 Network Guru Member

    ad1) once.

    ad2) page with actual data received from the UPS is included in build. I want to make some "settings page" with options:
    - enable
    - logfile path
    - send email
    when i will do this... i dont know :)
     
  26. occamsrazor

    occamsrazor Network Guru Member

    Thanks Shibby. Would like to try it but I need a build with VPN, and I think BT-GUI doesn't have.
    Am currently running Tomato Firmware 1.28.0000 MIPSR2-083V K26 USB Big-VPN
     
  27. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Very nice.
     
  28. were55

    were55 Addicted to LI Member

    Hi Shibby,

    I just installed the firmware 1.28.0000 MIPSR2-084V K26 USB BTgui-UPS but my UPS status is not working, here are some info:

    Code:
    root@ZERA-DISC:/sbin# apcaccess status
    Error contacting apcupsd @ localhost:3551: Connection refused
    root@ZERA-DISC:/sbin# cat /proc/bus/usb/devices
    
    T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 2
    B:  Alloc=  0/800 us ( 0%), #Int=  0, #Iso=  0
    D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
    P:  Vendor=1d6b ProdID=0002 Rev= 2.06
    S:  Manufacturer=Linux 2.6.22.19 ehci_hcd
    S:  Product=EHCI Host Controller
    S:  SerialNumber=0000:00:04.1
    C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
    I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
    E:  Ad=81(I) Atr=03(Int.) MxPS=  4 Ivl=256ms
    
    My UPS is a tripp-lite, any clue?
    thanks for you help
     
  29. shibby20

    shibby20 Network Guru Member

    enable usb1.1 support and re-check.
     
  30. Hackerivs

    Hackerivs Networkin' Nut Member

    This newest UPS firmware is stable and works very well
    Here are some UPS stats
    i would only be happier if shibbys builds would support my option gi0225 3G usb modem :)
     
  31. were55

    were55 Addicted to LI Member

    shibby, thanks a lot, now works fine after usb1.1 enabled.
     
  32. pctek4456

    pctek4456 Networkin' Nut Member

    Latest UPS build k24 displayed this under the ups tab.
    Nvram cleared, still displays the same. Any Ideas?

    APC UPS Status
    /tmp/.wxXvXXDC: line 5: ./ext/cgi-bin/tomatoups.cgi: not found
    APC UPS Response
    /tmp/.wxhNgxbt: line 5: ./ext/cgi-bin/tomatodata.cgi: not found
     
  33. were55

    were55 Addicted to LI Member

    Shibby, seems like "bitTorrent" is not working, I tried to open the page but is not working...any clue? (it was working fine in the last releases)

    thankss !!
     
  34. shibby20

    shibby20 Network Guru Member

    @were55 because this is BTgui version, wuthout transmission binaries included.

    @pctek4456 - please show me "cat /proc/bus/usb/devices"
     
  35. Hackerivs

    Hackerivs Networkin' Nut Member

    i noticed a bug in this build.
    when HE tunnelbroker dyndns, it says:
    that is a well known bug from toastman builds but it was corrected.
     
  36. arakhm

    arakhm Networkin' Nut Member

  37. Daky

    Daky Network Guru Member

    Hello all,

    Do i need to have my UPS connected to my router or PC?

    I have Back UPS XS 1500.

    T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 2
    B: Alloc= 0/800 us ( 0%), #Int= 0, #Iso= 0
    D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
    P: Vendor=1d6b ProdID=0002 Rev= 2.06
    S: Manufacturer=Linux 2.6.22.19 ehci_hcd
    S: Product=EHCI Host Controller
    S: SerialNumber=0000:00:04.1
    C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
    I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
    E: Ad=81(I) Atr=03(Int.) MxPS= 4 Ivl=256ms


    Thank you!
     
  38. Daky

    Daky Network Guru Member

    [​IMG]

    Got it working.

    Thank you
     
  39. Daky

    Daky Network Guru Member

    Actually, i am back, i am sorry.

    I just noticed in logs this:
    STARTTIME: 1969-12-31 19:00:49 -0500

    Why date would be 1969?:)

    Thank you!
     
  40. kthaddock

    kthaddock Network Guru Member

    What time do you have under Basic=>Time ? "Router TimeSun, 21 Oct 2012 17:20:59 +0200"
    maby isn't set !?
     
  41. Daky

    Daky Network Guru Member

    [​IMG]

    This looks normal to me?:)
     
  42. koitsu

    koitsu Network Guru Member

    http://en.wikipedia.org/wiki/Unix_time
    http://www.epochconverter.com/ (see "What is epoch time?")

    Your timezone is -0500 UTC, which means you're 5 hours behind UTC. 1969-12-31 19:00 + 5 hours = 1970-01-01 00:00, which is epoch time.

    So that explains the timestamp/year/etc.. Your next question is going to be "but why is the date in the past when the router obviously has the right time?"

    These routers do not have CMOS batteries like your PC does. They have absolutely no concept of what time it is once they reboot. The kernel starts and has no idea what time it is, so it begins at epoch time 0, which is 1970-01-01 00:00 UTC. The router can keep TRACK of time (as in "1 second just passed, another second passed", etc.) but they do not have any concept from the point of being rebooted what time it is. The only way they can find out what the present clock time is, is by using NTP, which requires network access to the Internet. They DO keep track of timezone offset (that's stored in NVRAM variable tm_tz).

    So what's happening? It's pretty simple: the UPS monitoring daemon is starting ***before*** the router has a chance to do its NTP synchronisation. The amount of time this takes will vary depending on your Internet connection (for example PPPoE will take longer to set up), DNS resolver/server speed, and NTP server reliability.

    What needs to happen is that the UPS monitoring daemon needs to start **only after** NTP has finished synchronising (not the same thing as "ntp has started running!"). This is an init script-related problem and is sometimes difficult to fix. You know the open-source mantra: "patches are welcome".
     
  43. Daky

    Daky Network Guru Member

    Thank you very much for explanation.

    This cannot be any problem for me? I mean, its just the date, correct? (If that is the case, i really do not mind it).

    Once again, thanks a lot for the great support.
     
  44. koitsu

    koitsu Network Guru Member

    I don't know if it'll be a problem for you. That's for you to decide. You should be able to answer your own question ("I mean, it's just the date correct?") by actually reading what I wrote slowly/in full (do not skim). :)

    I don't see anywhere in arrmo's PDF file where its mentioning how upsapcd gets started on reboot. Because that's what needs to be adjusted. Basically upsapcd should get started only *after* ntpd/ntpdate has finished synchronising time. This also is a problem in the case the user has NTP synchronisation turned off or if NTP servers cannot be reached (the script/code must be able to handle this scenario correctly).
     
  45. Daky

    Daky Network Guru Member

    I did read your post fully, i swear :) :)

    Thanks again
     
  46. arrmo

    arrmo Addicted to LI Member

    Sorry, just saw this ... :-(.

    I'm not doing anything special to start apcupsd - Shibby's latest builds seem to have this all set up (and it starts automatically). I do have two lines in my WAN Up Script (below). These are to configure email notifications of UPS messages ..

    echo SYSADMIN=my@email.addr > /etc/apcemail.conf
    echo "APCUPSD_MAIL=\"smtp -h emailserver -f root\"" >> /etc/apcemail.conf

    Hope this helps!
     
  47. Monk E. Boy

    Monk E. Boy Network Guru Member

    Whoa, that's nifty. Usually with APC they make you pony up cash to get email notification (or, at least, a usable form of it - no, I don't want to know about the power going out AFTER the power has already come back on, thanks).
     
  48. luckydog2006

    luckydog2006 LI Guru Member

    Thanks for the following UPS monitor stuff. I have a few questions.

    The UPS monitor is working from the USB but I needed to enable USB 1.1 to get it to provide a APC UPS Status.
    However, the problem I am getting now is that in my logs, I'm getting a continuous timestamped log which shows as:
    Oct 27 15:15:19 XxX user.err kernel: drivers/hid/usbhid/hid-core.c: can't reset device, 0000:00:04.1-1.1/input0, status -71

    Is there any way to fix this?


    Also, when using the email config above for UPS;
    echo "APCUPSD_MAIL=\"smtp -h emailserver -f root\"" >> /etc/apcemail.conf

    Is the emailserver the actual 'emailserver' IP address? example "smtp.gmail.com"
     
  49. luckydog2006

    luckydog2006 LI Guru Member

    Ok, the USB 1.1 did not need to be enabled, I just needed to reboot the router.This cleared up the logs flooding above.
     
  50. GhaladReam

    GhaladReam Network Guru Member

    Any idea if/when e-mail notifications are coming for this module? I love the UPS status page, but it isn't much good without notifications for when your UPS goes on or off battery.
     
  51. luckydog2006

    luckydog2006 LI Guru Member

    Ok, correction. The log flooding still happens but it takes a bit longer before it shows up in the logs. My APC UPS needs USB 1.1 to be enabled before being able to show its APC UPS Status. But this causes the continuous log flooding.

    Any help would be appreciated.
    Oct 27 17:30:11 XxX user.err kernel: drivers/hid/usbhid/hid-core.c: can't reset device, 0000:00:04.1-1.1/input0, status -71
     
  52. arrmo

    arrmo Addicted to LI Member

    See above - email notification should work, if you use the settings (commands) noted.
     
  53. GhaladReam

    GhaladReam Network Guru Member

    I'm not able to get e-mail notifications using the script above. I replace my@email.addr with my e-mail address, and emailserver with smtp.gmail.com and it doesn't work. I've also tried the SMTP server my ISP provides with no success. I've placed the script in WAN UP, saved, and rebooted the router.

    I've also maunally typed the script into SSH with no success.
     
  54. GhaladReam

    GhaladReam Network Guru Member

    Ok, so I got e-mail notifications to work. Turns out my ISP SMTP server will not send mail from unresolvable addresses. In the case of the script above I had to change smtp -h emailserver -f root to smtp -h emailserver -f ups@apc.com so that my SMTP server could resolve apc.com.

    My next questions is this. When I do get the notifications, the subject line is blank, but the first line of the body of the e-mail is "Subject: Router power failure !!!" or "Subject: Router power restored". How could we get this in the actual subject line rather than the first line of the body? I know the -s command would set the subject to something static like "Power_Event" or something, but I'd rather it say what actually corresponds to the event such as a power failure or restore.

    My script that works:

    echo SYSADMIN=my@email.addr > /etc/apcemail.conf
    echo "APCUPSD_MAIL=\"smtp -h emailserver -s Power_Event -f ups@apc.com\"" >> /etc/apcemail.conf
     
  55. luckydog2006

    luckydog2006 LI Guru Member

    Any help for the repeating logs when USB 1.1 is enabled? My older APC UPS needs the USB 1.1 to work for the APC UPS status to update.
     
  56. luckydog2006

    luckydog2006 LI Guru Member

    The UPS Monitor Status works for my APC Back-UPS 800 (with USB 1.1 enabled) but it generates a log every second on my router.

    ==> Oct 27 17:30:11 XxX user.err kernel: drivers/hid/usbhid/hid-core.c: can't reset device, 0000:00:04.1-1.1/input0, status -71

    Does it happen to anyone else? There seems to be many threads in APCUPSD regarding similar issues above and related to different linux kernels. Do you guys just ignore these logs, or its not happening to you? Could be APC UPS specific.
     
  57. Monk E. Boy

    Monk E. Boy Network Guru Member

    I get the feeling not a whole lot of people are using it, but it could be a model-specific problem with APC. There's quite a wide variety of "quality" between their different UPS lines, for a while there they had a line designed & built in India that failed in just about every way imaginable (which is probably why it was quietly killed off). I've got an APC UPS at home for the router (and Tivo and cable modem and switch) but I don't think the (older) build I'm using there has UPS support in it.

    You wouldn't happen to have another APC UPS by any chance would you? I'm wondering if the USB cable itself has a problem, if so swapping it with one from another UPS might help. Obviously if the problem is in the router and/or the UPS then swapping cables won't affect the issue. APC likes to use those 10-position RJ-45 plugs on the UPS interface side, which you can actually make up yourself if you're particularly determined, but its normally cheaper/easier to find one on eBay or the like (I got lucky at my last workplace and found a deal on 10-pin plugs & crimper).
     
  58. luckydog2006

    luckydog2006 LI Guru Member

    Yeah, not so lucky. I'm using the cable that comes with the APC UPS. It works fine on the PC running WinXP but also works on Shibby f/w but the logs are annoying. If I don't get another APC UPS or cable to confirm, I'll just disable the USB 1.1 to kill the noise from the logs.Thx.
     
  59. JAC70

    JAC70 Networkin' Nut Member

    This is pretty cool. But if it can't send a shutdown command over the network in case of power outage, its usefulness is limited.
     
  60. Monk E. Boy

    Monk E. Boy Network Guru Member

    In the event of a power outage, shouldn't you just have each UPS-connected system issue its own shutdown based the UPS's remaining battery life?

    You're not going to have it all connected to the same UPS, unless you want to get 5 seconds of runtime.
     
  61. Monk E. Boy

    Monk E. Boy Network Guru Member

    Based on a cursory read of the documentation available here:
    http://www.apcupsd.org/

    It appears to require adjusting shell script(s) to change the actions taken by apcupsd.

    Basically run an ssh daemon on each system, then script an ssh connection and shutdown command to each one in turn, then configure apcupsd to call that script either as part of the shutdown, part of the initial alert, or another event.
     
  62. Legoguy

    Legoguy Network Guru Member

    Is there a way to configure this feature to show information not for a local UPS via USB, but for a UPS made visible by apcupsd on a separate system? All that would require a change is to call 'apcaccess status 192.168.1.xxx' to get the status from the remote server. I can already confirm that running this command works properly from the command line within the router.
     
    occamsrazor likes this.
  63. NokHook

    NokHook Reformed Router Member

    Any possible to make 8MB build with UPS monitor?
    Thank you.
     
  64. arrmo

    arrmo Addicted to LI Member

    Hi,

    Shibby's builds (Makefile) include the option for this - is it not what you're after?
     
  65. NokHook

    NokHook Reformed Router Member

    infact i'm a n00b and don't know much about compile custom build. (never know i can custom firmware by myself)

    but after your suggestion, i Google for howto do it. and after 10 hours of n00b work.

    finally, i can do it. :D and i so glad.

    thank you very much.
     
  66. rotohammer

    rotohammer Reformed Router Member

    Here's what I put in my WAN Up script to give me nice subject lines on emails from ups events without having to fix the bug in the router firmware (running Shibby 114 atm):

    Code:
    cat >/etc/apcemail.conf <<EOF
    SYSADMIN=me@email.com                                               
    HOSTNAME=`hostname`                                                         
                                                                                                                                                       
    if [ "\$0" == "/usr/local/apcupsd/onbattery" ]                               
    then                                                                         
      MSG="\${HOSTNAME}..Power.Failure!!!"                                     
    fi                                                                           
                                                                                 
    if [ "\$0" == "/usr/local/apcupsd/offbattery" ]                               
    then                                                                         
      MSG="\${HOSTNAME}..Power.Restored!!!"                                   
    fi
                                                                             
    if [ "\$0" == "/usr/local/apcupsd/commfailure" ]                               
    then                                                                         
      MSG="\${HOSTNAME}..Communications.with.UPS.lost!!!"                                     
    fi                                                                           
                                                                                 
    if [ "\$0" == "/usr/local/apcupsd/commok" ]                               
    then                                                                         
      MSG="\${HOSTNAME}..Communications.with.UPS.restored!!!"                                   
    fi
                                                                                 
    if [ "\$0" == "/usr/local/apcupsd/changeme" ]                               
    then                                                                         
      MSG="\${HOSTNAME}..UPS.battery.needs.changing.NOW!!!"                                   
    fi
                                                                           
    APCUPSD_MAIL="smtp -h email.server.com -s \$MSG -f office-ups@email.com "             
                                                                                                                                                   
    (  echo "\$MSG"                                                               
      echo                                                                     
      /sbin/apcaccess status                                                   
    ) | \$APCUPSD_MAIL \$SYSADMIN                                                 
                                                                                 
    exit 0
    EOF
    
    I'm using a CyberPower CP600 UPS and it works nicely With Shibby 112 and now 114.

    Note: I basically override the 4 existing scripts with this one.
     
    Last edited: Oct 25, 2013
  67. Bird333

    Bird333 Network Guru Member


    I can't get this to work for me. I replaced 'me@email.com' with my hotmail address. I changed 'hostname' to 'RT-N66R'. I changed 'email.server.com' to 'smtp.live.com'. And I changed 'office-ups@email.com' to my hotmail address. I am not receiving any emails. What did I do wrong?
     
  68. kthaddock

    kthaddock Network Guru Member

    Where do you have your: cat >/etc/apcemail.conf file ?
     
  69. Bird333

    Bird333 Network Guru Member

    In /etc/apcemail.conf
     
  70. shibby20

    shibby20 Network Guru Member

    smtp command is not available in tomato.

    You propably need optware and this package:
    smtp-cli - 2.8-2 - Perl script to send e-mail.
     
  71. kthaddock

    kthaddock Network Guru Member

    Last edited: Oct 26, 2013
  72. Bird333

    Bird333 Network Guru Member

    I am running Entware. I installed 'msmtp' and substituted it for 'smtp' but that didn't work either. How can I convert this line from the script above
    Code:
    APCUPSD_MAIL="smtp -h smtp.live.com -s \$MSG -f ups@email.com "
    to an equivalent line using 'sendmail'? I'm not an expert but I think it might work. Also I would like to use 'sendmail' since it is built into the firmware.
     
  73. Bird333

    Bird333 Network Guru Member

  74. koitsu

    koitsu Network Guru Member

    Busybox comes with a binary called sendmail which is absolutely nothing like actual Sendmail (the software/suite). Just want to get that out there so people understand up front. I don't know what the syntax/usage arguments are exactly for smtp, but I can take a guess:

    -h = SMTP server to connect to
    -s = Probably Subject of message, but $MSG is vague as hell so it could be the entire message (ugh)
    -f = From address

    You should be able to therefore use this instead:

    sendmail -f from@somewhere -S smtp.live.com recipient@domain.com

    Run sendmail -h by itself on Busybox to get usage syntax.

    The Subject line needs to be part of the actual content sent to the program via stdin, e.g.:

    Code:
    $ sendmail -f ilikegiantrocks@gmail.com -S smtp.live.com alerts@yourfathersmeltofelderberries.com
    From: Snake Rider <ilikegiantrocks@gmail.com>
    Subject: Your UPS is on fire!
    Priority: high
    
    Hey man! Your UPS is on fire.  You'd better do something about that...
    {press Ctrl-D here (sends EOF)}
    $
    
    The important part to note in the above: SMTP headers come first, then a blank line, then the content/body of the Email. The Subject line is part of the headers, which you yourself need to put in first. Look at the "echo" part of the crazy-and-ugly-as-hell script near the bottom and you should be able to figure it out.

    Keep something in mind: this initiates a direct connection to TCP port 25 on (in the example) smtp.live.com. Some ISPs (many) filter outbound connections to destination TCP port 25 and instead require you siphon mail through them. You may also have to use SMTP authentication (see sendmail usage syntax), and some require SMTP authentication + SSL (which requires Entware openssl to be installed, because you need to use openssl s_client to do the SSL encapsulation, and use of the -H argument to sendmail). Some ISPs use an alternate port (such as TCP port 465 or 587) with different capabilities (some are SSL-only, some are TLS, some are plain/classic SMTP).

    Many people also do not understand the -f flag and how it differs from the From: line included in the headers. To understand the difference, you have to look at how an actual SMTP conversation works across the socket. The client sends the following commands and prays it gets back a 2xx status response from the server for each line (except everything past DATA; to end the DATA phase you just send a period by itself):

    Code:
    HELO my.fully.qualified.host.name
    MAIL FROM:<this@is.the.dash.f.flag.value>
    RCPT TO:<alerts@yourfathersmeltofelderberries.com>
    DATA
    From: Snake Rider <ilikegiantrocks@gmail.com>
    Subject: Your UPS is on fire!
    Priority: high
    
    Hey man! Your UPS is on fire.  You'd better do something about that...
    .
    QUIT
    
    Hope this helps. And welcome to SMTP today, where everything is a PITA and liable to be marked as spam.
     
  75. motocrossmann

    motocrossmann Network Guru Member

    I'm just trying to get the UPS reporting to work and my eyes are starting to go crossed. Just uploaded firmware "1.28.0000 MIPSR2-115 K26 USB Big-VPN", but I don't see any mention of a UPS even with USB 1.1 and 2.0 enabled. 'cat /proc/bus/usb/devices' shows this:

    T: Bus=01 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 6 Spd=1.5 MxCh= 0
    D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
    P: Vendor=051d ProdID=0002 Rev= 1.06
    S: Manufacturer=APC
    S: Product=Back-UPS ES 650 FW:825.B1.D USB FW:B1
    S: SerialNumber=3B0608X12166
    C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
    I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=00 Prot=00 Driver=(none)
    E: Ad=81(I) Atr=03(Int.) MxPS= 6 Ivl=10ms

    What am i missing here???
     
  76. arrmo

    arrmo Addicted to LI Member

    Not sure where the build came from, but ... did you load the Shibby build with UPS support?
     
  77. motocrossmann

    motocrossmann Network Guru Member

    Hi arrmo- You actually helped me out on a separate thread. I did get things going. It was either a file permission error on my *.ko files, or improper use of the insmod command. Thanks!
     
  78. arrmo

    arrmo Addicted to LI Member

    Glad it helped - yell if you have any more questions!
     
  79. Connor McCaffrey

    Connor McCaffrey Serious Server Member

    i have a back UPS ES 550, doesnt have any usb ports but it has a standard rj-45 ethernet jack along with 2 phone jacks. i plugged in the ethernet and connected to the router but it didnt seem to work and still just said model not available. is there any chance i could get this working or does it only work with USB to ethernet
     
  80. arrmo

    arrmo Addicted to LI Member

    Hi,

    You mean you connected it to one of the LAN ports?
     
  81. Connor McCaffrey

    Connor McCaffrey Serious Server Member

    yes from a lan port on the UPS to a lan port on the router
     
  82. shibby20

    shibby20 Network Guru Member

  83. hgeorges

    hgeorges Network Guru Member

    Hello;
    I just connected my APC ups to my router, and I would like to change the conf file to a master-slave configuration (net mode), to control the shutdown of several computers from it.

    How do I make the conf file (apcupsd.conf) rw?
    I tried remounting / as rw, but it didn't work.

    Thank you
     
    Last edited: Apr 16, 2014
  84. benoga

    benoga Reformed Router Member

    Can you disable the "apcupsd" deamon with
    Code:
    nvram set ups_enable=0
    nvram commit
    ??


    The service "apcupsd" is always running. Every reboot i do stop it with "service ups stop".

    I will disable the original apcupsd, while i run 2 apcupsd deamon's for 2 USV's. (2 Port's)

    Code:
    /opt/sbin/apcupsd --config-file /opt/etc/apcupsd/apcupsd1.conf
    /opt/sbin/apcupsd --config-file /opt/etc/apcupsd/apcupsd2.conf
     
  85. synthkeywizard

    synthkeywizard New Member Member

    What about Powercom UPS? Do you plan to implement support of these devices?
     
  86. arrmo

    arrmo Addicted to LI Member

    Hi,

    If apcupsd supports Powercom - then it will be supported. No plans to customize apcupsd ... sorry!
     
  87. error1

    error1 New Member Member

    Any chance of getting an updated apcupsd into the firmware? 3.14.10 is getting old and the latest 3.14.13 adds MODBUS over USB support which is needed to get all the detailed stats like load and voltages from the newest APC models.

    One very cool thing about apcupsd is that you can talk to it from the newest version of NUT, i have a NUT server running on another computer that collects statistics from apcupsd, and then use OpenHAB to connect to NUT and display this information as part of my home automation setup :)
     
    occamsrazor and Monk E. Boy like this.
  88. GhaladReam

    GhaladReam Network Guru Member

    I've also been hoping for an update... Add USB alerts via GUI. I currently have this working via a WAN UP script, but I would love to see this in the GUI. Possibly also SMTP Authentication for e-mail alerts, as most SMTP severs nowadays require authentication.
     
  89. arrmo

    arrmo Addicted to LI Member

    Hi,

    If you go to the top of this file - there is a pdf that outlines the steps needed to integrate apcupsd (new version) in to the build. Just follow those steps, build the new version?
     
  90. occamsrazor

    occamsrazor Network Guru Member

    I'm really confused here. I have an APC SUA1500I UPS connected via USB to my Tomato router. The router picks up all the UPS info fine. But I can't see what I can then actually do with that information.
    What I'd like to do is have tomato act as a network master, and send that info to a couple of Macs (which are running off the same UPS) so they can shutdown after X minutes of power loss etc.
    I've been reading a lot about NUT, but am confused how this differs from or is interfaced with APCUPSD. Should I be trying to install a NUT master on Tomato and then NUT clients on Mac? Or APCUPSD clients on Mac? Or what?
    Thanks in advance...
     
  91. occamsrazor

    occamsrazor Network Guru Member

  92. occamsrazor

    occamsrazor Network Guru Member

    Oh..... looks like I spoke to soon. Have just noticed the exact same flooding in my logs:

    Code:
    Oct 20 16:24:48 Tomato user.err kernel: drivers/hid/usbhid/hid-core.c: can't reset device, 0000:00:04.1-1.2/input0, status -71
    
    Also it seems that after a while the apcupsd in Tomato is failing to communicate status changes to the apcupsd client daemon. I'm guessing perhaps the two are related.

    I can disable USB 1.1 and still communicate with my UPS, but the problem re-occurs. Doing some googling it seems the device is somewhow disconnected or unresponsive. One user with same error (but totally different linux system) says the problem was fixed by "disabling autosuspend" but this is starting to get above my skills.....

    http://www.linuxquestions.org/questions/slackware-14/kernel-usb-error-71-and-system-freeze-903996/

    Did you ever find a solution?
     
    Last edited: Oct 20, 2015
  93. occamsrazor

    occamsrazor Network Guru Member

    Sorry to bump, but anyone have an idea on how we might go trying to fix this issue?
     
  94. occamsrazor

    occamsrazor Network Guru Member

    New Year bump to try and fix this problem....:)
     
  95. atx32

    atx32 Network Newbie Member

    I agree we need to have the Shibby builds updated to use the latest apcupsd version. I ran a power-fail test (unplugged the UPS) yesterday and even after power was restored the clients were still being told that the master was shutting down. This would force the clients to power off immediately after boot, and it took me a while to figure out what was happening. I haven't tried to debug this but it would be nice to be on the most current version so we aren't working through items that are already fixed. How about it @shibby20, could you do this for v133?
     
  96. premudriy

    premudriy LI Guru Member

    People were asking for a script that uses sendmail. I'm using the following script (in 'WAN Up') for my UPS. It is based on the script written by rotohammer in the post #66 above. I hope it might help somebody:

    Code:
    cat >/etc/apcemail.conf <<EOF
    UPS_NAME="Office UPS 1"
    UPS_EMAIL="ups_sender_mail@upssenderdomain.com"
    UPS_EMAIL_PASS="upsSenderPassword"
    SMTP_SERVER_AND_PORT="smtp.upssenderdomain.com:25"
    RECEPIENT_EMAIL="mymail@mymaildomain.com"
    
    if [ "\$0" == "/usr/local/apcupsd/onbattery" ]
    then
      MSG="ALERT!!! POWER OUTAGE!"
    fi
    if [ "\$0" == "/usr/local/apcupsd/offbattery" ]
    then
      MSG="Power restored back"
    fi
    if [ "\$0" == "/usr/local/apcupsd/commfailure" ]
    then
      MSG="Communication with UPS lost"
    fi
    if [ "\$0" == "/usr/local/apcupsd/commok" ]
    then
      MSG="Communication with UPS restored"
    fi
    if [ "\$0" == "/usr/local/apcupsd/changeme" ]
    then
      MSG="Internal battery needs changing ASAP"
    fi
    MAIL_COMMAND="sendmail \$RECEPIENT_EMAIL -f \$UPS_EMAIL -S \$SMTP_SERVER_AND_PORT -au\\"\$UPS_EMAIL\\" -ap\"\$UPS_EMAIL_PASS\""
    (
    echo "FROM: \$UPS_NAME <\$UPS_EMAIL>"
    echo "To: \$RECEPIENT_EMAIL"
    echo "Subject: \$MSG (\$UPS_NAME)"
    echo
    echo "\$MSG"
    echo
    echo "=================Full UPS Status================="
    /sbin/apcaccess status
    echo "================================================="
    ) | eval \$MAIL_COMMAND
    exit 0
    EOF
    
     
  97. Nathan Ellsworth

    Nathan Ellsworth Network Newbie Member

    Hi. Based on the code from premudriy, I have created an enhanced version of the UPS notification script. Main enhancements are:

    1. It uses smtp.gmail.com to send emails (assumes sendmail command has s_client helper stuff)
    2. It can also send a shorter email, appropriate for a SMS message, using an email-to-sms gateway

    A few notes though. It uses bash which runs from /opt, so it assumes Entware is installed. It may work with the builtin /bin/sh, but I haven't tested that. Also, I know the gmail password is in plain-text. Perhaps someone can suggest a good way to obscure that. But I'm not worried too much since I created a dedicated Gmail account just for this alert-sending purpose. Lastly, I actually am using the Entware apcupsd, which is a newer version than Shibby has in Tomato. So I made symlinks from the /opt/etc/apcupsd/onbattery, offbattery, changeme, etc. scripts to point to this new script, which I called apcupsd_notify.sh.

    If anyone is interested, I can share some notes on how I got Entware apcupsd working. It required using insmod to load the usbhid drivers.

    Enjoy

    Code:
    #!/opt/bin/bash
    #set -x
    
    UPS_NAME="Your Router Name"
    UPS_EMAIL="<email from address>@gmail.com"
    RECEPIENT_EMAIL="<email alert destination>@gmail.com"
    SMS_EMAIL="<SMS alert destination>@txt.att.net"
    
    AUTH="<gmail account for SMTP authentication"
    PASS="<gmail password>"
    SERVER=smtp.gmail.com
    PORT=587
    
    
    callee=${0##*/}
    case ${callee} in
       "onbattery")
           MSG="ALERT!!! POWER OUTAGE!"
           SMS=1
           ;;
       "offbattery")
           MSG="Power restored back"
           SMS=1
           ;;
       "commfailure")
           MSG="Communication with UPS lost"
           ;;
       "commok")
           MSG="Communication with UPS restored"
           ;;
       "changeme")
           MSG="Internal battery needs changing ASAP"
           ;;
    esac
    
    HELPER="exec openssl s_client -quiet -connect $SERVER:$PORT -tls1 -starttls smtp"
    MAIL_CMD='/usr/sbin/sendmail -f$UPS_EMAIL -H"$HELPER" -au$AUTH -ap$PASS'
    
    STATUS=$(/opt/sbin/apcaccess status)
    SHORT_STATUS=$(echo "$STATUS" | grep -e TIMELEFT -e LOADPCT -e BCHARGE -e LINEV)
    
    (
    echo "FROM: $UPS_NAME <$UPS_EMAIL>"
    echo "To: $RECEPIENT_EMAIL"
    echo "Subject: $MSG ($UPS_NAME)"
    echo
    echo "$MSG"
    echo
    echo "========Full UPS Status========"
    echo "$STATUS"
    echo "==============================="
    ) | eval $MAIL_CMD $RECEPIENT_EMAIL
    
    if [ "$SMS" == 1 ]
    then
    (
    echo "FROM: $UPS_NAME <$UPS_EMAIL>"
    echo "To: $RECEPIENT_EMAIL"
    echo "$MSG"
    echo "$SHORT_STATUS"
    ) | eval $MAIL_CMD $SMS_EMAIL
    
    fi
    exit 0
    Nathan
     
    Monk E. Boy likes this.

Share This Page