📜 ⬆️ ⬇️

We manage NooLite devices from Zyxel Keenetic router

image

In this article I will talk about how to manage nooLite devices via a USB PC1xx adapter directly from a Zyxel Keenetic router - without a computer.

Preamble


Themes about NooLite have already flashed here more than once, but just in case, let me remind you that these are components for building a “smart home” that communicate with each other via a radio channel. You can also order a USB adapter to their system, which allows you to send commands from a computer (in fact, there is one that can receive these commands, but we will not consider it now). Once upon a time, I specifically raised a Web server on my machine, which I could access from a computer or phone on my home network and control the lighting, as well as add scheduled tasks. For example - I, like a true owl, hardly wake up early in the morning, and even would not do it with pleasure, but I must. And to wake up in the dark from the sound of the alarm clock, it was extremely difficult, even if you put on it the sweetest melody, of all the sweet melodies on earth. And I decided to conduct an experiment by writing a script for smoothly turning on the light, when the brightness increases from 0 to 100% in 20 minutes, thereby imitating the sunrise, and the experiment was a success - it became much easier to wake up when the light does not sharply hit the eyes, but barely increases noticeably, and the body reacts to such an awakening much better than the alarm clock ... But something I left the topic. It all worked quietly for myself, and yet I wasn’t even bothered by the fact that a constantly turned on computer was required, I had quiet fans and it was hardly heard, but not so long ago after learning that you could install OpenWRT packages on Zyxel Keenetic with the second version firmware an idea began to ripen in my mind. And when this idea completely finished me, in no way wanting to leave my brain alone, I decided - well, to hell with it! Ahead of the weekend, and I will do it!

Agenda


So what did I actually do? I did the following:
')
- Web-based light and load control interface directly in Zyxel Keenetic router.
- Commands are sent directly from the router, via the USB transmitter NooLite (PC1xxx) plugged into the USB port of the router.
- In the web interface, you can configure scheduled tasks for cron to control the light.
- A console utility that allows you to send commands directly from the command line of the router (under SSH) and if my web interface was not to your taste, you can write your own or embed its call from anywhere.

Shut up and take my money
So what we need to configure. To begin with, we will prepare a router, this is done simply and in sufficient detail described here . Next we need to install several packages, therefore we do the following:

opkg update opkg install php5-cgi lighttpd-mod-fastcgi cron 

This command installs a web server, php, and cron for scheduling tasks. I would also put the Midnight Commander, for it is more convenient:
 opkg install mc 

Next, edit the Web server settings: /opt/etc/lighttpd/lighttpd.conf specifying the correct port:
server.port = 82

The 80th port is already occupied by the web interface of the router, so we select another one.
Then we edit the file: /opt/etc/lighttpd/conf.d/30-fastcgi.conf, doing this:

fastcgi.server = ( ".php" =>
( "php-local" =>
(
"socket" => "/opt/tmp/php-fastcgi-1.socket",
"bin-path" => "/opt/bin/php-fcgi",
"max-procs" => 1,
"broken-scriptfilename" => "enable",
)
),
# .....
# .....
)


That's all, and now we start the server:

 lighttpd -f /opt/etc/lighttpd/lighttpd.conf 

This preparation is completed, and you can proceed to the most important. Download this archive. It contains the program, a couple of libs, and php files. From the binaries folder we throw the binaries on the router's USB flash drive, bin in bin, lib in lib, share in share. In theory, he should not offer something to replace, but if he offers, we refuse, because we need to figure it out. If you do not trust me, then in the archive in the source folder is the source code of the utility for sending NooLite commands, you can build it yourself. How to do this is a separate topic, I will not paint here, there is a lot of information about this on the net. So, if all the files are thrown in their places, you can check the performance of this miracle. Go to the browser and enter the IP address of the router and the port that you specified in the web server settings.
http://192.168.1.1:82/

image

Here we should see a page with lighting control. But not yours, but mine. In order to make your settings, you need to edit the file: /opt/share/www/config.php

image

I specifically documented it with comments, I think there will be no problems with editing it. After you configure everything to fit your configuration, you can start using it. The web interface is made more for mobile devices, but on the desktop you can also use it. Special attention is paid to what to create, enable, disable and delete tasks for cron, you can directly from the browser, with changes, cron will be restarted and you do not need to think about anything. If you want to use the console utility, just type the following command in SSH:
noolite

You will see a list of parameters, here, too, nothing complicated.

image

I checked it on Zyxel Keenetic Giga II, it has 2 USB ports, but as far as I know, on routers with one USB port, you can use a hub. I decided to check it out and it worked for me through the hub.

That's all, I hope you were interested and you found this article useful. If you have questions - ask, I will be glad to answer.

Source: https://habr.com/ru/post/396635/


All Articles