What's new

Configuring apcupsd

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

PavelBab, thanks for the modules. We got a winner!

Code:
T:  Bus=02 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=051d ProdID=0002 Rev= 0.90
S:  Manufacturer=American Power Conversion
S:  Product=Back-UPS BX1500G FW:866.L1 .D USB FW:L1
S:  SerialNumber=3B0922X19672
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  2mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=100ms

@RMerlin Given how popular apc units are, why not embed, or make the modules available separately for your builds?

If someone can give me a list of the necessary Kernel option changes, I can take a look.
 
RMerlin, take a look at post #19 in this thread. I think those are the kernel options in question?
 
This ups project is almost done. Aside from the apcupsd-cgi not working (to be able to see ups stats via browser), I discovered one other issue.

Logging does not respect set timezone, but rather logs everything @ UTC +0000 time.

Actual time of this log is UTC -0600 (~1622 hours)
Code:
admin@Router2:/tmp/mnt/sda1/entware/var/log# cat apcupsd.events
2017-11-22 22:23:07 +0000  apcupsd 3.14.14 (31 May 2016) unknown startup succeeded
2017-11-22 22:23:14 +0000  Power failure.
2017-11-22 22:23:17 +0000  Power is back. UPS running on mains.

These same entries are also mirrored in /tmp/syslog.log with the same timestamp issue. Router generated log entries are stamped correctly. My guess is there's some variable not set that apcupsd looks for to set the timestamp offset.

Ideas?
 
I think that will do it. Are variables in /opt/etc/profile global and available even when not in ssh?
 
@RMerlin Are these hid modules now included with the new 384 builds?

If not, can you point me to the layman's guide to how to compile these myself?
 
@RMerlin Are these hid modules now included with the new 384 builds?

If not, can you point me to the layman's guide to how to compile these myself?

I don't know. Which router model? There are three different kernels in there, based on your router model.
 
While you're at it, it would be nice if the drivers were also there for the RT-AC3100 :)

Thanks in advance!
 
^^I'm sorry, rt-ac68u.

Module is enabled in the kernel config, but for some reason it's not being included in the firmware image.
 
Something you can fix? Baked in the firmware would be ideal. No need to load extra modules.

Thanks!
 
Something you can fix? Baked in the firmware would be ideal. No need to load extra modules.

Thanks!

I should be able to, just a matter of having the build script not filter out these modules.
 
@RMerlin

Thanks for including the modules. I finally got around to upgrading the rt-ac68u's to the 384.5 build after discovering the flash drive (older corsair voyager 16gb) became corrupted.

----------------

Building on the script from post #17, the module lines should look like this.

Code:
insmod /lib/modules/2.6.36.4brcmarm/kernel/drivers/input/input-core.ko
insmod /lib/modules/2.6.36.4brcmarm/kernel/drivers/hid/hid.ko
insmod /lib/modules/2.6.36.4brcmarm/kernel/drivers/hid/usbhid.ko

Recommendation for 384.5 was to do a reset of the router. Make sure to backup your jffs partition first. Also, installing entware overwrites contents of the /scripts folder. My config isn't too complicated, mainly using the RT as an AP & switch, but do have a number of vlans configured including one for an isolated wifi SSID.
 
@RMerlin

Thanks for including the modules. I finally got around to upgrading the rt-ac68u's to the 384.5 build after discovering the flash drive (older corsair voyager 16gb) became corrupted.

----------------

Building on the script from post #17, the module lines should look like this.

Code:
insmod /lib/modules/2.6.36.4brcmarm/kernel/drivers/input/input-core.ko
insmod /lib/modules/2.6.36.4brcmarm/kernel/drivers/hid/hid.ko
insmod /lib/modules/2.6.36.4brcmarm/kernel/drivers/hid/usbhid.ko

Recommendation for 384.5 was to do a reset of the router. Make sure to backup your jffs partition first. Also, installing entware overwrites contents of the /scripts folder. My config isn't too complicated, mainly using the RT as an AP & switch, but do have a number of vlans configured including one for an isolated wifi SSID.

For those that are interested, I was able to configure APCUPSD to use my gmail account to send emails and text messages* when my UPS goes onbattery, offbattery, requires a new battery (changeme) and is low on battery charge (failing). My mods depend on the google.pem file for SSL as Experian the one referenced in the wiki does not work.

To download the google.pem file, you can do the following from ssh session in the router;

Code:
wget https://pki.google.com/roots.pem
mv roots.pem /jffs/configs/google-roots.pem

Below are the files that I modified to support this. They're just loaded into /tmp/opt/etc/apcupsd directory on my RT-AC68U router with 384.5.

apcupsd_mail.conf (FROM, AUTH, PASS, TO, HOSTNAME, AND CELL fields needs to be modified with your information)
Code:
#!/bin/sh

MAILPROG="/usr/sbin/sendmail"
MAILHOST="smtp.gmail.com:587"
FROM="YOUR GMAIL EMAIL ADDRESS"
AUTH="YOUR GMAIL EMAIL ADDRESS"
PASS="YOUR GMAIL PASSWORD"
TO="RECIPIENT EMAIL ADDRESS "
HOSTNAME="YOUR ROUTER HOSTNAME"
CELL="YOUR CELLULAR SMS EMAIL ADDRESS"

*Note that for text messaging, I used the email to text feature that my cellular provider (T-Mobile) supports. Apparently, most US cellular providers support this feature and it works quite well. You can use this link to find out if your provider supports this feature and what the proper email address to use for this.

onbattery
Code:
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
. /opt/etc/apcupsd/apcupsd_mail.conf

MSG="$HOSTNAME has lost power!"
#
(
   echo "Subject:$MSG"
   echo "We must have lost power at home.  Below are stats as of time of
outage: "
   echo " "
   /opt/sbin/apcaccess status
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $TO

#
(
   echo "Subject:$MSG"
   echo "We must have lost power at home"
   echo " "
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $CELL

exit 0

offbattery
Code:
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
. /opt/etc/apcupsd/apcupsd_mail.conf

MSG="$HOSTNAME Power has been restored!"
#
(
   echo "Subject:$MSG"
   echo "Power has been restored at home.  Below is the status of the
UPS as of power restoration:"
   echo " "
   /opt/sbin/apcaccess status
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $TO
#
(
   echo "Subject:$MSG"
   echo "Power has been restored at home"
   echo " "
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $CELL

exit 0

changeme
Code:
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
. /opt/etc/apcupsd/apcupsd_mail.conf

MSG="$HOSTNAME UPS battery needs changing NOW."
#
(
   echo "Subject:$MSG"
   echo "You need to change the batteries asap.  Below are stats of the
UPS now: "
   echo " "
   /opt/sbin/apcaccess status
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $TO
#
(
   echo "Subject:$MSG"
   echo "You need to change the batteries asap"
   echo " "
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $CELL

exit 0

failing
Code:
#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
#
. /opt/etc/apcupsd/apcupsd_mail.conf

MSG="$HOSTNAME UPS battery is running low."
#
(
   echo "Subject:$MSG"
   echo "Battery has very low charge left and will exhaust soon!"
   echo " "
   /opt/sbin/apcaccess status
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $TO
#
(
   echo "Subject:$MSG"
   echo "Battery has very low charge left and will exhaust soon!"
   echo " "
) | $MAILPROG -H"exec openssl s_client -quiet -CAfile /jffs/configs/google-roots.pem -connect $MAILHOST -tls1 -starttls smtp" -f"$FROM" -au"$AUTH" -ap"$PASS"  $CELL
exit 0

Hopefully this is helpful to others.

3/5/2020 Update: Just sharing that these steps are still working for me on the RT-AC1900P unit with Merlin's 384.15 firmware.

4/9/2021 Update: Still working great for me with Merlin's 386.2 firmware. Did have to install libjpeg-turbo so that the upsstats.cgi would display the graphics correctly.
Code:
opkg update && opkg install libjpeg-turbo
 
Last edited:
In hopes that this helps others, I wasn't able to get apcupsd to see my UPS on 386.2_4 until I also loaded hid-generic module.

I believe that once this module was loaded, the /dev/usb/hiddev0 device was created, which seems to be what the daemon needs.
 
In hopes that this helps others, I wasn't able to get apcupsd to see my UPS on 386.2_4 until I also loaded hid-generic module.

I believe that once this module was loaded, the /dev/usb/hiddev0 device was created, which seems to be what the daemon needs.
I just purchased a RT-AX82U unit and installed the gnuton fork on this unit. This tip was what I needed to get my apcupsd setup up and working again. Thank you much for sharing.👍
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top