Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

note: In order to access GPIO settings, make sure that iot package is installed beforehand.

...

GPIO stands for General-Purpose Input/Output. It is a digital signal pin/pins on the routerbboard routerboard that allows you to send/receive the signal. It can be useful in different scenarios, like:

...

note: in our examples, we are using KNOT as a reference device. Other devices may have a different pinout but the same principles apply.

...

Info

note: please check on a product page whether your hardware supports analog input or not.

In the "analog" setting you can measure voltages on the analog input/ADC input pins:

Please note that long-term (6.47.10) and stable (6.48.3) versions, you have to use "/system gpio", command structure remains the same as in "/iot gpio" examples, aside from "analog" and "digital" sub-menus, which were added in later versions. Versions 6.49beta54+ and RouterOS v7, use "/iot gpio" sub-menu.

/iot gpio analog

note: please check on a product page whether your hardware supports analog input or not.

In the "analog" setting you can measure voltages on the analog input/ADC input pins:

Code Block
language
Code Block
languageros
[admin@device] /iot gpio analog> print
 # NAME                                                                                     VALUE       OFFSET
 0 pin2                                                                                       0mV          0mV
 1 pin3                                                                                      32mV          0mV

...

"DIRECTION" for the pin can be either "input" (a pin that can receive the signal) or "output" (a pin that can send the signal).

Info

...

KNOT pin's

...

"DIRECTION" for pin4 and pin6 can not be changed. Both pins are meant to be used only as "output" pins.

When the pin's direction is set to "output", you can configure the "output", you can configure the "OUTPUT" value. Changing the "OUTPUT" value sends the signal to the pin.

...

The broker's "name" should be changed accordingly (you can check all created brokers and their names using CLI command /iot mqtt brokers print).

:local topic "topic"

The topic should be changed as well. The topic itself is configured on the server-side, so make sure that the correct topic is used.

).

:local topic "topic"

The topic should be changed as well. The topic itself is configured on the server-side, so make sure that the correct topic is used.

Do not forget to apply/set the script to pin5 (/iot gpio digital set pin5 script=script_name), as shown in the "email notification" example above.


If the mechanical switch is used to send the signal to the GPIO pin, it is suggested to use the following script instead (in case the script is initiated more than once when the signal is received on the pin):

:global gpioscriptrunning;
if (!$gpioscriptrunning) do={:set $gpioscriptrunning true;
:log info "script started - GPIO changed";
:do {if ([/iot gpio digital get pin5 input] = "0") do={/tool e-mail send to="config@mydomain.com" subject=[/system identity get name] body="pin5 received logical 0"} else {/tool e-mail send to="config@mydomain.com" subject=[/system identity get name]  body="pin5 received logical 1"};
:delay 1s;
:set $gpioscriptrunning false} on-error={:set $gpioscriptrunning false;
:log info "e-mail error, resetting script state..."}}

If the GPIO pin state changes more than once within mili/microseconds - the script above is going to make sure that e-mail notification is not sent more than onceDo not forget to apply/set the script to pin5 (/iot gpio digital set pin5 script=script_name), as shown in the "email notification" example above.

Monitoring voltage

Last but not least - is to "monitor voltage" using the analog pins.  You need a script that will read/monitor voltage on schedule and then send the data via e-mail, MQTT or HTTPS (fetch).

...