It did go quicker then I expected.
You also have the right to use my photo I placed above this post. I can deliver you the same photo at a higher resolution if you want.
====================================================================
How to use your Blink(1) / Blink(1) mk2 of ThingM on your GL-AR150 (or other OpenWRT router AR71xx based)
Let me explain some things: English is not my native language (Dutch is my native language) and I do have only a basic knowledge about Linux based on Debian / Raspbian (Raspberry Pi). Some sentences may be wierd due this reasons. My apologies for that. I hope the text is still readable and understable.
A few things I assume you already know or already did:
- You are logged on as root through a SSH session.
- You are familiar with how to tranfer files to your GL-AR150 (FTP, SCP, etc.)
- You are familiar how to extract ZIP-files.
Step 1: create directory to store blink1-tool
At first we need to create a directory to store the blink1-tool at.
I mainly create a directory /data on all linux devices I own with local storage and mountpoints in it. On my Raspberry Pi for example I mount my USB-storage to /data/usb and share it with Samba to my Windows PC. On both my Raspberry Py and my GL iNet GL-AR150 I also use the local storage and only create it under /data/local (so no special mount).
I asume you already have logged on on your GL-AR150 as root through a SSH session.
Then you can go to the root by executing
cd /
Then we will create the needed directory’s (I have based my steps on the information found here: Setting up a Raspberry Pi Samba Server - The Urban Penguin):
mkdir -m 1777 /data
mkdir -m 1777 /data/local
mkdir -m 0755 /data/local/blink1
Step 2: download the right blink1-tool version
Go to the created directory:
cd /data/local/blink1
Download “blink1-tool-openwrt-ar71xx.zip” from https://github.com/todbot/blink1/releases/tag/v1.95.
Extract the file “blink1-tool” out of the ZIP-file.
Transfer the file “blink1-tool” to your GL-AR150 router at the directory /data/local/blink1
Step 3: give the correct rights to blink1-tool
The file “blink1-tool” needs executing rights.
Provide the execute rights by executing the following command:
chmod +x blink1-tool
Step 4: connect your Blink(1) and test it
Now connect your Blink1 to test it.
You can simply turn a white bright light on on the Blink(1) with the following command:
./blink1-tool --on
To turn it off:
./blink1-tool --off
Step 5: create script to execute Blink(10 commands by switching the switch on the GL-AR150
I use the programm “nano” to edit files. It is a small programm and a lot easier to control then “vi”. If you prefer to use “vi” and you are familiar with how to use “vi” you may keep using “vi” on your own.
To install “nano” execute:
opkg install nano
Then we will navigate to the button scripts by executing:
cd /etc/rc.button
When you have installed “nano” you can load the file “BTN_8” into it by executing:
nano BTN_8
The we will place the following content:
#!/bin/sh
logger "Button: $BUTTON ; State: ${ACTION}";
if [ "${ACTION}" == "pressed" ]; then
/data/local/blink1/blink1-tool --on > /dev/zero;
logger "Blink(1) switched to 'on'.";
else
/data/local/blink1/blink1-tool --off > dev/zero;
logger "Blink(1) switched to 'off'.";
fi
“#!/bin/sh” should always stay on the very first line!
The variable “$BUTTON” contains the name of the button which is being used within this script. In this case it will contain the value “BTN_8”.
The variable “${ACTION}” will contain the state of the button: “pressed” or “released”.
After the blink1 commands you see “> /dev/zero”. This will prevent any output to the console since we don’t need to see that output.
“logger” will log the text after it to the logs which you can read later on with the command “logread” on the console.
When you use “nano” you can now exit “nano” bij pressing CTRL+X on your keyboard, then press “y” to save the file and press enter to keep using the filename “BTN_8”.
Step 6: test the switch
At startup of your GL-AR150 the state of the button will not have any effect on your Blink(1). You need to switch the switch.
If you switch the switch to the left position the script will fetch the “pressed” state and turns your Blink(1) on. If you switch the switch to the right position the script will fetch the “released” state and turns your Blink(1) off.
Advanced example 1: Blink(1) mk2 with different colors per LED
The Blink(1) mk2 does have 2 different LED’s on the same device which you can control indepently.
Here’s a example script for “BTN_8” which will swap the right and green light from side when you switch the switch to the different positions:
#!/bin/sh
logger "Button: $BUTTON ; State: ${ACTION}";
if [ "${ACTION}" == "pressed" ]; then
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=1 > /dev/zero
/data/local/blink1/blink1-tool --rgb=075,0,0 --led=2 > /dev/zero
else
/data/local/blink1/blink1-tool --rgb=075,0,0 --led=1 > /dev/zero
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=2 > /dev/zero
fi
This will turn LED 1 on with a soft green color and LED 2 on with a soft red color when the button has the state “pressed” (switched to the left position).
It will turn LED 1 with a soft red color and LED 2 on with a soft green color when the button has the state “released” (switched to the right position).
Advanced example 2: Blink(1) mk2 with 3 LED states
The switch actually has 3 positions. Because the manufacturer has limited the use of the switch by putting the enclosure in front of the third position you weren’t able to use the third position. You can see a small thinner part of the enclosure at the right side of the switch. When you open the enclosure with caution and drill away that thin part you will be able to use the third position of the switch.
The switch actually drives BTN_7 when the button is switched to the most right position. The middle position sets the “released” state to BTN_7 or BTN_8 following where the switch came from:
- When the switch is at the most left position it sets BTN_8 to “pressed”.
- When manouvre the switch to the middle position it sets BTN_8 to “released”.
- When the switch is at the most right position it sets BTN_7 to “pressed”.
- When manouvre the switch back to the middle position it now sets BTN_7 to the “released” state.
That makes it possible to also provided 3 states for the Blink(1) mk2.
I use it as follows:
- Most left: LED 1 soft green, LED 2 soft red
- Middle: LED 1 soft green, LED 2 soft green
- Right: LED 1 soft red, LED 2 soft green
My content for the BTN_8 file at /etc/rc.button :
#!/bin/sh
logger "Button: $BUTTON ; State: ${ACTION}";
if [ "${ACTION}" == "pressed" ]; then
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=1 > /dev/zero
/data/local/blink1/blink1-tool --rgb=075,0,0 --led=2 > /dev/zero
else
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=1 > /dev/zero
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=2 > /dev/zero
fi
And my content for the BTN_7 file at /etc/rc.button :
#!/bin/sh
logger "Button: $BUTTON ; State: ${ACTION}";
if [ "${ACTION}" == "pressed" ]; then
/data/local/blink1/blink1-tool --rgb=075,0,0 --led=1 > /dev/zero
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=2 > /dev/zero
else
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=1 > /dev/zero
/data/local/blink1/blink1-tool --rgb=0,075,0 --led=2 > /dev/zero
fi
Of course you can edit both BTN_8 and BTN_7 to your own wishes. The scripts do also have effect when you connect the Blink(1) to an USB hub which is connected to the GL-AR150.