This may already be covered at some point in the previous 8 pages of this thread, but this has been my experience over the past 24 hours trying to get Python running in Metarouter on RB493AH:
Working Image:
http://openwrt.wk.cz/trunk/mr-mips/open ... sic.tar.gz
RouterOS Version: RouterOS v6.40.9
Had no problems copying the image to my 493, going to MetaRouter, importing it, and starting it up.
I created a dynamic interface for it under Metarouter --> Interfaces, and added vif1 to my LAN bridge on the 493.
This let OpenWRT grab an IP using its DHCP client, which was already running.
It did NOT configure a DNS server automatically however - not sure why, so I added "nameserver 8.8.8.8" to /etc/resolv.conf.
I don't know if I just missed something, or if it's some sort of bug - I didn't really look into it too hard.
At this point, I had internet, which let me download and install python 2.7, and its requirements:
wget http://openwrt.wk.cz/trunk/mr-mips/packages/libpthread_0.9.33-104_mr-mips.ipk
wget http://openwrt.wk.cz/trunk/mr-mips/packages/zlib_1.2.5-1_mr-mips.ipk
wget http://openwrt.wk.cz/trunk/mr-mips/packages/libffi_3.0.10-1_mr-mips.ipk
wget http://openwrt.wk.cz/trunk/mr-mips/packages/python-mini_2.7.3rc2-2_mr-mips.ipk
wget http://openwrt.wk.cz/trunk/mr-mips/packages/python_2.7.3rc2-2_mr-mips.ipk
opkg install *.ipk
rm -v *.ipk
This should give you working python2.7.
To talk to the host mikrotik using Mikrotik API, you have a few choices:
- https://github.com/rtician/routeros
- https://github.com/socialwifi/RouterOS-api
Option 1 is a project that doesn't seem to have any SSL support (can't use the Mikrotik API SSL protocol), so it should work out of the box.
Option 2 is slightly harder to get to work.
In both cases, the problem you'll likely run into is SSL. OpenWRT keeps things lean, and doesn't include SSL support out of the box.
As far as I can tell, normally, you can install SSL using opkg without much effort. Unfortunately,
http://openwrt.wk.cz/trunk/mr-mips/packages/, which is a repository of pre-built packages that will work on the MIPS CPU the RB493AH has, does not appear to have the SSL package. This means:
- You can't use wget to download anything that starts with https (SSL encrypted web pages)
- You need to modify RouterOS-api to disable SSL support, or it won't run
To get around the fact that you can't download anything from HTTPS, I just downloaded stuff on a different computer, and used SCP to copy it over to OpenWRT.
Note: OpenWRT's tar also didn't seem to like extracting some of the packages I was downloading, so if you have a .tar.gz file you need to extract, you might need to extract it on a different machine and scp it as an extracted folder.
To get around RouterOS_api having built-in SSL support, which causes "import routeros_api" to fail (complains about importing of _ssl), you need to disable ssl. Find and modify api_socket.py in that project, and do 2 things:
- Comment out "import ssl"
- In get_socket(), right before this line
- if ssl_context is None and use_ssl:
add this:
- if ssl_context or use_ssl: raise Exception("SSL not supported on OpenWRT")
It's probably enough to just comment out the import line, but I added a bit of extra code in case I ever forget, and try to use api_ssl.
At this point, as long as your current working directory has the routeros_api folder in it, you should be able to import routeros_api and use it.
If you want to install routeros_api system-wide, you can either move the entire routeros_api dir anywhere that's in python's sys.path (I haven't tried this, but it'll probably work), or use Python's SetupTools.
To use SetupTools, which is actually required in order to install a bunch of packages from PyPi, you can do this:
- Download the setup tools zip file from https://pypi.org/project/setuptools/#files on any other machine
- Extract it
- SCP the extracted folder to OpenWRT
- cd into that folder on openwrt
- Run "python setup.py install"
- Delete the setup tools folder to save space - it's now installed system-wide
At that point, you can go back to the RouterOS_API directory, and run "python setup.py install" on that, which will install it system-wide.
If it complains about failing to import "six", you can download that from pypi and install it with "python setup.py install" just like everything else.
Having setuptools installed will let you download and install many of the packages found on pypi's website.
It seems like most packages work, as long as they don't have C binaries that need to be compiled first - OpenWRT doesn't have a gcc compiler pre-installed.
You can even download and install pip from pypi, and it seems to work fine, except for the fact that the pypi repos are ssl-protected, and with OpenWRT not having SSL support, pip fails to fetch anything.
SSL isn't totally essential for what I'm trying to do, but my 493 should have plenty of hard drive space for it (about 70MB free - I would think it would fit), so it would be nice to have. Unfortunately, as far as I can tell, the only way to get it working is to use the toolchain to cross-compile ssl binaries on a different system, and move them to OpenWRT, unless someone out there is nice enough to do this and put them online. I haven't tried this yet - maybe I will at some point.
Essentially, what this lets you do is install any packages from github or pypi that are pure python. If you need to do mikrotik discovery using MNDP, or talk to a mikrotik using mac telnet, have a look at
https://github.com/pjoe/py-mactelnet. Its MNDP script is pure python, and works great. It's mac-telnet script uses netifaces, which is a C module, making it not work out of the box, but as far as I can tell, the only thing netifaces does is make it easier for the mac-telnet script to grab the MAC and IP of the interfaces on OpenWRT, which can be done without netifaces, so it probably wouldn't take much effort to remove the dependency on netifaces.
If this is interesting to anyone, but they're having trouble following my rushed explanation, let me know, and I'll try to clarify.