Community discussions

MikroTik App
 
User avatar
Molleby
just joined
Topic Author
Posts: 6
Joined: Mon Oct 24, 2022 9:54 am

Permanently running scripts, keyboard input and relay control

Mon Mar 06, 2023 10:19 am

We have been tasked to create the following prototype setup for a potential client, and I need to know if the following setup is possible using scripting:

We would like to connect a USB-numpad to a Mikrotik KNOT (the KNOT is our go-to communications module, and we would like to avoid using something like a Raspberry Pi or similar). The KNOT controls a relay via the GPIO pins, which controls a pump. When a user enters a valid code, the pump runs until the user enters a stop key. The duration of the pump run is sent to an external server along with the user ID and timestamp.

Now, what I need to know, to determine if we can use the KNOT or not, is the following:

I have read that the KNOT can read serial input, so it should be able to catch the numpad keystrokes in a script. However, this might require that a script is running permanently to listen for the numpad inputs over serial? So, is it possible to have a script running permanently and reliably? Or can a small script be executed everytime a keystroke happens, sort of like when a GPIO pin executes a script in this example:
https://help.mikrotik.com/docs/display/ ... ter+device
If a keystroke could start a small script, when each key value could be saved in a global variable, and then when the # key is entered, a start-relay-script is activated.

So, can we use a permanently running script and/or a "small-script-per-keystroke-input"?
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3441
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Permanently running scripts, keyboard input and relay control

Tue Mar 07, 2023 8:50 am

Ran into similar stuff myself. The serial port just isn't very scriptable in RouterOS. There certainly no equivalent of the old UNIX expect, but more fundamentally there isn't some basic read/write operation for serial.

Couple ideas but no ideal for the KNOT.

- What they let you do is convert serial into TCP data (either raw sockets or rfc2217/telnet). See /ports/remote-access. This lets you send serial data to someplace else, like office or cloud. But for something like a pump, you'd like want to be able to turn that on without internet. I built a container "serial2http" (viewtopic.php?t=193785) that takes the TCP to essentially proxy serial data via HTTP requests that do this locally...BUT the KNOT doesn't support containers so it won't work.

- I've used these Texxmo IoT buttons that send an HTTP request upon press, so these can be used to trigger a script via REST on the Mikrotik. https://www.texxmo.info/get-your-iot-buttons/ but not sure they actively sell them, we haven't used them in a while. I guess you could put in it physical key box or similar with analog combo log. Or maybe some like similar device with keypad exists that more Wi-Fi friendly for the KNOT.

- The scripting language does support :inkey which waits for keyboard input, so if the keypad acted as HID device. Perhaps that might be useful, still the serial port can NOT be routed directly to a script, only the command line – which doesn't help since you'd need to accept a PIN code as the first keypresses. Not a command to launch a script...

So not a lot of instant ideas for your problem. Mikrotik scripting language was built for routing, so the I/O operations are rather limited, and they only "recently" started getting into IoT gateway things, but the language hasn't been extended to support them particular well. And you can't just load some driver/program into RouterOS.

Maybe someone else has ideas here, but this "authenticated push to start script"... I dunno of any good ones.
 
User avatar
Sertik
Member
Member
Posts: 435
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: Permanently running scripts, keyboard input and relay control

Tue Mar 07, 2023 9:21 am

There are ideas. But they are not allowed to be published. Some of the forum moderators are deleting my posts. Apparently competition or sanctions against Russia.
 
User avatar
Molleby
just joined
Topic Author
Posts: 6
Joined: Mon Oct 24, 2022 9:54 am

Re: Permanently running scripts, keyboard input and relay control

Tue Mar 07, 2023 12:29 pm

Ran into similar stuff myself. The serial port just isn't very scriptable in RouterOS. There certainly no equivalent of the old UNIX expect, but more fundamentally there isn't some basic read/write operation for serial.
Thanks for the input. I think we will need to go another route then. Maybe let an arduino handle the numpad and relay stuff, and then just let the KNOT handle communications. But it's too bad, we were hoping to use the KNOT as a sort of Swiss army knife tool with the GPIO pins and other features.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Permanently running scripts, keyboard input and relay control

Tue Mar 07, 2023 2:46 pm

against Russia
The sanctions are against those who govern, not against the people.
The Russians don't want war.They are brothers like everyone else.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3441
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Permanently running scripts, keyboard input and relay control

Tue Mar 07, 2023 5:06 pm

I think we will need to go another route then. Maybe let an arduino handle the numpad and relay stuff, and then just let the KNOT handle communications. But it's too bad, we were hoping to use the KNOT as a sort of Swiss army knife tool with the GPIO pins and other features.
I think it mainly the accepting keypad input into a script that's the tricky one. Everything else you describe should be possible in scripting.

I did put in a feature request a little bit ago for some "serial-chat" that operate like "at-chat" in PPP/LTE, except supporting a "terminating regex" to wait for and/or timeout. e.g. Today, in scripting you can send serial using the /ppp/at-chat, but if it doesn't respond with an unchangeable "OK" response (understandable since it designed for AT commands)... but means you can't use for it for generic serial protocol to get any data back from the far side of the KNOT serial.

Maybe some hardware/GPIO scheme possible to get some keypad to work, dunno.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3441
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Permanently running scripts, keyboard input and relay control

Tue Mar 07, 2023 5:08 pm

There are ideas.
FWIW I don't think technical ideas have boundaries.
*unless those ideas come from ChatGPT

Who is online

Users browsing this forum: No registered users and 42 guests