Monday, May 15, 2017

KanKun Wireless Plug

I recently purchased  a wireless KanKun plug, specifically because I heard that it was running a version of OpenWRT and could easily be modified.

I found the primary directions here.

There were a couple of challenges.  The first was getting the plug on the wireless network.  The Chinese directions and app did not function at all, and I tried them multiple times.

The good news is that the plug successfully resets all failed attempts very well with its reset process.  Eventually I was successful following these steps:

- Use a laptop to connect to the wireless network the plug defaults to creating.
- Lookup the Plugs IP based on the DHCP address assigned to the laptop because it did not create the network that most examples were claiming it would.
- Use Putty to SSH into the plug with a username of 'root'.  My default password was p9z34c, however others have claimed it might be admin or 1234.
- Edit the following file with 'vi': /etc/config/wireless

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '9'
        option hwmode '11ng'
        option path 'platform/ar933x_wmac'
        list ht_capab 'SHORT-GI-20'
        list ht_capab 'SHORT-GI-40'
        list ht_capab 'RX-STBC1'
        list ht_capab 'DSSS_CCK-40'
        option htmode 'HT20'
        option disabled '0'
        option country 'CN'

config wifi-iface
        option device 'radio0'
        option network 'wwan'
        option ssid 'MyWirelessSID'
        option encryption 'psk2'
        option mode 'sta'
        option key 'MyWirelessPassword'

I made sure the channel was set correctly since I run my wireless network on 9 rather than the standard 11.  I also struggled a bit with the encryption since I run WPA2 Personal; I finally got the very logical instructions to set encryption to 'psk2'.

- The second critical file to edit is: /etc/config/network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd59:45ed:8ead:0000:/48'

config interface 'lan'
        option ifname 'eth0'
        option force_link '1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.145.253'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option proto 'dhcp'
        option ifname 'eth1'

config interface 'wwan'
        option proto 'static'
        option ipaddr '192.168.1.32'
        option gateway '192.168.1.1'
        option netmask '255.255.255.0'

I modified the MAC address in this file, adding the '0000', however leaving it empty would probably have been fine as well from what others have said; and considering it was working prior.  Adding the last 'config interface wwan' section is the most critical.  It is used by the wireless file for interface settings and specifies the static IP network necessary to communicate on this network.

- 'reboot' the plug
- With the plug now successfully connecting to my network I was able to return to my main computer for further configuration.
- My next step was to copy in a simple CGI script someone created to allow me to remotely control the plug.  I did have to modify the following script slightly because my RELAY_CTRL was different from the ones they were using.
- I had to create the folder /www/cgi-bin
- And create the following file: /www/cgi-bin/relay.cgi

#!/bin/sh
echo "Content-Type: text/plain"
echo "Cache-Control: no-cache, must-revalidate"
echo "Expires: Sat, 26 Jul 1997 05:00:00 GMT"
echo

RELAY_CTRL=/sys/class/leds/i-konke\:red\:relay/brightness

case "$QUERY_STRING" in
state) 
case "`cat $RELAY_CTRL`" in
0) echo "OFF"
;;
1) echo "ON"
;;
esac
;;
on) 
echo 1 > $RELAY_CTRL
echo OK
;;
off) 
echo 0 > $RELAY_CTRL
echo OK
;;
esac

- Unfortunately I discovered that the uhttpd service did not exist on my plug.  I had to turn to a very helpful Internet community who was able to give me the required files.  You can download them here.
- Inside the rar file you should see a kkplug folder with the most likely folder structure and the files that go in each folder.  Use WinSCP to copy the files to the plug.
- Run the following command
/etc/init.d/uhttpd enable
- This creates a sym link that causes the plug to execute the startup file on boot.
- 'reboot' again to test and verify that the service will start correctly.

- When the plug comes up you should be able to use a web browser and control the plug in this way.
http://192.168.1.32/cgi-bin/relay.cgi?on

No comments:

Post a Comment

Please leave your thoughts, I love hearing what you got out of the post. Spam comments will be removed.