Complete DELPHI API client: update 4

update 4:

  • rewritten mrecv functions to avoid errors when output contains #0
  • faster output reducing timer interval between two sentences
  • now empty password are allowed
  • added output to log file

update 3:

The download contain the source code of a Delphi class (and of a demo application) to simply interface the routerOS API.
Please refer to http://wiki.mikrotik.com/wiki/API_Delphi for more informations.

LAST VERSION
api_studio_108.zip (497 KB)
Please report me suggestions, errors and so on.

Thanks.

Hi Rodolfo,

the included compiled EXE does work OK here. Compiling the source with Delphi 6 works (after hacking in a replacement for PosEx, which is not there in Delphi 6), but the tool hangs during opening the connection to the router. Actually it stalls in tr_mkrouter.open while waiting for the response for the first “/login” command. That’s in this line:

hash:=ex_val(res,'ret','',false);

Any idea?

Nevermind. Seems to be a bug with the version of the synapse library contained in your download.
I checked out the latest revision from SVN (rev. 95) and it started working right away :wink:

where did you download synapse from?

Main site http://www.ararat.cz/synapse/doku.php/download
Last version: https://synalist.svn.sourceforge.net/svnroot/synalist/trunk/

cmit: thanks, I updated the main thread with last library

i have tried this software its great, i would like to know why it doesnt handle streaming data from the router,
for example: i am trying this command /tool ping 192.168.100.1

one time i get this:
14/01/2009 05.21.50 - 142 -
14/01/2009 05.21.50 - info 102 - EXECUTE= /tool ping 192.168.100.1
14/01/2009 05.21.50 - info 103 - =!done=

and the other time i get this (why?) :
14/01/2009 05.23.57 - 142 -
14/01/2009 05.23.57 - info 102 - EXECUTE= /tool ping 192.168.100.1
14/01/2009 05.23.57 - #ERROR# 10004 - 192.168.100.1 tr_mkrouter.mrecv !trap==!trap=message=no such command=
14/01/2009 05.23.57 - info 103 - =!trap=message
=no such command=

ping works differently using api, than usual ping in terminal

on api, you get result of how many pings sent, and how many you received back, so you have to set =count= allways

or it will run until you issue cancel command to cancel your ping.

I have Delphi 5 and could not compile without some tweaking:

I tried /ping =address=10.50.10.13 =count=3 and it works ok, but returns just number of successful ping. Is there an option to get all ping details?

Response string is not parsed properly.

It is very strange that = is uset to delimiter both items and item name and value. It is very tricky to parse.

Here is an example:

=!re=.id=*6=name=wan-adsl=mtu=1500=mac-address=00:41:05:4F:82:DA=arp=enabled=disable-running-check=yes=auto-negotiation=yes=full-duplex=yes=cable-settings=default=speed=100Mbps=running=yes=slave=no=comment==disabled=no==

It’s hard to distinguish which part is item name and which one is item value.

Is it possible to change these delimiters?

if you try other example and sniff for actual API traffic you will notice that there is symbol in between the lines and your output of :
=!re=.id=*6=name=wan-adsl=mtu=1500=mac-address=00:41:05:4F:82:DA=arp=enabled=disable-running-check=yes=auto-negotiation=yes=full-duplex=yes=cable-settings=default=speed=100Mbps=running=yes=slave=no=comment==disabled=no==

actually looks more like:

=!re
=.id=*6
=name=wan-adsl
=mtu=1500
=mac-address=00:41:05:4F:82:DA
=arp=enabled
=disable-running-check=yes
=auto-negotiation=yes
=full-duplex=yes
=cable-settings=default
=speed=100Mbps
=running=yes
=slave=no
=comment=
=disabled=no
==

now, compare what i get when issue the command in my implementation:

!re
=.id=*1
=name=ether1
=mtu=1500
=mac-address=00:0C:42:2D:80:06
=arp=enabled
=auto-negotiation=yes
=full-duplex=yes
=speed=100Mbps
=running=yes
=slave=no
=comment=
=disabled=no

as far as i can remember - each line have value preceding the line, that shows how many symbols there is in the line, hence, always it will be like =some-arg=value and value will be everything till the end of line after 2nd “=”

either fix that in the code or ask someone to do that for you

Right! :slight_smile: Silly me, I forgot that I am not getting data directly from Mikrotik but from intermediate layer which was messed up. I got it now. Thanks.

I entierely rewritten the library, taking in account the correct numbering of the send commands and !done received.

Now commands link /tool/ping =address=19.19.18.17 works well, as the others command.

Thanks for suggestions.

You could download from main post.

Rodolfo

I published a wiki page and update a little the code.
thanks

oops, example application do not work with empty password =)

also, this class do not work correctly with replies, containing #0 in parameter value, because it is designed to think that #0 is the end of sentence. so, for example, I cannot get normal list of my DHCP server leases, where Agent-Circuit-ID is MAC address of switch and contains #0 in it

I see something like the following:

=!re=.id=*3952
<...text here...>
=src-mac-address=00:1E:58:49:EF:F1
=agent-circuit-id=
==agent-remote-id
=
=XIпс=radius
=true
=dynamic
=tru=
=blocked=false

p.s. why is this implementation so slow?.. mine is based on Synapse too, and prints output much faster… I hope some day I will public it, I just began to code…

Hi Chupaka, thanks for suggestions.
I have updated the code and:

  1. empty passwords could be allowed
  2. I rewritten mrecv function. Now I have a better implementation of the protocol and #0 char works well
  3. I reduced a lot the timer interval between the receive of two sentences and the output is much faster.

Dear rodolfo:

I am using the API to develop an control software as ‘Mini-winbox’, now i face an trouble with the api.
when i want to issuse the command like ‘/ip/router/unset .id=*2 routing-mark’ , i get get an argument error.

How to using unset command through RouterOS API?

I have ask this question 1 year before, but no body can answer me as well, Would u like to help me on this ? Thank u very much~!

did you asked support@mikrotik.com ?

ya, not yet ,i think i need to report to them too, thx Chupaka