Send commands to DD-WRT router
#1
I'm currently in the process of taking up Python and getting familiar with it. I've been sifting through documentation and online references to make a script that can send commands to a DD-WRT based router via telnet commands. At this stage the script loads, goes to a black screen and displays the output from the telnet session. It's very rough and ugly but so far so good Smile . At this stage I'm just having troubles with how to get the output to display correctly. I'm using ControlLabel (xbmcgui.ControlLabel) to display output but I'm starting to get the feeling that it's only meant for titles because there appears to be a width limit.

Background: I'm building a custom Xbox with a stripped down Belkin wireless router with DD-WRT installed inside of it, and I need to set it up as a Repeater Bridge (already done, works fine). But the thing is, there will be times where I'll need to connect it to other wifi networks or change the way the router behaves through a set of predefined commands. Later on it will eventually scan for nearby access points, return a list of SSID's (and ask for a passkey if required), but baby steps first, right?

Anyways, so main question: What's the best way to display (and later update) text on screen?

Current code (works)
Code:
import xbmc, xbmcgui
import sys
import telnetlib

host = "192.168.1.2"
user = "root"
password = "admin"

tn = telnetlib.Telnet(host)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
   tn.read_until("Password: ")
   tn.write(password + "\n")

tn.write("nvram show\n")
tn.write("exit\n")
nvram_result = tn.read_all()

ACTION_PREVIOUS_MENU = 10

class toolsmain(xbmcgui.Window):
  def __init__(self):
    self.strActionInfo = xbmcgui.ControlLabel(20, 20, 200, 600, '', 'font13', '0xFF00FF00')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('DD-WRT Tools')

  def onAction(self, action):
    if action == ACTION_PREVIOUS_MENU:
      self.confirmexit()

  def confirmexit(self):
    dialog = xbmcgui.Dialog()
    if dialog.yesno("Confirm Exit", "Are you sure you want to exit?"):
      self.close()

mydisplay = toolsmain()
mydisplay.strActionInfo.setLabel(nvram_result)
mydisplay .doModal()

del mydisplay

Which shows up as:
Image
Reply
#2
Quote: self.strActionInfo = xbmcgui.ControlLabel(20, 20, 200, 600, '', 'font13', '0xFF00FF00')

Here you are setting the control... Try:
Code:
self.setCoordinateResolution(1)
self.strActionInfo = xbmcgui.ControlLabel(0, 0, 1280, 720 ....

That should make the ControlLabel fit the screen size.

Also a monospaced font would be nice to look at..

cheers Nordish
Reply
#3
Thanks for the speedy reply

The change you suggested made the script fail to execute.

I added it here:
Code:
class toolsmain(xbmcgui.Window):
  def __init__(self):
    self.setCoordinateResolution(1)
    self.strActionInfo = xbmcgui.ControlLabel(0, 0, 1280, 720, '', 'font13', '0xFF00FF00')
...

Fails to execute in Xbmc4Xbox 3.3.2 Stable
Reply
#4
That means there's a syntax error somewhere in the script. Look at the xbmc logfile to find the python error message. It's probably a misplaced paren or inconsistent indentation, but the log will tell you for sure.
Reply
#5
(2013-12-01, 18:36)jerimiah797 Wrote: That means there's a syntax error somewhere in the script. Look at the xbmc logfile to find the python error message. It's probably a misplaced paren or inconsistent indentation, but the log will tell you for sure.

Good call. That was exactly it.
Even though it looked exactly how it should indentation-wise, I copied and pasted the indentation from the line above and it worked. Must have been a bunch of spaces as opposed to a tab-indent or something.

Anyways, it's showing up full width now and I'm starting to tie in a few some useful commands to issue to DD-WRT. I'm also in the process of drawing inspiration from a few other scripts to see how they handle settings and GUI elements. This is shaping up to work beautifully. Thank you for the help nordish and jeremiah. I'm a long standing member in Xbox-scene and Xbmc4Xbox forums but this is my first time in the official Xbmc forums and I see Xbmc is still attracting knowledgeable helpful people to its community. Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Send commands to DD-WRT router0