コード例 #1
0
ファイル: zmq_tracker.py プロジェクト: ccoupe/tracker
def main():
    global settings, hmqtt, log, imageHub, imageQ
    # process args - port number,
    ap = argparse.ArgumentParser()
    ap.add_argument("-c",
                    "--conf",
                    required=True,
                    type=str,
                    help="path and name of the json configuration file")
    args = vars(ap.parse_args())

    # logging setup
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')
    log = logging.getLogger('ML_Tracker')

    settings = Settings(log, (args["conf"]))
    hmqtt = Homie_MQTT(settings, ctrlCB)
    settings.print()

    # load the pre-computed models...
    init_models()

    log.info(f'listen on {settings.our_IP}:{settings.image_port}')
    imageHub = imagezmq.ImageHub(open_port=f'tcp://*:{settings.image_port}')
    imageQ = Queue.Queue(maxsize=60)
    log.info('tracker running')
    server = HTTPServer(('', 5000), CamHandler)
    log.info("http server started")
    server.serve_forever()
コード例 #2
0
ファイル: alarm.py プロジェクト: ccoupe/mqtt-alarm
def main():
    global isDarwin, settings, hmqtt, applog, audiodev
    # process cmdline arguments
    loglevels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
    ap = argparse.ArgumentParser()
    ap.add_argument("-c",
                    "--conf",
                    required=True,
                    type=str,
                    help="path and name of the json configuration file")
    ap.add_argument("-s",
                    "--syslog",
                    action='store_true',
                    default=False,
                    help="use syslog")
    ap.add_argument("-d",
                    "--debug",
                    action='store',
                    type=int,
                    default='3',
                    nargs='?',
                    help="debug level, default is 3")
    args = vars(ap.parse_args())

    # logging setup
    applog = logging.getLogger('mqttalarm')
    #applog.setLevel(args['log'])
    if args['syslog']:
        applog.setLevel(logging.DEBUG)
        handler = logging.handlers.SysLogHandler(address='/dev/log')
        # formatter for syslog (no date/time or appname. Just  msg.
        formatter = logging.Formatter(
            '%(name)s-%(levelname)-5s: %(message)-40s')
        handler.setFormatter(formatter)
        applog.addHandler(handler)
    else:
        logging.basicConfig(
            level=logging.DEBUG,
            datefmt="%H:%M:%S",
            format='%(asctime)s %(levelname)-5s %(message)-40s')

    audiodev = AudioDev()
    isDarwin = audiodev.isDarwin
    settings = Settings(args["conf"], audiodev, applog)

    hmqtt = Homie_MQTT(settings, playUrl, chimeCb, sirenCb, strobeCb)
    settings.print()

    # fix debug levels
    if args['debug'] == None:
        debug_level = 3
    else:
        debug_level = args['debug']

    # All we do now is loop over a 5 minute delay
    while True:
        time.sleep(5 * 60)
コード例 #3
0
                "--debug",
                action='store',
                type=int,
                default='3',
                nargs='?',
                help="debug level, default is 3")
args = vars(ap.parse_args())
# fix debug levels
if args['debug'] == None:
    debug_level = 3
else:
    debug_level = args['debug']

settings = Settings(args["conf"], None, log)
hmqtt = Homie_MQTT(settings)
settings.print()

# Now we loop forever
unresp = 0
while True:
    # get the ups data
    status = {}
    try:
        with PyNUTClient() as s:
            status = s.list_vars(settings.nut_ups)
    except:
        pass

    # did we get good values?
    if 'ups.status' not in status or 'battery.charge' not in status or 'battery.runtime' not in status:
        unresp += 1
