📜 ⬆️ ⬇️

Another traffic light in the office

Hello, my name is Maxim and I am an employee of the IT department of a trading company. Once, my colleagues and I decided that we were missing in the traffic light department. We have not yet understood why we need it, but the irresistible "I want" overcome us ...


image


And now, after a couple of minutes, we are already looking for it on the Internet. Requirements were as follows: real, cheap, warm-lamp, you can used. Found quickly, ordered, paid, waited. Received, unpacked, disassembled, washed. Collected. Put the light bulb. Turned on all at once. The office got warmer.


Were thinking where to adapt it and how to manage it.


The Ke-USB24R was found in the table nightstand - in essence, a USB module with four relays that can be controlled from a computer by writing data to a virtual COM port, plus 18 IO lines and four 10-bit ADCs. Details and instructions on the manufacturer's website http://www.kernelchip.ru/Ke-USB24R.php


I connected a traffic light through it. It turned out to blink bulbs separately, using software from the manufacturer's website.


Then they decided that it would be nice to fasten the traffic light to the monitoring system zabbix, which works in the company. The traffic light should signal problems depending on the importance of triggered triggers:



Wrote a script on PowerShell. The logic of work is as follows:


  1. Receives three parameters
    • numeric trigger id
    • trigger status (0 - OK, 1 - Problem)
    • numeric trigger value
  2. If a trigger has arrived with a problem - we add it to the array, if a trigger has arrived with a solution to the problem - we delete it from the array
  3. Based on what values ​​of the triggers are in the array, this or that signal is turned on.

An array of triggers with identifiers of problem triggers is stored in the xml file.


I am not a programmer. I did as I knew and knew how, it seems to work without failures. If there are comments I will listen and try to take into account in the future.


Script code traffic_lights.ps1
#  $trigger_id = $args[0] #0 - , 1 - Problem $trigger_status = $args[1] #   . 0 -  , 1 - , 2 - , 3 - , 4 - , 5 - . $trigger_nsev = $args[2] #      $red = 1 $yellow = 2 $green = 3 #    Key - ID , Value -    $triggers=@{} #      $triggers = Import-Clixml -Path C:\Users\User\Desktop\DB_traffic_lights.xml #     if ($trigger_status -eq 1) { #        if (!$triggers.ContainsKey($trigger_id)) { #    $triggers.Add($trigger_id,$trigger_nsev) } } #      else { #         if ($triggers.ContainsKey($trigger_id)) { #     $triggers.Remove($trigger_id) } } #      $triggers | Export-Clixml -Path C:\Users\User\Desktop\DB_traffic_lights.xml #-    $red_turn_on = $false $yellow_turn_on = $false #   foreach ($trigger in $triggers) { switch ($trigger.Values) { #0 -   0 { } #1 -  1 { } #2 -  2 { $yellow_turn_on = $true } #3 -  3 { $yellow_turn_on = $true } #4 -  4 { $red_turn_on = $true } #5 -  5 { $red_turn_on = $true } } } #[System.IO.Ports.SerialPort]::getportnames() $port = New-Object System.IO.Ports.SerialPort $port.PortName = 'COM4' $port.BaudRate = '9600' $port.Parity = "None" $port.Handshake = "None" $port.DataBits = 8 $port.StopBits = 1 $port.ReadTimeout = 500 $port.WriteTimeout = 500 $port.DtrEnable = $true $port.RtsEnable = $true $port.Open() if ($port.IsOpen -eq $true) { #      if($trigger_status -eq "0") { #    $command = '$KE,REL,' + $red + ',0'+"`r" $port.WriteLine($command) $command = '$KE,REL,' + $yellow + ',0'+"`r" $port.WriteLine($command) #   $command = '$KE,REL,' + $green + ',1'+"`r" $port.WriteLine($command) Start-Sleep -Milliseconds 300 $command = '$KE,REL,' + $green + ',0'+"`r" $port.WriteLine($command) Start-Sleep -Milliseconds 300 $command = '$KE,REL,' + $green + ',1'+"`r" $port.WriteLine($command) Start-Sleep -Milliseconds 300 $command = '$KE,REL,' + $green + ',0'+"`r" $port.WriteLine($command) Start-Sleep -Milliseconds 300 } #    if ($red_turn_on) { $command = '$KE,REL,' + $red + ',1'+"`r" $port.WriteLine($command) } #    if ($yellow_turn_on) { $command = '$KE,REL,' + $yellow + ',1'+"`r" $port.WriteLine($command) } } $port.Close() 

In the settings of the zabbix server, I added an action (Settings -> Actions) in which I specified in the conditions: Trigger value = PROBLEM, Trigger value = OK.


Screenshot

image


And in the Operations indicated "Run remote commands on the nodes in the network." A remote node is a computer running a zabbix agent:


 powershell.exe -File C:\Users\User\Desktop\traffic_lights.ps1 {TRIGGER.ID} {TRIGGER.VALUE} {TRIGGER.NSEVERITY} 

Screenshot

image


Thus, when a trigger is triggered, a script is executed with the necessary parameters on a remote computer to which the traffic light control module is connected. The light is on or off.



The result was an interesting and functional element of the interior, very much attracting attention. We have to answer a lot of questions like where we got it and why we need it, how much it costs and so on. In the future, I plan to make the device autonomous, to avoid using a computer and a USB controller. Replace it with some Ethernet-Relay module and transfer the logic of work to the zabbix server. Modify the display and hang it vertically.


Thanks for attention!


')

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


All Articles