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

Alexa can't find device when running from service. #67

Closed
6 tasks done
jakewtaylor opened this issue Oct 9, 2018 · 9 comments
Closed
6 tasks done

Alexa can't find device when running from service. #67

jakewtaylor opened this issue Oct 9, 2018 · 9 comments

Comments

@jakewtaylor
Copy link

jakewtaylor commented Oct 9, 2018

  • Operating system and version: Raspbian (unsure which version, latest)
  • Python version: 3.7
  • Fauxmo version (fauxmo --version): 0.4.7
  • Echo device type (e.g. Echo, Echo Plus, Dot): Echo Dot
  • Echo Firmware Version: Unsure - assuming not relevant

My Issue

I've got FauxMo working just fine - excellent work, by the way - but only when I run the script from the command line myself, Alexa can't find the device when the script starts from a service (assuming it is starting). My knowledge (or lack thereof) on services are probably the problem here.

I have my fauxmo.service file like so:

[Unit]
Description=Fauxmo
After=network.target
Wants=network.target

[Service]
Type=simple
WorkingDirectory=/home/pi/fauxmo
# Fix the paths below:
ExecStart=/home/pi/fauxmo/bin/fauxmo -c /home/pi/app/config.json -vv
Restart=on-failure
User=fauxmo

[Install]
WantedBy=multi-user.target

Then I ran sudo systemctl enable fauxmo.service and sudo systemctl start fauxmo.service, like the docs says, and no errors appear to be happening, however Alexa just doesn't detect anything.

The output of sudo systemctl status fauxmo.service shows the following:

● fauxmo.service - Fauxmo
   Loaded: loaded (/etc/systemd/system/fauxmo.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-09 20:27:29 UTC; 2s ago
 Main PID: 854 (fauxmo)
   CGroup: /system.slice/fauxmo.service
           └─854 /home/pi/fauxmo/bin/python3.7 /home/pi/fauxmo/bin/fauxmo -c /home/pi/app/config.json -vv

Oct 09 20:27:29 raspberrypi systemd[1]: Started Fauxmo.

Which looks good to me - the only thing that I'm not sure is right is that the time it started always says 2 or 3s ago, which should be the last time the the service was (re)started, surely?

Manually running the command that the status shows:

/home/pi/fauxmo/bin/python3.7 /home/pi/fauxmo/bin/fauxmo -c /home/pi/app/config.json -vv

Starts the script just fine and Alexa can find it.

I'm currently sort-of getting round this by using nohup, but that doesn't work through reboots.

Not really sure where to go from here, any ideas?

Thanks for any help!

My config can be found in my repo, here.

WHYT

Covered above.


Please make sure you've taken these steps before submitting a new issue:

  • Try to reproduce the issue with Fauxmo installed in a
    venv
  • Ensure you're running a supported version of Python
    • Requires Python >= 3.2 for Fauxmo < 0.3.0
    • Requires Python >= 3.4.4 for Fauxmo >= 0.3.0
    • Requires Python >= 3.6.0 for Fauxmo >= 0.4.0
  • Run Fauxmo in debug mode (-vvv) and include relevant output
  • Include your Fauxmo config.json
  • Search the existing (including closed) issues
  • Please use codeblocks around your debug output and config
@n8henrie
Copy link
Owner

Huh, haven't run into this.

Can you increase the verbosity to -vvv in your systemd service file, then take a look at sudo journalctl -xf -b -u fauxmo.service.

@jakewtaylor
Copy link
Author

Thanks for the response. I'll give this a go as soon as I get a chance, probably over the weekend.

@jakewtaylor
Copy link
Author

jakewtaylor commented Oct 14, 2018

Okay, so I increased the verbosity to -vvv, then ran sudo journalctl -xf -b -u fauxmo.service`, which gave me this output:

Oct 14 16:00:19 raspberrypi systemd[1]: Started Fauxmo.
-- Subject: Unit fauxmo.service has finished start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit fauxmo.service has finished starting up.
-- 
-- The start-up result is done.
Oct 14 16:00:22 raspberrypi fauxmo[675]: 2018-10-14 16:00:22 fauxmo:37       INFO     Fauxmo v0.4.7
Oct 14 16:00:22 raspberrypi fauxmo[675]: 2018-10-14 16:00:22 fauxmo:38       DEBUG    3.7.0 (default, Oct  7 2018, 15:47:50)
Oct 14 16:00:22 raspberrypi fauxmo[675]: [GCC 6.3.0 20170516]
Oct 14 16:00:22 raspberrypi fauxmo[675]: 2018-10-14 16:00:22 fauxmo:24       DEBUG    Attempting to get IP address automatically
Oct 14 16:00:22 raspberrypi fauxmo[675]: 2018-10-14 16:00:22 fauxmo:40       DEBUG    Using IP address: 192.168.1.239
Oct 14 16:00:22 raspberrypi fauxmo[675]: 2018-10-14 16:00:22 fauxmo:100      DEBUG    plugin_vars: {}
Oct 14 16:00:22 raspberrypi fauxmo[675]: 2018-10-14 16:00:22 fauxmo:103      DEBUG    device config: {'name': 'Lamp', 'port': 12340, 'channel': 8}
Oct 14 16:00:22 raspberrypi fauxmo[675]: Traceback (most recent call last):
Oct 14 16:00:22 raspberrypi fauxmo[675]:   File "/home/pi/fauxmo/bin/fauxmo", line 11, in <module>
Oct 14 16:00:22 raspberrypi fauxmo[675]:     sys.exit(cli())
Oct 14 16:00:22 raspberrypi fauxmo[675]:   File "/home/pi/fauxmo/lib/python3.7/site-packages/fauxmo/cli.py", line 30, in cli
Oct 14 16:00:22 raspberrypi fauxmo[675]:     main(config_path_str=args.config, verbosity=verbosity)
Oct 14 16:00:22 raspberrypi fauxmo[675]:   File "/home/pi/fauxmo/lib/python3.7/site-packages/fauxmo/fauxmo.py", line 109, in main
Oct 14 16:00:22 raspberrypi fauxmo[675]:     plugin = PluginClass(**plugin_vars, **device)
Oct 14 16:00:22 raspberrypi fauxmo[675]:   File "/home/pi/app/RelayPlugin.py", line 21, in __init__
Oct 14 16:00:22 raspberrypi fauxmo[675]:     gpio.setup(self.pin, gpio.OUT)
Oct 14 16:00:22 raspberrypi fauxmo[675]: RuntimeError: No access to /dev/mem.  Try running as root!
Oct 14 16:00:23 raspberrypi systemd[1]: fauxmo.service: Main process exited, code=exited, status=1/FAILURE
Oct 14 16:00:23 raspberrypi systemd[1]: fauxmo.service: Unit entered failed state.
Oct 14 16:00:23 raspberrypi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
Oct 14 16:00:23 raspberrypi systemd[1]: fauxmo.service: Service hold-off time over, scheduling restart.
Oct 14 16:00:23 raspberrypi systemd[1]: Stopped Fauxmo.
-- Subject: Unit fauxmo.service has finished shutting down
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit fauxmo.service has finished shutting down.

I'm guessing I've got some permissions problems, recreating the user didn't work.

I made the user using the command from the docs: sudo useradd -r -s /bin/false fauxmo.

@n8henrie
Copy link
Owner

n8henrie commented Oct 16, 2018

Manually running the command that the status shows:

/home/pi/fauxmo/bin/python3.7 /home/pi/fauxmo/bin/fauxmo -c /home/pi/app/config.json -vv

Starts the script just fine and Alexa can find it.

What user are you running this command as?

Does it work if you do this?

$ sudo -u fauxmo /home/pi/fauxmo/bin/python3.7 /home/pi/fauxmo/bin/fauxmo -c /home/pi/app/config.json -vv`

If not, you're probably correct in that you're missing some permissions for the fauxmo user -- perhaps membership in the gpio group, which should allow rootless access to the GPIO pins by way of /dev/gpiomem.

Relevant reading:

Let me know if that fixes it.

@n8henrie
Copy link
Owner

I haven't gotten a reply, so I'm closing this issue as dead. Please feel free to let me know if I should re-open.

@jakewtaylor
Copy link
Author

jakewtaylor commented Nov 29, 2018

Hi, I haven't resolved the issue but I also haven't had time to investigate it further. I'm still getting round it just fine using nohup, and manually restarting the service if my RPi restarts for whatever reason. Not ideal but that happens so infrequently its not a problem.

I'll eventually try out your suggestions and get back to you here.

Thanks!

@jakewtaylor
Copy link
Author

Hi, I've just tried running this command, as you suggested:

sudo -u fauxmo /home/pi/fauxmo/bin/python3.7 /home/pi/fauxmo/bin/fauxmo -c /home/pi/app/config.json -vv

This is the output I got:

2019-03-06 22:39:23 fauxmo:37       INFO     Fauxmo v0.4.7
Traceback (most recent call last):
  File "/home/pi/fauxmo/bin/fauxmo", line 11, in <module>
    sys.exit(cli())
  File "/home/pi/fauxmo/lib/python3.7/site-packages/fauxmo/cli.py", line 30, in cli
    main(config_path_str=args.config, verbosity=verbosity)
  File "/home/pi/fauxmo/lib/python3.7/site-packages/fauxmo/fauxmo.py", line 109, in main
    plugin = PluginClass(**plugin_vars, **device)
  File "/home/pi/app/RelayPlugin.py", line 21, in __init__
    gpio.setup(self.pin, gpio.OUT)
RuntimeError: No access to /dev/mem.  Try running as root!

Looks like a permissions error with /dev/mem.

@n8henrie
Copy link
Owner

n8henrie commented Mar 28, 2019

Did you see this:

If not, you're probably correct in that you're missing some permissions for the fauxmo user -- perhaps membership in the gpio group, which should allow rootless access to the GPIO pins by way of /dev/gpiomem.

sudo usermod -a -G gpio fauxmo -- but make sure you know what this command does first!

EDIT: For testing purposes, is there a way you can run RelayPlugin.py as your fauxmo user? Something like sudo -u fauxmo python RelayPlugin.py? That will leave the fauxmo code out of the way and let you focus on getting your permissions issues sorted out.

@jakewtaylor
Copy link
Author

Just got fauxmo setup on another project, hit the same issue, and running sudo usermod -aG gpio fauxmo is just what I needed to get it working! Thanks :)

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

2 participants