コード例 #4
0
ファイル: turrets.py プロジェクト: ccoupe/mqtt-turret
def main():
  global settings, hmqtt, applog, turrets, tur_locks
  # process cmdline arguments
  loglevels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
  ap = argparse.ArgumentParser()
  ap.add_argument("-c", "--conf", required=True, type=str,
    help="path and name of the json configuration file")
  ap.add_argument("-s", "--syslog", action = 'store_true',
    default=False, help="use syslog")
  ap.add_argument("-d", "--debug", action='store', type=int, default='3',
    nargs='?', help="debug level, default is 3")
  args = vars(ap.parse_args())
  
  # logging setup
  applog = logging.getLogger('mqttlaser')
  #applog.setLevel(args['log'])
  if args['syslog']:
    applog.setLevel(logging.DEBUG)
    handler = logging.handlers.SysLogHandler(address = '/dev/log')
    # formatter for syslog (no date/time or appname. Just  msg.
    formatter = logging.Formatter('%(name)s-%(levelname)-5s: %(message)-40s')
    handler.setFormatter(formatter)
    applog.addHandler(handler)
  else:
    logging.basicConfig(level=logging.DEBUG,datefmt="%H:%M:%S",format='%(asctime)s %(levelname)-5s %(message)-40s')

  #GPIO.setmode(GPIO.BOARD)

  settings = Settings(args["conf"], 
                      applog)
  # init turrets from settings. Do any of the turret
  # use PCA9685, if so, we init that device here.
  init_pca = False
  kit = None
  for t in settings.turrets:
    if t.get('laser_pin', False):
      init_pca = True
  if init_pca:
    applog.info('initializing PCA9685')
    kit = ServoKit(channels=16)
    
  # init mqtt server connection
  hmqtt = Homie_MQTT(settings, turretCB)
  
  for i in range(0, len(settings.turrets)):
     turrets.append(Turret(settings.turrets[i], kit, applog))
     tur_locks.append(Lock())
                       
  settings.print()
  
  # fix debug levels
  if args['debug'] == None:
    debug_level = 3
  else:
    debug_level = args['debug']
    
  atexit.register(cleanup)
  # All we do now is loop over a 5 minute delay
  # and let the threads work.
  while True:
    time.sleep(5 * 60)
