margyle / decaf

Decaf: Does Every Coffee Action, Friend
26 stars 10 forks source link

This channel is already in use, continuing anyway #14

Closed jjok closed 5 years ago

jjok commented 5 years ago

I get this message when calling /relayControl.

/var/mugsy/decaf/models.py:56: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup(int(pinNumber), GPIO.OUT)

I think it's just a case of adding GPIO.cleanup() at the end of the function, so it's cleaned up for the next run.

jjok commented 5 years ago

Hmm... That doesn't seem to fix it. Not sure what to do... Has anyone else seen this issue? Is it just because I'm running in Docker? It happens when I call the endpoint, then stop and start the container, the hit the endpoint again.

margyle commented 5 years ago

I haven't installed the Docker version, will do so tonight and check it out. I would have also expected the GPIO.cleanup() to do the trick.

jjok commented 5 years ago

And you haven't seen that warning when running straight on, presumably, Raspbian?

margyle commented 5 years ago

I do not see the warning in the json response. I do see it after calling the endpoint and then calling the pin from the terminal. I added the cleanup call to each section of the loop and it went away on subsequent calls:

    `if (repeatValue > 1):
        for _ in itertools.repeat(None, repeatValue):
            GPIO.output(int(pinNumber), GPIO.LOW)
            time.sleep(timeOn)
            GPIO.output(int(pinNumber), GPIO.HIGH)
            time.sleep(repeatDelay)
            GPIO.cleanup()
    else:
            GPIO.output(int(pinNumber), GPIO.LOW)
            time.sleep(timeOn)
            GPIO.output(int(pinNumber), GPIO.HIGH)
            GPIO.cleanup()`

Where did you add the GPIO.cleanup()?

jjok commented 5 years ago

Hmm... I added it at the end. Right before the function returns.

if (repeatValue > 1):
        for _ in itertools.repeat(None, repeatValue):
            GPIO.output(int(pinNumber), GPIO.LOW)
            time.sleep(timeOn)
            GPIO.output(int(pinNumber), GPIO.HIGH)
            time.sleep(repeatDelay)
    else:
            GPIO.output(int(pinNumber), GPIO.LOW)
            time.sleep(timeOn)
            GPIO.output(int(pinNumber), GPIO.HIGH)
GPIO.cleanup()
margyle commented 5 years ago

Just tested it your way and there was no warning. Probably something with the Docker build but I don't know enough to say...

Im running:

Description: Raspbian GNU/Linux 9.6 (stretch) Release: 9.6 Codename: stretch

jjok commented 5 years ago

I wonder it was whitespace-related? I was using vi and having trouble wrangling the tabs.

margyle commented 5 years ago

Maybe, but Python is pretty good about breaking and erroring out on any tab issues. I'll install Docker and see what happens.

margyle commented 5 years ago

Having some issues with the Docker set up, doesn't appear to be using the mysql config. I know you mentioned something about that earlier. Will resolve but will be later tonight or tomo.

jjok commented 5 years ago

Did you run the commands in the same order as the README? The whole codebase (./) gets copied into the image at build time, so you have to have edited the config file before then.

Oh. Hang on. That's my problem, isn't it? :man_facepalming: That's why I wasn't seeing the change having any effect.

margyle commented 5 years ago

Ahhhhhh! That makes sense! Do I have to do anything special to rebuild? Like remove it first? Or does Docker know to just overwrite?

jjok commented 5 years ago

Nope. Just run the build command again. It should have cached all the steps that haven't changed since the last build, so it should just add the files again and do the last few bits, rather than installing everything as it did the first time. It should take seconds, rather than tens of minutes.

jjok commented 5 years ago

Surprisingly, my original fix works when I actually test it properly. I'll open a PR in a sec.

margyle commented 5 years ago

Sweet, thanks!