Power Management via Mikrotik + Windows Phone

    I read the article KUB-Pico220 Controller-Socket from Technotronics and decided to share my bike with the habrasociety.

    It was necessary to implement power management from a cell phone. There are a lot of these solutions, with a wide variety of technological solutions and price limits. But the problem was that it was necessary to do it VERY urgently, as the customer said - “We need it yesterday”. Given the distance from Moscow at 6000 km (and the upcoming weekend), the problem arose decent.

    After browsing the Internet, I came across an article - http://www.lanmart.ru/blogs/mikrotik-rb750up-remote-power-management-220v/ which helped a lot, considering that this router was available, but it was used for another but when VERY necessary it is possible to remove :)

    For implementation details welcome to cat (photo)

    Initially, they decided to test by taking one outlet and act exactly in accordance with the article.


    And it didn’t work :) After a short Google search, it turned out that after updating the firmware and upgrading the PoE version (the command in MikroTik routers interface ethernet poe settings upgrade), this instruction ceases to correspond to reality as a line resistance test was added. And when using a relay, it is.

    But it doesn’t matter! A little knowledge of the basics of electrical circuits and the station of a young technician visited in childhood suggested to try to throw a diode. The result is what you see in the picture (do not scold for installation - this was only at the time of the test)



    AND BINGO! It worked exactly as we needed :)

    Further, everything was neatly packed in a standard electrical panel -


    and connected. Now, through WinBox (or via the web interface, or via ssh, or via telnet), it was possible to control the power by sending commands
    interface ethernet set ether2 poe-out=forced-onto turn off
    and
    interface ethernet set ether2 poe-out=offto turn on.
    By changing the port number (from 2 to 5), it was possible to control a specific outlet.

    Further (recall TK), control via a cell phone was required. In general, there was no longer any problem - there is WinBox for mobile platforms, a web interface, and many SSH clients. Also (since there is a USB port in the router), it was possible to connect a USB modem and control via SMS. But we could not be stopped.

    Since the customer wanted it to be as simple as possible, they took the Windows Phone 8X by HTC and Microsoft Visual Studio Express 2012 for Windows Phone. And the project MikrotikOnOff was created in it.

    All programming at the end came down to just three actions -
    1. Created a form


    2. Connected the SSH.NET library

    3. Added the following code (I don’t give the settings code, there is the standard IsolatedStorageSettings.ApplicationSettings)

            private string MikrotikSSHCommand (string MikrotikIP, int MikrotikSshPort, string MikrotikUser , string MikrotikPassword, string Command)
            {
                try
                {
                    ConnectionInfo sLogin = new PasswordConnectionInfo (MikrotikIP, MikrotikSshPort, MikrotikUser, MikrotikPassword);
                    SshClient sClient = new SshClient (sLogin);
                    sClient.Connect ();
     
                    SshCommand appStatCmd = sClient.CreateCommand (Command);
                    appStatCmd.Execute ();
     
                    sClient.Disconnect ();
                    sClient.Dispose ();
     
                    return appStatCmd.Result;
                }
                catch
                {
                    return "Server connection failure";
                }
            }        
     
     
            private void Btn_All_On_Click (object sender, RoutedEventArgs e)
            {
                MessageBox.Show (MikrotikSSHCommand (MikrotikIP, MikrotikSshPort, MikrotikUser, MikrotikPassword, "system script run 0"));
            }
     
            private void Btn_All_Off_Click (object sender, RoutedEventArgs e)
            {
                MessageBox.Show (MikrotikSSHCommand (MikrotikIP, MikrotikSshPort, MikrotikUser, MikrotikPassword, "system script run 1"));
            }
     
            private void Btn_Test_Click (object sender, RoutedEventArgs e)
            {
                MessageBox.Show (MikrotikSSHCommand (MikrotikIP, MikrotikSshPort, MikrotikUser, MikrotikPassword, "system script run 2"));
            }
     

    This is where the creation of the program ended :)

    Then we created scripts on Mikrotik - it is possible through System - Scripts. It is possible through the console

    / system script
    add name = "All On" policy = ftp, reboot, read, write, policy, test, winbox, password, sniff, sensitive, api source = \
        "interface ethernet set ether2 poe-out = off \ r \
        \ ninterface ethernet set ether3 poe-out = off \ r \
        \ ninterface ethernet set ether4 poe-out = off \ r \
        \ ninterface ethernet set ether5 poe-out = off "
    add name =" All off "policy = ftp, reboot, read, write, policy, test, winbox, password, sniff, sensitive, api source = \
        "interface ethernet set ether2 poe-out = forced-on \ r \
        \ ninterface ethernet set ether3 poe-out = forced-on \ r \
        \ ninterface ethernet set ether4 poe-out = forced-on \ r \
        \ ninterface ethernet set ether5 poe-out = forced-on "
    add name = SystemIdent policy = ftp, reboot, read, write, policy, test, winbox, password, sniff, sensitive, api source = \
        " system identity print "

    And you can check, pack and give to the customer


    A little about the pros and cons of this solution -
    Pros
    • Cost - except for the phone that was, the total price of the solution was 3120 rubles (2200 router itself, 400 rubles box, 160 rubles - 4 sockets on a DIN rail, 280 rubles - 4 relays with blocks, 80 rubles - 4 terminal connectors )
    • Reliability - Mikrotik routers are quite reliable and stable in operation, which allows you not to worry about the power management system hanging up (before that, I had to deal with two remote control systems - quality and stability were not up to par)
    • Manageability - in my case, it was only necessary to remotely control the power from a cell phone, but no one forbids making more serious decisions using all kinds of Mikrotik tools - from the simplest ping and power-up when not responding, to fairly complex scripted actions with a execution schedule
    • 4 controlled sockets - in most solutions of this price level it is one, which is quite inconvenient
    • Easy for the end user - all they need to do is press a single button to manage their power


    Minuses
    • Electrical safety - anyway, given some “collective farm” solutions, there are some concerns about its protection and other parameters. I would do it now - I would take a bigger box and push it into each outlet by a differential machine.


    PS: Smart people on ixbt suggested that another diode is needed
    Jamal: So that when the voltage from the relay is removed, the inductive current surge from it does not fry everything around. A diode is needed in order for the current surge to run inside the closed loop formed by the winding and the diode and spend it on heating the windings and the diode, and not on burning the nearby electronics

    . In short: the coil, by definition, resists the current change, and if the current stops (the relay is de-energized), then the energy stored in the coil will tend to keep the current from stopping. Hence the surge.

    But I did not do this, this advice was received after the delivery to the customer. But considering that it has been working for quite a long time, let's hope for the best :)

    UPD: Tip from a NetRat user
    I would use solid state relays. In this case, the diode is not needed and the relays with the heatsink themselves are perfectly mounted on the dinrake.

    For example, you can use something like http://www.electronshik.ru/card/rele-g3pa-so-smennimi-silovimi-elementami-10-50160a-88159 , but in this case the price increases (by about 8 thousand ) But the solution is more beautiful and correct.

    bougakov
    Tell me, what kind of relay did you use? Very like a car 12V 30A
    Relays 90.3777 were used.

    Also popular now: