2017-06-06, 23:01
(2017-06-06, 22:51)Roman_V_M Wrote:(2017-06-06, 21:09)ablues10 Wrote:(2017-06-06, 20:35)el_Paraguayo Wrote: The libreelec forum suggests the append line should be:
Have you tried that?Code:sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.ImportError'>
Error Contents: dynamic module does not define init function (initGPIO)
Traceback (most recent call last):
File "/storage/.kodi/addons/script.relay/addon.py", line 7, in <module>
import RPi.GPIO as GPIO
ImportError: dynamic module does not define init function (initGPIO)
-->End of Python script error report<--
That was using theCode:sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
This error means that a compiled dynamic library cannot be initialized as a Python module. It looks as if the binary GPIO module (_GPIO.so) is either incorrectly compiled or for a wrong platform. Make sure that you have installed this module from the official LibreELEC repo via Kodi Addon Manager. This should guarantee that you have correct binary components installed.
And for Kodi module addons you don't need to manipulate sys.path. Just add the necessary module addon to the requires section of your addon.xml and it will be added to sys.path of your addon automatically.
BTW, just out of curiosity I've installed RPi tools addon and imported it with no problems:
addon.xml (excerpt):
main.py:Code:<requires>
<import addon="xbmc.python" version="2.19.0"/>
<import addon="virtual.rpi-tools" />
</requires>
Result:Code:from pprint import pformat
import xbmc
import RPi.GPIO as GPIO
xbmc.log(pformat(dir(GPIO)), xbmc.LOGNOTICE)
Code:23:33:49.107 T:1240986528 NOTICE: ['BCM',
'BOARD',
'BOTH',
'FALLING',
'HARD_PWM',
'HIGH',
'I2C',
'IN',
'LOW',
'OUT',
'PUD_DOWN',
'PUD_OFF',
'PUD_UP',
'PWM',
'RISING',
'RPI_INFO',
'RPI_REVISION',
'SERIAL',
'SPI',
'UNKNOWN',
'VERSION',
'__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'__path__',
'add_event_callback',
'add_event_detect',
'cleanup',
'event_detected',
'getmode',
'gpio_function',
'input',
'output',
'remove_event_detect',
'setmode',
'setup',
'setwarnings',
'wait_for_edge']
Here is my new error:
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.SyntaxError'>
Error Contents: ('invalid syntax', ('/storage/.kodi/addons/script.relay/addon.py', 6, 1, '<requires>\n'))
SyntaxError: ('invalid syntax', ('/storage/.kodi/addons/script.relay/addon.py', 6, 1, '<requires>\n'))
-->End of Python script error report<--
and code:
Code:
import xbmcaddon
#import xbmcgui
import os
import xbmc
import sys
<requires>
<import addon="xbmc.python" version="2.19.0"/>
<import addon="virtual.rpi-tools" /></requires>
# Grab a GPIO adapter for the current platform.
gpio = GPIO.get_platform_gpio
GPIO.setup(9, GPIO.OUT)
addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')
line1 = "Turned on/off a relay"
line2 = "Version: " + addon.getAddonInfo('version')
os.system("sh /storage/.kodi/addons/relay-addon-kodi-master/relay.sh")
xbmc.executebuiltin('Notification(Relay Addon, The relay was turned on/off,5000,//storage/.kodi/addons/script.relay.master/icon.png)')
#xbmcgui.Dialog().ok(addonname, line1, line2)
I did install Raspberry pi tools from the addon library located in Kodi