Push RouterOS metrics to InfluxDB

Here is a really simple and easy way to push metrics (or any value) from RouterOS right into InfluxDB:

I needed this to grab some simple numbers to put on a Grafana dashboard so I set the script above to run every 5 minutes. So far this has worked really well.

Stream to youtube from Unifi NVR

Here is a short script which uses ffmpeg to stream video from a Unifi NVR straight to Youtube. I experimented with a few different ffmpeg options and found this one produces the best stream with the best audio.

The first stream URL is generated by creating a stream for the camera in Unifi video. The second URL is the stream URL from youtube.

Fix for nonfunctioning power window in 2007 Mazda3

I’ve been having trouble with the driver’s side power window on my 2007 Mazda3 for a while. The window would go down, but wouldn’t go back up. Researching the problem online, this is a super common issue, but the suggested fixes are to replace whole assemblies, slam the door hard (to release a jammed mechanism), or to ‘recalibrate’ the motor controller.

I was able to fix it for zero cost so I am documenting the solution online here in the hope that it will help others: Completely disassemble the switch assembly, and then apply some pencil (graphite) to the contact pads of the tactile membrane switch. It’s an old trick, and this perfectly fixed my issue, was very quick and simple, and cost nothing, so I am documenting it here. More detail/pics below:

Continue reading

Sonoff, meet powerstrip

I recently became super fascinated with ESP8266 hardware, and it wasn’t long before I also found out about and ordered a couple of ESP8266-based Sonoff AC switches to play with (immediately flashing them with some generic MQTT firmware). They work wonderfully and are just too cheap to resist.

It also wasn’t very long until I began wondering whether I could jam the bare PCB from the Sonoff right into a power strip. I took apart the closest one and was pleased to find that (with only a little bit of creative modification of the plastic ribs and bosses) the bare Sonoff PCB fit inside perfectly. Too perfectly:

SDIM1329

Obviously, this is extremely unsafe, so don’t ever do this – or will burn your house down, kill your pets and loved ones and so on. More pictures of how not to do this follow..

Continue reading

Netinstall for RouterOS in Virtualbox (on Mac OS)

I recently ‘bricked’ my Mikrotik HAP AC Lite router – the router didn’t have enough room on its flash memory to install an update, but – in an unexpected turn of events – tried to apply the firmware update anyway, and became un-bootable.

Fortunately, Mikrotik supply a bit of software (‘Netinstall’) which is able to re-flash the devices using BOOTP, but this software won’t run in Wine (it requires root to bind to the low BOOTP port, yada yada).

For Mac users, this means it’s really only possible to run it in a VM (in my case, in Windows 8.1, in Virtualbox on Mac OS 10.11 El Cap). Since this added a few additional layers of very un-wanted hassle at a quite stressful time, I thought I would leave some hints here – tips and screenshots below. Happy flashing! Continue reading

Quick RouterOS script for hurricane electric 6to4 tunnel dynamic updating

If your ISP doesn’t offer IPv6 you may have set up an IPv6 6to4 tunnel using Hurricane Electric’s free ‘tunnelbroker.net‘ service.

To operate the tunnel, tunnelbroker.net requires that you configure an IPv4 endpoint/client IP in their tunnel configuration. Additionally, the Mikrotik RouterOS ‘6to4’ tunnel interface requires this same IPv4 address is (redundantly) entered as the 6to4 interface’s 'local-address' property value. If you are given a dynamic public IP address by your ISP, this is a bit messy!

Here is a quick script (I suggest running it periodically) which will:

    • Use Mikrotik’s Cloud IP service (which obviously must be enabled) to resolve your WAN IP,
    • Check that IP against the local-address value in your 6to4 interface (which is assumed to be the only interface, named ‘sit1’) and
    • If the IPs do not match, will update tunnelbroker.net with your new WAN IP (using their dyn-compatible GET request method) and
    • Update the ‘local-address’ of your 6to4 interface

You can obtain the necessary values (<USERNAME>, <PASSWORD> (which is hashed) and <TUNNELID>) by logging into the tunnelbroker.net website, opening your tunnel details, then clicking the ‘advanced’ tab.

Note that it might be unnecessary to force the cloud IP service to update – I believe it does this every minute anyway.

Something worth noting too is that the endpoint/client IP for the tunnelbroker.net tunnel (ie. your WAN IP) must respond to ICMP pings from tunnelbroker before it can be set up on the tunnelbroker.net website. If you’re blocking ICMP, configuring the tunnel endpoint on the tunnelbroker.net website will just mysteriously fail.

Send Slack messages from Mikrotik RouterOS

This is a quick RouterOS script hack which I just wanted to get up online; it’s not anywhere near perfect but it might be useful to others. My objective here was to post a message to any Slack channel from Mikrotik RouterOS:

RouterOS to Slack

Slack has a super-simple to use ‘incoming webhook‘ integration but unfortunately, this requires that your app make a HTTP POST request – unfortunately not actually possible with RouterOS. Luckily, you can alternatively send messages using a HTTP GET request to Slack’s chat.postMessage API method. All you’ll need to do this is an API test token, which you can generate here.

Once you have your test token (beginning xoxp-..) you can form a HTTP GET request, including your message and any additional args (username, icon, channel..) as per the script below. Submitting a message is as easy as making a /tool fetch url command in your script.

To actually implement this usefully, the script below will parse the log file (ref.) for topics of interest, URL-encode any unsafe ASCII characters (non-exhaustive…) then post a message to your nominated Slack channel.

Todo: Read multiple log lines and post them as a single message using newlines, make logging topics and keywords better.

Quota-based traffic usage alerts in LibreNMS

Out of the box, LibreNMS does not readily expose traffic transfer measurements – it is geared towards network operators who buy (and sell) transit bandwidth wholesale, and not really for the home-gamer who just wants to stay under their ISP’s data cap.

As per the documentation, LibreNMS’ billing module can be enabled in config.php, and this will allow us to track and historise data usage for an interface in a nice billing page. Once billing is enabled we can add a new bill: under Ports > Bills, hit ‘add new’ and select a device and interface to measure against (you can add more than one interface per bill). Select ‘quota’ if, like me, you are interested in total transfer (not 95th percentile traffic).

