Another RouterOS API Delphi Client

It’s my API client realization for Delphi7. It implements execution of parallel queries which are easily handled due to database-like interface.

v1.3: Added support for RouterOS 6.43+ API login method
v1.2: Added basic support for API over TLS
v1.1: Added Delphi 2009 compatibility (thanks to Anton Ekermans for testing)

GitHub page: https://github.com/Chupaka/Delphi-RouterOS-API
GitHub releases: https://github.com/Chupaka/Delphi-RouterOS-API/releases

Direct links to files:
Delphi-RouterOS-API-1.3.zip: https://github.com/Chupaka/Delphi-RouterOS-API/archive/v1.3.zip
APITest-source-1.3.zip: https://github.com/Chupaka/Delphi-RouterOS-API/releases/download/v1.3/APITest-source-1.3.zip
APITest-1.3.exe: https://github.com/Chupaka/Delphi-RouterOS-API/releases/download/v1.3/APITest-1.3.exe

Hi Chupaka

I am searching some one there can help developing an api to the routeros.

Would you contact me at dev (at) sealink dot dk

The final result should make a communication from a web portal interface to the routerboard for activating predefined scripts on the routerboard ex. could be

The interface, API and scripts will give a user ex. in the reception of a hotel a https page where he can login. On this page the hotel have all network plugs for meeting rooms.
The user pick a room “center stage east” and choose 6 hours from the drop down menu and a few other parameters like which bandwidth there are required.
When he click execute button then it should establish a connection by the API to the routeros and execute a script which is on the routerboard.

For further details about your consulting please contact me.

B/R
Kenneth

Is this unit D2009 compatible? Should I convert all String to AnsiString to avoid Unicode clashes?

Thanks
Ekkas

New version 1.1: Delphi 2009 compatibility (thanks to Anton Ekermans for testing)
Requires Synapse Release 39

oops… reuploaded with fixed typo in version history: it’s Nov, not Oct :blush:

Thanks a lot Chupaka, for your good work,
it will help me a lot.

Chupaka,
very good work with “RouterOSAPI.pas” I am a doubt, because not found any procedure in the engine ROSAPI for when the connection to incorrectly, you already did something for this case?? to be clearer for example when Winbox this running and for some reason it loses connectivity to the server then it terminates the application, I am trying to do that! you can help me?

Chupak,

very good work with “RouterOSAPI.pas” I have some doubts, because not found in any procedure for ROSAPI engine stoped when the connection incorrectly, you already did something for this case?? to be clearer for example when Winbox this running and for some reason it loses connectivity to the server then it terminates the application, I am trying to do that! you can help me?

unfortunately, there’s no such functions. you may try to check Synapse Socket state directly

Hey Chupaka! Hope you’re doing well…

I’ve been developing some very nice stuff with ROS to read info from my ±200 RBs, it’s really great!
But I have a question:
How do I set a value using ROSAPI? e.g. i can read ‘hw-protection-mode’ by:
Res := ROS.Query([‘/interface/wireless/print’], True);
if not Res.Trap
then begin
ShowMessage(Res[‘hw-protection-mode’]);
end;
but how do I set the value to e.g. ‘hw-protection-mode=rts-cts’ ?


Anton Ekermans

Res := ROS.Query([‘/interface/wireless/set’, ‘=.id=*bla-bla-bla’, ‘=hw-protection-mode=HERE’], True);

Sorry for the trouble, but I run the command:
Res:=ROS.Query([‘/interface/wireless/set’, ‘=.id=*1234’, ‘=hw-protection-mode=client-mode’], True);

It returns without error, but the value stays unchanged?

just tested with v4.5…

/interface/wireless/print
=.proplist=.id,hw-protection-mode

returns

!re=
=.id=*6
=hw-protection-mode=none

now change hw-protection-mode:

/interface/wireless/set
=.id=*6
=hw-protection-mode=cts-to-self

and after that query again, response is

!re=
=.id=*6
=hw-protection-mode=cts-to-self

tested using ‘APITest’ application from the first post…

I did not bother using the .id returned from first query and just gave it a random number, I suppose that is my problem.
Thanks.

:smiley: sure it is )))

To Chupaka:
Im trying do develop something similar in C# using the help from http://wiki.mikrotik.com/wiki/API_in_C_Sharp, but I have some problems concerning sending the requests:
I run the application, Login forms po-pup - input login,passwd, connect successfully, main application window is open.
And now if I want to execute(send) certain commands to the router I use the same function,which was used to create connection at the beginning but without login function. But then I get response from router about !fatalogin.
Is it necessary to use login and passwd, set at the beginning, to execute(send) each command sentence to the router? How do you do it?

Maybe I’m doing the whole thing wrong, but I thought it could work.

PS:I don’t work with Delphi at all so your code does not really help me.

You shouldn’t need to send the login info with each request, as long as you maintain (keep open) the same session/conection.
Once the session is authenticated, it should work on the same session.
Maybe you can generate an exact log of what you send/receive and post it here, that might be easier to see what’s wrong as C code would not make any sense to a Delphi-only programmer like me either. (Or at least compare the log with the API wiki)

Ekkas

anyway, if we see what output you have, we could say where is the problem.

And as previously said - basic steps are - make tcp/ip connection, authenticate w/ /login, send commands, close connection.
now every part in bit more detail

  1. making of connection - easy part, simple connection
  2. /login part - you have to follow the procedure carefully, getting challenge, forming reply and getting positive reply that you are in
  3. sending commands - on each command you send you will get reply. if you use several commands that will run for some time (/ping, something with =follow=) use .tag, to tag replies
  4. when you are done, terminate connection.

Thanks for your replies.

I already got to the point 3 where I can send comands without problems(but only one at the same time) except these two:
/interface/monitor-traffic
/interface/wireless/scan

  • the first one works only with argumnent once.
  • is sth like once also by the scan?

I will be probably sending more request at the same time( for example I will monitor bandwidth and I will also want to get info about some interface..), so you think just to tag the reqest is enough? Because I was thinking about threading, where especially those commands like monitor,scan etc will be send through one of these threads.

hmmm… maybe the problem is you are waiting for ‘!done’, but those command you should stop manually by ‘/cancel’?..