50ButtonsEach / fliclib-linux-hci

Flic SDK for Linux
306 stars 53 forks source link

Python fliclib.ScanWizard() not receiving events from MacOS FlicServiceBeta #31

Closed leanto closed 7 years ago

leanto commented 8 years ago

I'm running the MacOS FlicServiceBeta v0.0.2 from 31 May, 2016 (the latest) like this:

$ /Applications/FlicServiceBeta.app/Contents/MacOS/FlicServiceBeta --interface localhost
2016-08-20 11:13:27.740 FlicServiceBeta[63756:2194025] Flic service started on port 5551, interface: localhost

My python program is:

#!/usr/bin/env python3
#
# Test to get flic presses.
#

import fliclib
import logging

def main():
  rootLogger = logging.getLogger()
  consoleHandler = logging.StreamHandler()
  rootLogger.setLevel(logging.DEBUG)
  rootLogger.addHandler(consoleHandler)

  client = fliclib.FlicClient("localhost")
  wizard = fliclib.ScanWizard()

  def wiz_on_found_private_button(scan_wizard):
    print('shittlesticks, a private button was found')

  def wiz_on_found_public_button(scan_wizard, bd_addr, name):
    print('found public button: {} ({})'.format(bd_addr, name))

  def wiz_on_button_connected(scan_wizard, bd_addr, name):
    print('found public button: {} ({})'.format(bd_addr, name))

  def wiz_on_completed(scan_wizard, result, bd_addr, name):
    print('complete: {} {} ({})'.format(result, bd_addr, name))
    client.close()

  wizard.on_found_private_button = wiz_on_found_private_button
  wizard.on_found_public_button = wiz_on_found_public_button
  wizard.on_button_connected = wiz_on_button_connected
  wizard.on_completed = wiz_on_completed
  print('adding wizard')
  client.add_scan_wizard(wizard)
  print('starting event loop')
  client.handle_events()

if __name__ == '__main__':
  main()

I've also modified fliclib to add some logging in _handle_one_event:

  def _handle_one_event(self):
    self._logger.debug('waiting for event')
    if len(self._timers.queue) > 0:
      current_timer = self._timers.queue[0]
    [...]
    self._logger.debug('read event')
    self._dispatch_event(data)
    return True

When I run the program, I get:

adding wizard
starting event loop
waiting for event

And in the FlicServiceBeta output I see:

2016-08-20 11:13:57.439 FlicServiceBeta[63756:2194554] Accepted client ::1:49243

And that's it, regardless of how many times I press the button.

When I run scan_wizard.py, that works fine but it doesn't use the ScanWizard object provided by the library.

Thoughts?

Emill commented 8 years ago

The scan wizard was introduced after the mac daemon was released, so it's not implemented there yet. However we have implemented it a few days ago on mac and are just doing some final tests right now and will release it soon.

Den 20 aug. 2016 11:35 fm skrev "leanto" notifications@github.com:

I'm running the MacOS FlicServiceBeta v0.0.2 from 31 May, 2016 (the latest) like this:

$ /Applications/FlicServiceBeta.app/Contents/MacOS/FlicServiceBeta --interface localhost 2016-08-20 11:13:27.740 FlicServiceBeta[63756:2194025] Flic service started on port 5551, interface: localhost

My python program is:

!/usr/bin/env python3## Test to get flic presses.

import fliclibimport logging def main(): rootLogger = logging.getLogger() consoleHandler = logging.StreamHandler() rootLogger.setLevel(logging.DEBUG) rootLogger.addHandler(consoleHandler)

client = fliclib.FlicClient("localhost") wizard = fliclib.ScanWizard()

def wiz_on_found_private_button(scan_wizard): print('shittlesticks, a private button was found')

def wiz_on_found_public_button(scan_wizard, bd_addr, name): print('found public button: {} ({})'.format(bd_addr, name))

def wiz_on_button_connected(scan_wizard, bd_addr, name): print('found public button: {} ({})'.format(bd_addr, name))

def wiz_on_completed(scan_wizard, result, bd_addr, name): print('complete: {} {} ({})'.format(result, bd_addr, name)) client.close()

wizard.on_found_private_button = wiz_on_found_private_button wizard.on_found_public_button = wiz_on_found_public_button wizard.on_button_connected = wiz_on_button_connected wizard.on_completed = wiz_on_completed print('adding wizard') client.add_scan_wizard(wizard) print('starting event loop') client.handle_events() if name == 'main': main()

I've also modified fliclib to add some logging in _handle_one_event:

def _handle_one_event(self): self._logger.debug('waiting for event') if len(self._timers.queue) > 0: current_timer = self._timers.queue[0] [...] self._logger.debug('read event') self._dispatch_event(data) return True

When I run the program, I get:

adding wizard starting event loop waiting for event

And in the FlicServiceBeta output I see:

2016-08-20 11:13:57.439 FlicServiceBeta[63756:2194554] Accepted client ::1:49243

And that's it, regardless of how many times I press the button.

When I run scan_wizard.py, that works fine but it doesn't use the ScanWizard object provided by the library.

Thoughts?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/50ButtonsEach/fliclib-linux-hci/issues/31, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlXakJm8gZYPX2pHvBvB4jPZ1CWNMBbks5qhsphgaJpZM4JpChC .

leanto commented 8 years ago

Thanks for the quick response! Should I have expected to receive some sort of error, though? I don't see anything in the docs, so it seems that unknown commands are dropped silently. Is that correct?

Emill commented 8 years ago

Yes unfortunately. Sorry for the inconvenience...

Den 20 aug. 2016 1:03 em skrev "leanto" notifications@github.com:

Thanks for the quick response! Should I have expected to receive some sort of error, though? I don't see anything in the docs https://github.com/50ButtonsEach/fliclib-linux-hci/blob/master/ProtocolDocumentation.md, so it seems that unknow commands are dropped silently. Is that correct?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/50ButtonsEach/fliclib-linux-hci/issues/31#issuecomment-241193426, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlXajBXfzl0Ij1I24IVZEMf2gPQAe5lks5qht8agaJpZM4JpChC .

Emill commented 8 years ago

Try now, we've just uploaded a new mac program

AntonMeier commented 8 years ago

Release 0.0.3 of flic-service-osx fixes this.