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
    

divyadabgar
Posts: 1
Joined: Thursday 28 June 2018 12:42
Target OS: OS X
Domoticz version:
Contact:

Re: Can't debug python plugin

Post by divyadabgar » Thursday 28 June 2018 12:52

hello,
You can launch a Python program through pdb by using pdb myscript.py or python -m pdb myscript.py.

There are a few commands you can then issue, which are documented on the pdb page.

Some useful ones to remember are:

b: set a breakpoint
c: continue debugging until you hit a breakpoint
s: step through the code
n: to go to next line of code
l: list source code for the current file (default: 11 lines including the line being executed)
u: navigate up a stack frame
d: navigate down a stack frame
p: to print the value of an expression in the current context
If you don't want to use a command line debugger, some IDEs like Pydev have a GUI debugger.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests