Communicating with the UPiS UPS from RasPlex

Standard

As part of my recent media centre build, I wanted to have a Raspberry Pi running RasPlex power down gracefully when power was removed. The UPiS Advanced UPS to the rescue! Despite the terrible name, this UPiS comes complete with a battery and UART so that the power status can be monitored from the Raspberry Pi.

The script is straightforward enough — it queries the UPiS every few seconds. If it detects that power is removed, it shuts itself down and triggers the “file sfe shutdown” on the UPiS. After 30 seconds or so, with everything safely shut down, the UPiS cuts power.

The script is in Python and requires PySerial. However, RasPlex is very bare-bones, python libraries can’t be compiled and nothing can be installed (there is no package manager). It turns out, however, that this doesn’t matter — PySerial can be installed to a local folder and run from source.

The (small) code and instructions for running are on my GitHub repository. PySerial is included.

 

About Me

Standard

Based in Shanghai, China, I’m an experienced knowledge and digital marketing leader with a particular interest in social media and web application design.

I’m passionate about sharing knowledge, and am a strong advocate for open source and software freedom.

Some of my recent personal work includes:

  • WP-United: A project that integrates leading social software to make better social sites. WP-United empowers hundreds of communities all over the web, from small university clubs to large newspapers and corporate intranets.
  • rmbtb.com: One of the first Bitcoin exchanges in China, with top notch security and features, including an advanced secure API. One of the few Bitcoin sites not to get hacked and lose a bunch of money! RMBTB is now closed due to Chinese legislation banning Bitcoin.

Reboot TP-Link router remotely or automatically

Standard

using cURL or wget, it’s easy to reboot a TP-Link router from a terminal or command line. Put it in a script and schedule it to run automatically if your router overheats or is flaky:

in OSX (using cURL):

curl --user username:password http://192.168.1.1/userRpm/SysRebootRpm.htm?Reboot=Reboot > /dev/null

If you have wget by default instead of cURL (i.e. most *nix):

wget -qO- --user=username --password=password http://192.168.1.1/userRpm/SysRebootRpm.htm?Reboot=Reboot > /dev/null

Replace username and password with the admin username and password of your router. Replace 192.168.1.1 with the IP address of your router.

If you have Windows, with neither of the above, and don’t want to download wget, try using bitsadmin to create a download job.

Selecting x items at random from a column in Excel

Standard

I wanted to select 300 users at random from a row of 10,000 users in Excel. Really easy, but a bit of a lateral solution: Rather than trying to randomly select each item, just order them randomly instead:

  1. In another column adjacent to the column of user names, create a random number for each row (the formula I used was =RANDBETWEEN(1, 90000)). This won’t guarantee unique values for each item, but it doesn’t matter.
  2. Copy the the column with the formulas and Paste As… Values to another adjacent column. This fixes the nubmers and stops them from updating.
  3. Sort by this third column and take x users from the top. I chose the first 300.
  4. Done