Dothat - what goes wrong?


#1

This is my script:

#!/usr/bin/env python
import sys
import socket
sys.path.append("../../")


import dothat.touch as touch
import dothat.lcd as lcd
import dothat.backlight as backlight
import dot3k.backlight
from dot3k.menu import Menu, MenuOption
from plugins.utils import Backlight, Contrast
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed
from plugins.clock import Clock
from plugins.wlan import Wlan
from plugins.text import Text
import time
import os
import urllib2
import threading
import dot3k.lcd as lcd
import dot3k.backlight as backlight

lcd.clear()
backlight.rgb(100, 200, 255)
time.sleep(3)
checker = True

class poweroff(MenuOption):
      def __init__(self):
        self.start = self.millis()
        MenuOption.__init__(self)
      def redraw(self, menu):
        menu.write_row(0, 'Abracadabra!')
        menu.clear_row(1)
        menu.clear_row(2)
        #dot3k.backlight.rgb(100, 100, 100)
        time.sleep(1)
        #os.system("sudo python /home/pi/Scripts/send_wemo_commands.py slaapkamer.off")
        menu.left()

class poweron(MenuOption):
      def __init__(self):
        self.start = self.millis()
        MenuOption.__init__(self)
      def redraw(self, menu):
        menu.write_row(0, 'Helloow!')
        menu.clear_row(1)
        menu.clear_row(2)
        #dot3k.backlight.rgb(100, 100, 100)
        time.sleep(1)
        #os.system("sudo python /home/pi/Scripts/send_wemo_commands.py slaapkamer.on")
        menu.left()

class backlightoff(MenuOption):
      def __init__(self):
        self.start = self.millis()
        MenuOption.__init__(self)
      def redraw(self, menu):
        checker = False
        menu.write_row(0, 'Lights out!')
        menu.clear_row(1)
        menu.clear_row(2)
        dot3k.backlight.rgb(0, 0, 0)
        time.sleep(1)
        menu.left()
	
class backlighton(MenuOption):
      def __init__(self):
        self.start = self.millis()
        MenuOption.__init__(self)
      def redraw(self, menu):
        checker = True
        menu.write_row(0, 'Lights on!')
        menu.clear_row(1)
        menu.clear_row(2)
        dot3k.backlight.rgb(255, 0, 0)
        time.sleep(1)
        menu.left()




def internetstatus():
 hostname = "192.168.1.1"

 while checker:
          response = os.system("ping -c 1 " + hostname)
          if response == 0:  
	    # def __init__(self):
	    #  self.start = self.millis()
            #  MenuOption.__init__(self)
	    # def redraw(self, menu):  			
             backlight.rgb(0, 100, 0)
	    #  dot3k.backlight.rgb(100, 100, 100)
             time.sleep(3)	
          else:		
	     #def __init__(self):
             # self.start = self.millis()
	     # MenuOption.__init__(self)	
             #def redraw(self, menu):
              backlight.rgb(0, 0, 255)
              #menu.write_row(0, 'No WiFi and, or')
	      #menu.write_row(1, 'No Internet')
	      #menu.clear_row(2)
               #dot3k.backlight.rgb(100, 100, 100)
	      time.sleep(2)
  





def menuu():
 	menu = Menu(
	    structure={
       	 'Power On': poweron(),
       	 'Power Off': poweroff(),
	 'Backlight Off': backlightoff(),
         'Backlight On': backlighton()
       	     },
	    lcd=lcd,
#	    idle_handler=poweron,
#	    idle_timeout=5,
	    input_handler=Text())
	touch.bind_defaults(menu)

	while 1:
	    menu.redraw()
	    time.sleep(0.05)




a = threading.Thread(name='internetstatus', target=internetstatus)
b = threading.Thread(name='menuu', target=menuu)


a.start()
b.start()

So basically what it does is ping 192.168.1.1 (router). If ping succeeds, backlight turns green. If ping fails, backlight turns red.
Then there are two options for a wemo switch ( off and on ). But that only works if you have wifi, hence the red and green background.

Then there is an option called Backlight Off. When chosen, the backlight goes off for a second and then flips back on ( red or green, depending if I have WiFi ). It doesn’t stay off.
It all comes down to the variable named checker. Something goes wrong when checking it’s status.

Also I’m 100% sure my code could be a lot better but I’m actually just learning and believe I’ve come quite far in just a matter of days so please bear with me :)