Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Timeout #8

Open
garphi opened this issue Feb 26, 2015 · 0 comments
Open

Prevent Timeout #8

garphi opened this issue Feb 26, 2015 · 0 comments

Comments

@garphi
Copy link

garphi commented Feb 26, 2015

Hi,
thank you for this great lib. It works great, but if you leave the myo alone, it will automatically disconnect and never will come back again.
Myo Firmware Version: 1.1.755.2
Therefore I decided to modify your lib.

In the myo_raw.py I've replaced in function Main (line 463):

        if m.run(1) is None:
          print("Connection lost, try to reconnect")
          m.connect()
        else:

...and changed function run (line 194) to:

def run(self, timeout=None):
    return self.bt.recv_packet(timeout) 

In the classify_myo.py I've replaced in function Main (line 48):

ltime = time.time() #Set initial lasttime for further timeout
timeout = 1 #Timeout in seconds

try:
    while True:
      if time.time() > (ltime + timeout):
        print("Connection lost, try to reconnect")
        m.connect()
        ltime = time.time() #Set lasttime for further timeout
      else:
        ltime = time.time() #Set lasttime for further timeout
        m.run()

The same for the function main in myo.py (line 113)

ltime = time.time() #Set initial lasttime for further timeout
timeout = 1 #Timeout in seconds

while True:
  if time.time() > (ltime + timeout):
    print("Connection lost, try to reconnect")
    m.connect()
    ltime = time.time() #Set lasttime for further timeout
  else:
    ltime = time.time() #Set lasttime for further timeout
    m.run()

With this modifications myo will reconnect after a few seconds.
Don't know how to uploads Commits.

Best regards
garphi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant