Xbmc4xbox Openwrt Wifi Telnet Script Help

Discussion of plugin / script development for XBMC4Xbox
Post Reply
Jimbob7891
Posts: 12
Joined: Tue Apr 10, 2018 1:10 am
Has thanked: 5 times
Been thanked: 1 time

Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by Jimbob7891 »

Im new to python this is my attempt to add wifi
[youtube]https://youtu.be/bo8X5rsZ-Lw[/youtube]
Image

I read all of this viewtopic.php?t=1965 and used goteamscotch script as a starting point. and ended up here

Code: Select all

import xbmc, xbmcgui, time
import sys
import telnetlib

dialog = xbmcgui.Dialog()
dprogress = xbmcgui.DialogProgress()
host = "192.168.0.25"
tn = telnetlib.Telnet(host, 23)

#Telnet.set_debuglevel (1)
scan_results = tn.read_until("OpenWrt:/#")
#time.sleep(1)
tn.write("Scanning\n")
#time.sleep(1)
scan_results = tn.read_until("Enter")

ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7

class openwrt(xbmcgui.Window):
  def __init__(self):
    self.addControl(xbmcgui.ControlImage(0,0,1280,720, 'background.png'))
    self.strActionInfo = xbmcgui.ControlLabel(326,82,720,480, '', 'font13', '0xFF00FF00')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('scan_results')
    self.button1 = xbmcgui.ControlButton(240, 134, 80, 30, "No1")
    self.addControl(self.button1)
    self.setFocus(self.button1)
  def onAction(self, action):
    if action == ACTION_PREVIOUS_MENU:
      self.confirmexit()
    if action == ACTION_SELECT_ITEM:
      self.No()
  def confirmexit(self):
    dialog = xbmcgui.Dialog()
    if dialog.yesno("Confirm", "Are you sure you want to quit?"):
      self.close()

import telnetlib
host = "192.168.0.25"
tn = telnetlib.Telnet(host, 23)
self.tn.write("exit\n")
tn.write("exit\n")
self.tn.write("reboot\n")
tn.write("reboot\n")

    
    

#  def No1(
      
#    self.button2 = xbmcgui.ControlButton(240, 164, 80, 30, "No2")
#    self.addControl(self.button2)
#    self.setFocus(self.button2)
#    self.button3 = xbmcgui.ControlButton(240, 194, 80, 30, "No3")
#    self.addControl(self.button3)
#    self.setFocus(self.button3)
#    self.button4 = xbmcgui.ControlButton(240, 224, 80, 30, "No4")
#    self.addControl(self.button4)
#    self.setFocus(self.button4)
#    self.button5 = xbmcgui.ControlButton(240, 254, 80, 30, "No5")
#    self.addControl(self.button5)
#    self.setFocus(self.button5)
#    self.button6 = xbmcgui.ControlButton(240, 284, 80, 30, "No6")
#    self.addControl(self.button6)
#    self.setFocus(self.button6)
#    self.button7 = xbmcgui.ControlButton(240, 314, 80, 30, "No7")
#    self.addControl(self.button7)
#    self.setFocus(self.button7)
#    self.button8 = xbmcgui.ControlButton(240, 344, 80, 30, "No8")
#    self.addControl(self.button8)
#    self.setFocus(self.button8)
#    self.button9 = xbmcgui.ControlButton(240, 374, 80, 30, "No9")
#    self.addControl(self.button9)
#    self.setFocus(self.button9)
#    self.button10 = xbmcgui.ControlButton(240, 404, 80, 30, "No10")
#    self.addControl(self.button10)
#    self.setFocus(self.button10)
  
#def No10(self):
#  self.strActionInfo = xbmcgui.ControlLabel(100, 300, 300, 800, '', 'font13', '0xFFFFFFFF')
#  self.addControl(self.strActionInfo)#(0,0,720,480, 'Q:\\scripts\\background.jpg'))
#  keyboard = xbmc.Keyboard('password')
#  keyboard.doModal()
#  if (keyboard.isConfirmed()):
#    self.strActionInfo.setLabel(keyboard.getText())
#  else:
#    self.strActionInfo.setLabel('user canceled')

#scan_results = tn.read_until("OpenWrt:/#")#, timeout = 10)
  #time.sleep(1)
#tn.write("exit\n")
#self.tn.write("exit\n")
#self.tn.write("exit\n")
#tn.expect("networks:", timeout = 5)
#scan_results = tn.read_until("OpenWrt:/#")
#scan_results = tn.read_lazy(timeout = 5)

#  def onControl(self, control):
 #   if control == self.button10:
  #    self.No10()

#def No1(self):
 # host = "192.168.0.25"
#  tn = telnetlib.Telnet(host, 23)
#  self.tn.write ("exit\n")
#  self.tn.write ("exit\n")
#  tn.read_untill("network:")
#  tn.write("password\n")
#  scan_results = tn.read_all()
#  def onControl(self, control):
#    if control == self.button1:
#      self.No1()

#  def No2(self):
#    if dialog.yesno("No2", "connect?"):
#      self.tn.write("2\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button2:
#      self.No2()

#  def No3(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No3", "connect?"):
#      self.tn.write("3\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button3:
#      self.No3()
      
#  def No4(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No4", "connect?"):
#      self.tn.write("4\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button4:
#      self.No4()

#  def No5(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No5", "connect?"):
#      self.tn.write("5\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button5:
#      self.No5()
#      
#  def No6(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No6", "connect?"):
#      self.tn.write("6\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button6:
#      self.No6()
#      
#  def No7(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No7", "connect?"):
#      self.tn.write("7\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button7:
#      self.No7()
#      
#  def No8(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No8", "connect?"):
#      self.tn.write("8\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button8:
#      self.No8()
#      
#  def No9(self):
#    dialog = xbmcgui.Dialog()
#    if dialog.yesno("No9", "connect?"):
#      self.tn.write("9\n")
#      if network:
#        tn.read_untill("network")
#        tn.write(keyboard + "\n")
#  def onControl(self, control):
#    if control == self.button9:
#      self.No9()
#          
#  def onControl(self, control):
#    if control == self.button10:
#      self.No10()
#def onAction(self, action):
#  if action == ACTION_PREVIOUS_MENU:
#    self.confirmexit()
      
#def confirmexit(self):
#  dialog = xbmcgui.Dialog()
#  if dialog.yesno("Confirm", "Are you sure you want to quit?"):
#    self.close()
 
mydisplay = openwrt()
mydisplay.strActionInfo.setLabel(scan_results)
mydisplay .doModal()

del mydisplay
Im no coder just trying to piece it all together
Last edited by Jimbob7891 on Thu Apr 18, 2019 9:14 am, edited 4 times in total.
User avatar
cashonly
Posts: 181
Joined: Thu Jul 19, 2012 5:12 pm
Has thanked: 20 times
Been thanked: 32 times

Re: Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by cashonly »

how do we use this?
These pretzels are making me thirsty!
Jimbob7891
Posts: 12
Joined: Tue Apr 10, 2018 1:10 am
Has thanked: 5 times
Been thanked: 1 time

Re: Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by Jimbob7891 »

This is far from finished and other than listing wifi networks is useless.
Im having trouble running telent commands once under a def or class.
If i can work this out the rest isnt too hard
Jimbob7891
Posts: 12
Joined: Tue Apr 10, 2018 1:10 am
Has thanked: 5 times
Been thanked: 1 time

Re: Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by Jimbob7891 »

Image
i need to update my code but once i work out how to select button with controller, i can add button but cant select them this is about done.
tested and connected to my wifi no problem
i can add more as i go once i work out the buttons
Jimbob7891
Posts: 12
Joined: Tue Apr 10, 2018 1:10 am
Has thanked: 5 times
Been thanked: 1 time

Re: Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by Jimbob7891 »

Image
Image
Image
User avatar
GoTeamScotch
Posts: 268
Joined: Sat Apr 06, 2013 2:17 am
Has thanked: 97 times
Been thanked: 75 times

Re: Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by GoTeamScotch »

Looks like you've been busy. ;)

Glad to see you making progress on this script. I'm tempted to bust out my dd-wrt router and start playing around with this.
Image
Remember kids, always zero-ize your HDD key!
Jimbob7891
Posts: 12
Joined: Tue Apr 10, 2018 1:10 am
Has thanked: 5 times
Been thanked: 1 time

Re: Xbmc4xbox Openwrt Wifi Telnet Script Help

Post by Jimbob7891 »

:D
Post Reply