WebIOPi - name 'GPIO' is not defined


#1

I installed Cayenne seemingly without issue, and I was able to set up a BMP180 successfully on my RPi 3 Model B.

However, when I tried to access GPIO-connected devices, it failed and I found this in /var/log/webiopi:

WebIOPi - ERROR - Error while adding device sIMpop3KqMMuyJ5F(MotionSensor) : name ‘GPIO’ is not defined

What did I miss? gpio works from the command line. I am on Jessie, debian_version 8.0, and I now have both python2 and python3 installed now. Here is output of uname -a:
Linux mypi 4.9.16-v7+ #978 SMP Sat Mar 18 13:59:01 GMT 2017 armv7l GNU/Linux

Please let me know if what else I should check. Thanks!


#2

Do you have GPIO Library installed?


#3

My Python2 scripts still work. But I see that WebIOPi uses Python3.4. I tried the following and it appears to work:

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import RPi.GPIO as GPIO

Is this the library that is required? Or is there another? Thanks!


#4

I think this is the required. Is it working?


#5

Yes, I can run a script that shows activity from a PIR sensor, code below:

# External module imports

import RPi.GPIO as GPIO
import time

# Pin Definitons:

butPin = 6 # Broadcom pin 17 (P1 pin 11)

# Pin Setup:

GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(butPin, GPIO.IN) # PIR sensor pin set as input w/ pull-up

while True:
if GPIO.input(butPin): # false = no motion
print (“motion!”)
else:
print (“nothing.”)
time.sleep(1)

The local WebIOPi web service can’t access the GPIO. How does Cayenne or WebIOPi implement this? Are there other log outputs? Thanks again!


#6

Hi @bryanherger, Cayenne’s Raspberry Pi interface is built on webiopi (we hired its creator!), but it’s a modified version and I’m not sure if webiopi will behave the way it did before with Cayenne installed. Certainly I can grab him to ask.

Am I misunderstanding your question though? Do you have a problem with Cayenne, or is it just that webiopi isn’t behaving the same as it was before after you installed Cayenne?


#7

Hi, I didn’t have WebIOPi installed before Cayenne, but I had installed some libraries such as RPi.GPIO beforehand in order to run Python scripts like the example I pasted.

I ran the Cayenne web installer to install Cayenne and WebIOPi. I don’t think I had Python3.4 on my Pi previously, so perhaps there are version conflicts, missing paths etc. but since the only message I’ve found so far is the one line I found in /var/log/webiopi indicating GPIO is not found, I am not sure where to look to trace this issue. I don’t see anything helpful in syslog or messages, for instance. Thanks!


#8

I’m sorry, I was asking if you were seeing any negative/broken behavior with the Cayenne product, or just curious about the error message? I’ll tag @eptak here who should be able to speak to the error message more specifically.


#9

The Cayenne web interface works with my BMP180 but not with GPIO digital sensors - I’m testing with a PIR now.

I ran webiopi in foreground with “sudo webiopi -l /tmp/webiopi.log -d 8000” and found a stack trace. I ran the following in Python3.4 and got closer to the issue:

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import _webiopi.GPIO as GPIO
Traceback (most recent call last):
File “”, line 1, in
_webiopi.GPIO.SetupException: This module can only be run on a Raspberry Pi!

I ran strings on GPIO.cpython-34m.so and found the exception there, so I assume that is where it is thrown. Is the source for this library available? Has it been tested on an Element14 Raspberry Pi 3B? Thanks!


#10

I think I see the issue now, I just wanted to test and reproduce on my own, and I can get the same error as you on the 4.9 kernel.

While we’ve tested on all models of Pi, Raspbian is still on 4.4 and it doesn’t look like we’re working properly with 4.9 yet. Since it looks like Raspbian will be moving in this direction soon in the official release, it’s something we’re going to have to tackle fairly soon.

Until then it looks like you’ll need to revert to 4.4 if you want to use the Cayenne Agent to communicate with our platform. An alternate option would be to add the Pi via our MQTT API and interact with it that way. Though I haven’t tested that explicitly on 4.9, I imagine it would work.


#11

OK, I will look at all of these options. I have a second Pi that is on Wheezy so I’ll upgrade that to Jessie with kernel v4.4 rather than try to downgrade my Pi3. I was just looking for a quick setup to test Cayenne - I’ll look at the MQTT API as well, since at least one of these boards on my desk is based on nRF52832 using mbed ARM platform so it will need a custom interface. Thanks again!


#12

No problem. Hopefully we’ll have an update out soon and then you’ll have a third option of remaining on 4.9. Whenever that happens, I’ll be sure to update this thread.

Now that we’re aware of it, that’s half the battle :slight_smile:


#13

Hi @bryanherger ,

Cayenne and WebIOPi are not using regular RPi.GPIO module to access GPIO, but a custom one.
Looks we hit a limitation following Rasbian upgrade we need to look onto.
In the meantime, as @rsiegel say, I suggest you to use our vanilla MQTT API if you have programming skills.
We have Python, Node.JS, C and many other libraries available.

Best.