But what if we also want to generate alerts when a device/interface exceeds a given threshold? Well, then we also need to add the following macro in config.php (thanks to laf on ##librenms):

More detail – including screenshots – after the break:

Continue reading

Reverse-engineering the IKEA “Ledberg” LED

This is an “Ledberg” LED downlight from IKEA:

ledberg

I really like it – the LED is a nice, warm white, it has a very high output (up to 3W) and the diffuser lens makes a nice soft spot. It’s low-profile, easy to mount, doesn’t require heatsinking, and is a complete solution including a 24VDC power supply, inline switch and driver circuit. And it’s only about $8. You can buy a three-pack (single power supply) for about $16.

I bought it with a little project in mind which will be the topic of a future post.

I was very curious about how the LED is being driven so I cracked this thing open while I was still on the bus home and spent the rest of the bus ride itching to get home to get it apart properly and satisfy my curiosity. Inside the puck enclosure is a tiny PCB with just 5 discrete surface mount components driving the single LED chip:

Continue reading

Read the RFCs

I recently moved a bunch of websites over to a VPS (likely the one you are reading this from). It runs Ubuntu with a LEMP stack.

I ran into some problems when I went to reconfigure my DNS Zones to reflect the change. The zones (combined) I created looked more-or-less like this:

There’s a lot of records pointing to vps.mydomain.com, and only one ‘A’ record for vps.mydomain.com that points to my VPS’s actual IPv4 address.
This way I just have to update the one record if my VPS’ IP address changes. Makes sense, doesn’t it?

I thought so, but could not make this configuration work. After some research, I learned that according to RFC 1912 s.2.4, a ‘TLD cannot be a CNAME’. When I adjusted the zone as below, it all worked again.

What’s frustrating is that both strategies actually seem to work when the NS records point to a cPanel server hosting the zone file, but do not when the zone is served directly by my registrar’s “free DNS hosting”. This led to an argument with my registrar/host where I declared that their DNS server was broken (when it was actually just following RFC strictly), and they maintained that there was “no way to have an A and an MX record in the same zone, which wasn’t right either. In the end, we were both wrong!

Monitoring and reporting 3G radio signal-strength (RSSI, dBm) on Mikrotik Routerboards

Monitoring a large number of Mikrotik Routerboards is easy using software and tools like LibreNMS and Oxidized, but it is unfortunately not possible to retrieve values for 3G/4G/etc signal-strength RSSI (in dBm) via SNMP when using interfaces like the Sierra MC8705 Mini-PCIe card.

However, using some RouterOS scripts, we can read and push the value for signal strength to a remote listening server using HTTP GET requests. In my case, the server is running Mango Automation software, which also handles the historising, trending and event-detection handling.

3g-signal

Continue reading

Raspberry Pi internet streaming radio station

My partner has been overseas for a few months and was desperately missing a local radio station. It doesn’t have an online stream that she can listen to and so she asked me whether I could record the station for ten hours – this just sounded like a hassle, so I set up an internet streaming station to permanently re-stream the local broadcast over the internet using my Raspberry Pi, a cheap USB sound card, a cheap DAB digial radio, and darkice/icecast to run the streaming server.

The output of lsusb showed the cheap USB sound card to be a “C-Media Electronics, Inc. CM108 Audio Controller”. I found that I could access the device using ALSA and the arecord utility (as long as I didn’t specify 2 channels):

Next, I tried to set up icecast2 with darkice. I’m using Raspbian and the standard raspbian-distributed package for darkice is not compiled with ALSA support, and I nearly fell down a rabbit-hole trying to get OSS-compatible emulation working.

In the end, I was able to compile and install darkice with ALSA and mp3 support by following the excellent instructions here:

Continue reading

Modbus TCP Temperature Sensor with Arduino and LM335

I used to hate on Arduino a bit, but have recently come around. I was having a conversation with a work colleague along the lines of how super easy it would be nowadays to build a temperature sensor with ethernet connectivity and a modbus interface. Remembering that I had an old Arduino board (with Ethernet) kicking around from some abandoned project years ago, I laid myself a little personal challenge: to see how quickly I could prototype such a device. The answer is: Really, surprisingly quickly!

Gluing together other people’s hard work together made this a trivial exercise, and it was kind of too easy. It felt a bit like cheating. And I think this kind of plug-n-play, lego block engineering has made me lazy – I know someone else has already done the legwork so all my time is spent evaluating the relative merit of one library against another, rather than engineering something tricky from first principles. I guess this is both the blessing and the curse of the Arduino phenomenon.

Continue reading

LibreNMS network monitor with Slack integration and Oxidized config versioning

I used to use Observium for network monitoring. After evaluating a couple of options – Cacti, Zabbix, Nagios – I found Observium, and loved its beautiful, well organised and extremely usable interface. Observium has two main drawbacks for me though:

A few months after running Observium, and being largely happy with it despite the shortcomings above, I found LibreNMS. LibreNMS is an earlier forked version of Observium, and basically exists to ensure the project is run by friendly, community-minded folks. They’ve also implemented a lot more functionality, making it a much more complete and rounded product.

Continue reading

Install Request Tracker 4 from source with lighttpd and postfix on Ubuntu 14.04

Request Tracker is a tried-and-tested ticketing system, written in Perl. The manual installation documentation is pretty clear but not tailored to any particular distribution or configuration and I still had to do a bit of digging around to complete the installation, so I am posting my notes in case they help others.

Unpack the latest release of the application to /usr/local/src:

After building you have to install the extra dependencies. Unfortunately make fixdeps didn’t do a great job. Here’s all the extra packages I installed:

For my installation I’m also using Postfix as MTA to Sendgrid.

SMTP for Sendgrid on Postfix can be configured as per:
https://www.linode.com/docs/email/postfix/postfix-smtp-debian7#settings-for-sendgrid

In /etc/postfix/main.cf add:

In /etc/postfix/sasl_passwd:

Then, generate the password hash as per the link above.

Here’s the configuration for /opt/rt4/etc/RT_SiteConfig.pm:

I chose to use Lighttpd as my webserver. After installing it, I placed the following in /etc/lighttpd/lighttpd.conf:

Then (as I was installing on Ubuntu) I removed apache2 from startup:

Terrariums are fun

I’ve been playing with terrariums. I made a lot, to try out different ideas. One was made with a LED in the bottom of the lid providing illumination.

IMG_20160306_145021

A few months on and a friend is looking after it for me. The plants (well – the weed) has gone crazy and a little mushy has grown:

Continue reading

3G Weather Station using MangoES and RouterBoard

I thought I would share a recent little side-project that I did at work, putting together a neat and tidy solution to take wind measurements over a three month period for a customer who is interested in installing small wind turbines at some of their rural radio repeater sites.

With a tame sparky on hand to do the fabrication and mounting, I built two almost-identical boxes for the customer, using a MangoES to log data from a Davis Instruments “Vantage Pro 2” weather station. All the equipment in the box is powered by an external DC supply (one site has 48VDC, one has 12VDC) provided by the customer.

mango-weather-station

Continue reading

MiniPCIe cards on RB912 boards – how to make the interface appear

If you’re using MiniPCIe 3G cards on Mikrotik Routerboards, the new RB912 may be a much better choice than the older and cheaper RB411u, as the RB912 has the capability to interrupt or cycle power to the miniPCIe interface via software, which the RB411 lacks. In some particular circumstances*, such a full ‘power cycle’ of the 3G card can be necessary to restore 3G connectivity, and so for some installations, the RB912 is an essential choice when considering overall reliability.

Possibly because of this additional power cycling feature, I’ve found that 3G miniPCIe cards in the RB912 can be a bit tricker to get up and running. Out of the box, with a Sierra Wireless Mini-PCIe card (MC0705) installed, the card is inactive in the RB912 and the board will not have a 3G interface. In this case, it is necessary to first enable USB power to the MiniPCI interface by running:

If it doesn’t immediately come up (and instead tries to create an LTE interface), it’s quite possible that you need to disable DirectIP on the port first, hard reboot for good measure, then run the following:

Then, hard reboot for a final time and run the ‘usb set’ command as above again.

We can also use this power-cycling feature to create a more effective interface watch-dog script, that will monitor and reset power to the card if the interface goes down:

Add the script (or just that command) to the System Scheduler at any interval. Note that the board should have time to try to connect and bring that interface up before the script runs and power cycles it, so a start delay of 5-10 minutes (after boot) is a good idea.

IMG_20150205_164603624-edited small

* One common scenario here is when the network carrier has ‘cut off’ service for the SIM because the SIM’s data usage cap has been exceeded. We ran in to this often, and found that in most cases, there was no way to get that SIM back online other than by power cycling the radio itself. This seemed to be a limitation of the network/carrier.

Pulse Metering using ADAM-6051 units

We (at work) needed a quick and cheap solution for remotely collecting data (in pulses per 100L) from some gas volume meters so I built these two boxes. An Advantech ADAM-6051 unit in each box each reads and counts the pulses from two meters, and then the pulse count values (there are two pulse count channels per unit) are remotely read into a SCADA system using Modbus TCP.

I would not recommend the ADAM-6051 units. On paper they look good, but they can only be configured in Internet Explorer (using a very poor Java applet) and while the documentation for them is OK, the after-sales customer support is very poor.

IMG_20141003_175038-edited
Continue reading

Prius Panel Repairs

Oops. Prius v. concrete pole.

IMG_20150314_165754891-edited

Reading SNMP values from Mikrotik RouterOS into Mango Automation

If you use Mikrotik routerboard devices in your networking environment or for remote telemetry applications, you may be interested in retrieving some datapoints from the Routerboard using Mango’s SNMP datasource module.

In this example, I am going to monitor the up/down state of an interface, as well as the DC supply voltage to the routerboard – but of course you can monitor many more things using SNMP, such as interface traffic, temperature, even the number of wireless clients.

Pulling data points like these into Mango makes it possible to do a variety of interesting things. For example, I’m currently hacking together a Mango-based project that will alert me if the front door of my house is left open (via magnetic reed switch), which is a recurring problem. To figure out if anyone’s actually home, Mango will also retrieve the number of connected wireless clients from my home’s wireless access point. When the door is open, but no clients are active (with a bit of additional logic to prevent false alarms) Mango generates an email alert.
Continue reading

ISP congestion monitoring with Raspberry Pi

The ISP I use at home is suffering from pretty bad congestion and the service has become barely usable during peak times. Despite multiple reports from other customers, they won’t admit that there is a problem, so it’s time to show them some data!

Screen Shot 2015-04-16 at 10.46.50 pm

I put together a really quick and hacky shell script that grabs a large-ish file from their own speedtest server (within their network) and logs the max download speed to a CSV file.
Continue reading

Rancilio Silvia mods – PID temperature control, repaint, and open bottom portafilter

I installed a cheap chinese PID controller inside my Rancilio Silvia V2 espresso machine. Modifying the machine with PID control is not an entirely new concept, however my decision to mount it inside the front panel of the machine (rather than in an external enclosure) is reasonably novel. When I did it, I was not aware of anyone having done so, but I did later find some other examples.


eAA2qMa

Continue reading

Ghetto Lab PSU

Old ATX PSUs can easily be made into really great, regulated, high-current power supplies. It’s an old idea.

Banana posts for output (3.3V, 5V, 12V) with a 5A fuse on the AC side plus a neon indicator whenever AC is connected. An pushbutton with LED illumination (driven from 3.3V rail with some current limiting) starts the PSU and provides visual feedback that DC is on and OK. Can’t go wrong with a project that cost 5 bucks.

IMG_20130622_224004-edited
Continue reading

2003 Prius (NHW11) stock stereo replacement

I installed a JVC KD-R80BT in the CD Changer slot (the single-DIN slot just below the air con controls) of my NHW11 2003 Prius. It works perfectly and I’m really happy with how it turned out – I’d recommend the JVC unit to others wanting the same. The bluetooth speakerphone functionality and music streaming means I can just jump in my car and everything happens wirelessly. And installing it in the CD changer slot looks clean:

prius1

Continue reading

Monitor a SMA Power Reducer Box with Mango Automation

The SMA Power Reducer Box is a device for control of PV plants via some external control (usually ripple receiver from the grid operator). It has 4 digital inputs to select from up to 16 states of active and reactive power limitation.

For whatever reason, reading the current active power limitation setpoint value via Modbus is not possible. Nor can the value be read from the inverters or other plant devices – or SMA Webbox – using Modbus.

The solution I came up with is a bit hacky – but using Mango Automation, you can configure a HTTP retriever data source and regex expression to scrape and parse the value from the Power Reducer Box’s internal web server:

power-reducer-box

The public-access URL for the setpoint is:

And this is the regex expression that will match the active power limitation setpoint:

And here is the complete JSON export:

 

Counselling Centre business cards

I designed and printed these cards for a local counselling centre. Recycled stock, vegetable ink. The typeface is Gotham.

5841783852_a27db5287b_o

5841783962_831cb5755e_o

I also designed a custom WordPress theme (this is an earlier screenshot – I have since warmed the tones up).

Screen shot 2011-05-25 at 6.21.40 PM