コード例 #5
0
def main():
  global settings, hmqtt, log,  env_home, mq_thr
  global mainwin,menu_fr,alarm_btn,voice_btn,laser_btn,login_btn,logoff_btn
  global menu_fr, panel_fr, center_img, pnl_middle, message
  global pnl_hdr, status_hdr, msg_hdr, content
  global device,saver_cvs,stroke_fill, screen_height, screen_width
  global font1,font2,font3,devFnt
  env_home = os.getenv('HOME')
  if sys.platform == 'darwin':
    isOSX = True
    print('Darwin not really supported')
  ap = argparse.ArgumentParser()
  ap.add_argument("-c", "--conf", required=True, type=str,
    help="path and name of the json configuration file")
  ap.add_argument("-s", "--syslog", action = 'store_true',
    default=False, help="use syslog")

  args = vars(ap.parse_args())
  
  # logging setup
  log = logging.getLogger('testbear')
  #applog.setLevel(args['log'])
  if args['syslog']:
    log.setLevel(logging.DEBUG)
    handler = logging.handlers.SysLogHandler(address = '/dev/log')
    # formatter for syslog (no date/time or appname. Just  msg, lux, luxavg
    formatter = logging.Formatter('%(name)s-%(levelname)-5s: %(message)-30s')
    handler.setFormatter(formatter)
    log.addHandler(handler)
  else:
    logging.basicConfig(level=logging.DEBUG,datefmt="%H:%M:%S",format='%(asctime)s %(levelname)-5s %(message)-40s')

  settings = Settings(args["conf"], 
                      log)
  settings.print()

  try:
    hmqtt = Homie_MQTT(settings, on_mqtt_msg)
  except:
    log.fail('failed mqtt setup')
    exit()
    
  tkroot = Tk()
  mainwin = Toplevel(tkroot)
  # new:
  #root.wait_visibility(saver_cvs)
  mainwin.wm_attributes("-topmost", True)
  mainwin.attributes('-fullscreen', True)    # required, else ghost window on top
  # old:
  #root.geometry('900x580')

  mainwin.protocol("WM_DELETE_WINDOW", do_quit)
  st = ttk.Style()
  st.theme_use('alt') # better than 'default', IMO
  st.configure("Menlo.TButton", font = ('Menlo', 16, 'bold'), 
    height=20, width=10)
  
  st = ttk.Style()
  st.configure("Menlo.TRadiobutton", font = ('Menlo', 12))
  
  st = ttk.Style()
  st.configure("MenloSm.TLabel", font = ('Menlo', 14))
  st = ttk.Style()
  st.configure("MenloMd.TLabel", font = ('Menlo', 16))
  st = ttk.Style()
  st.configure("MenloMd.TLabel", font = ('Menlo', 18))
  
  st = ttk.Style()
  st.configure("Menlo.TCheckbutton", font = ('Menlo', 16), 
    height=10, width=10)
    
  st = ttk.Style()
  st.configure("Menlo.TCombobox", font = ('Menlo', 16), 
    height=16, width=10)
  
  content = ttk.Frame(mainwin)
  menu_fr = ttk.Frame(content, width=100, height=580, borderwidth=5)
  menu_fr.pack(side=LEFT, expand=True)
  
  st_p = 4
  alarm_btn = ttk.Button(menu_fr, text ="Alarm", style='Menlo.TButton', 
      command=alarm_panel)
  alarm_btn['state'] = 'disabled'
  alarm_btn.grid(row=st_p + 2)
  voice_btn = ttk.Button(menu_fr, text = "Voice", style='Menlo.TButton',
      command=mycroft_panel)
  voice_btn.grid(row=st_p + 3)
  voice_btn['state'] = 'disabled'
  laser_btn = ttk.Button(menu_fr, text = "Lasers", style='Menlo.TButton',
      command=laser_panel)
  laser_btn.grid(row=st_p + 4)
  laser_btn['state'] = 'disabled'
  login_btn = ttk.Button(menu_fr, text = "Login", style='Menlo.TButton', 
      command = on_login)
  login_btn.grid(row=st_p + 5)
  logoff_btn = ttk.Button(menu_fr, text = "Logoff", style='Menlo.TButton',
      command = on_logoff)
  logoff_btn.grid(row=st_p + 6)
  logoff_btn['state'] = 'disabled'
  start_panel(True)

  # fill in the right side panel. 
  content.pack()
  
  # ----- Now the screen saver panel ---
  device= Toplevel(tkroot)
  
  # Tkinter Window Configurations
  #device.wait_visibility(saver_cvs)
  device.wm_attributes('-alpha',1)
  device.wm_attributes("-topmost", False)
  #device.overrideredirect(1)
  device.attributes('-fullscreen', True)
  device.attributes("-zoomed", True)
  #device.attributes("-toolwindow", 1)
  screen_width = device.winfo_screenwidth()
  screen_height = device.winfo_screenheight()
  # create canvas 
  saver_cvs = Canvas(device, background='black', borderwidth = 0)
  saver_cvs.create_rectangle(0, 0, screen_width, screen_height, fill = 'black')
  saver_cvs.pack(expand="yes",fill="both")
 
  
  font1 = font.Font(family=settings.font1, size=settings.font1sz[0])
  font2 = font.Font(family=settings.font2, size=settings.font2sz[0])
  font3 = font.Font(family=settings.font3, size=settings.font3sz[0])
  fnt = settings.deflt_font
  set_font(fnt)
  stroke_fill = settings.stroke_fill
  for seq in ['<Any-KeyPress>', '<Any-Button> ', '<Any-Motion>']:
    device.bind_all(seq, saver_closing)

  # arrange toplevel windows
  saver_running = False
  device.withdraw()
  mainwin.state('normal')
  log.info(f'starting mainloop fg: {mainwin.state()}, bg: {device.state()}')
  
  # set screensaver timer
  screen_timer_reset()
  
  # NOTE: mqtt messages seem to arrive just fine. Even though we
  # don't seem to accomodate them
  mainwin.mainloop()
  while True:
    time.sleep(10)