...
- Measuring voltage through ADC input
- Reading 0 and 1 signal received from another device - "dry contact"
- Controlling connected relays by sending logical 0 or 1 signal to the pin
RouterOS configuration
note: GPIO settings are available only using CLI.
...
note: in our examples, we are using KNOT as a reference device. Other devices may have a different pinout but the same principles apply.
/iot gpio analog
note: please check on a product page whether your hardware supports analog input or not.
...
Code Block | ||
---|---|---|
| ||
[admin@device] /iot gpio analog> set pin2 offset Offset ::= [-]Num[mV] Num ::= -2147483648..2147483647 (integer number) [admin@device] /iot gpio analog> set pin2 offset 2 [admin@device] /iot gpio analog> print # NAME VALUE OFFSET 0 pin2 2mV 2mV 1 pin3 0mV 0mV |
/iot gpio digital
In the "digital" section you can send/receive a logical 0 or 1 signal using the digital output/input pins (output pins are "open drain"):
...
Code Block | ||
---|---|---|
| ||
[admin@device] /iot gpio digital> set pin4 script=script1 [admin@device] /iot gpio digital> set pin5 script="/system .." [admin@device] /iot gpio digital> print Flags: X - disabled # NAME DIRECTION OUTPUT INPUT SCRIPT 0 pin5 input 0 0 /system .. 1 pin4 output 1 script1 2 pin6 output 0 |
Different scenarios
Controlling relays
One of the scenarios for the GPIO implementation is "controlling other relays" using digital output pins. Basically, sending "0" or "1" signal to the unit that is connected to the pin. To automate the process, you can use a scheduler, which will run the script at specific times.
...
You can change the scheduled time as you see fit (depending on the requirements).
Monitoring input signal
Another scenario is to "monitor input signal" using the digital input pins. You need a script that will initiate e-mail notification or MQTT/HTTPS (fetch) publish whenever the "INPUT" value changes for the pin with the direction="input" (whenever the RouterOS device receives a signal "0 or 1" from another device connected to the pin).
...
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.
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).
...