Can't debug python plugin

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!
Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
hboisselle
Posts: 1
Joined: Friday 08 June 2018 18:08
Target OS: Raspberry Pi
Domoticz version:
Contact:

Can't debug python plugin

Post by hboisselle » Friday 08 June 2018 18:24

Hello there,

I've been trying to debug a python plugin without success for quite a while now, I was wondering if you could help me a bit. I'm not sure if this is a bug or just me not understanding how to properly debug.

First and foremost, I am running Domoticz 3.9483 on a Lubuntu 18.04 VM on OSX. I'm using python 3.6.5 . I'm just trying to set a breakpoint and attach to rpdb through telnet. When I add the hardware on Domoticz for the following plugin, the log never shows any of the messages I've put into the callbacks. Rpdb doesn't start either.

Do I have to compile Domoticz in debug to make this work? I've set the -debug flag in domoticz.sh.

Your help is appreciated!

Code: Select all

# Basic Python Plugin Example
#
# Author: GizMoCuz
#
"""
<plugin key="BasePlug" name="Basic Python Plugin Example" author="gizmocuz" version="1.0.0" wikilink="http://www.domoticz.com/wiki/plugins/plugin.html" externallink="https://www.google.com/">
    <description>
        <h2>Plugin Title</h2><br/>
        Overview...
        <h3>Features</h3>
        <ul style="list-style-type:square">
            <li>Feature one...</li>
            <li>Feature two...</li>
        </ul>
        <h3>Devices</h3>
        <ul style="list-style-type:square">
            <li>Device Type - What it does...</li>
        </ul>
        <h3>Configuration</h3>
        Configuration options...
    </description>
    <params>
    </params>
</plugin>
"""
import Domoticz

class BasePlugin:
    enabled = False
    def __init__(self):
        #self.var = 123
        return

    def onStart(self):
        Domoticz.Log("onStart called")
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onStop(self):
        Domoticz.Log("onStop called")
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onConnect(self, Connection, Status, Description):
        Domoticz.Log("onConnect called")
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onMessage(self, Connection, Data):
        Domoticz.Log("onMessage called")
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onCommand(self, Unit, Command, Level, Hue):
        Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile):
        Domoticz.Log("Notification: " + Name + "," + Subject + "," + Text + "," + Status + "," + str(Priority) + "," + Sound + "," + ImageFile)
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onDisconnect(self, Connection):
        Domoticz.Log("onDisconnect called")
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

    def onHeartbeat(self):
        Domoticz.Log("onHeartbeat called")
        Domoticz.Debugging(1)
        Domoticz.Log("Debugger started!")
        import rpdb
        rpdb.set_trace()

global _plugin
_plugin = BasePlugin()

def onStart():
    global _plugin
    _plugin.onStart()

def onStop():
    global _plugin
    _plugin.onStop()

def onConnect(Connection, Status, Description):
    global _plugin
    _plugin.onConnect(Connection, Status, Description)

def onMessage(Connection, Data):
    global _plugin
    _plugin.onMessage(Connection, Data)

def onCommand(Unit, Command, Level, Hue):
    global _plugin
    _plugin.onCommand(Unit, Command, Level, Hue)

def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
    global _plugin
    _plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)

def onDisconnect(Connection):
    global _plugin
    _plugin.onDisconnect(Connection)

def onHeartbeat():
    global _plugin
    _plugin.onHeartbeat()

    # Generic helper functions
def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return
    

xiaoyao9184
Posts: 1
Joined: Sunday 25 November 2018 7:28
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Can't debug python plugin

Post by xiaoyao9184 » Tuesday 04 December 2018 11:30

same as me.

and i use windows and raspberry

I used two platforms for debugging, and the plugin like this:

Code: Select all

def onStart(self):
        # Test
        Domoticz.Log("Debugger started, use 'telnet 0.0.0.0 4444' to connect")
        import rpdb
        rpdb.set_trace()

        debug = 0
        if (Parameters["Mode3"] == "Debug"):
            Domoticz.Debugging(1)
            debug = 1
windows platform log is:

Code: Select all

2018-12-04 17:28:01.598 [3dc8] Status: (Plug) Started.
2018-12-04 17:28:01.598 [3dc8] Status: EventSystem: reset all events...
2018-12-04 17:28:01.599 [3dc8] Status: EventSystem: reset all device statuses...
2018-12-04 17:28:01.610 [3dc8] Status: Python EventSystem: Initalizing event module.
2018-12-04 17:28:01.611 [22e0] Status: EventSystem: Started
2018-12-04 17:28:01.611 [3b68] Status: EventSystem: Queue thread started...
2018-12-04 17:28:01.914 [1500] Status: PluginSystem: Entering work loop.
2018-12-04 17:28:02.125 [1500] (Plug) Debugger started, use 'telnet 0.0.0.0 4444' to connect
2018-12-04 17:28:02.125 [461c] Status: (Plug) Entering work loop.
2018-12-04 17:28:02.125 [1500] Status: (Plug) Initialized version 1.0.0, author 'xiaoyao9184'
2018-12-04 17:28:02.127 [1500] Error: (Plug) 'onStart' failed 'AttributeError'.
2018-12-04 17:28:02.127 [1500] Error: (Plug) ----> Line 291 in 'D:\Program\TOOL\Domoticz\plugins\MiioChuangmiPlug\plugin.py'
2018-12-04 17:28:02.127 [1500] Error: (Plug) ----> Line 82 in 'D:\Program\TOOL\Domoticz\plugins\MiioChuangmiPlug\plugin.py'
2018-12-04 17:28:02.127 [1500] Error: (Plug) ----> Line 112 in 'D:\IDE\Python37-32\lib\site-packages\rpdb\__init__.py'
2018-12-04 17:28:02.128 [1500] Error: (Plug) ----> Line 54 in 'D:\IDE\Python37-32\lib\site-packages\rpdb\__init__.py'
linux platform just running but no output any log

Code: Select all

2018-12-04 17:19:17.758 [6ffff430] Status: (Plug) Started.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests