Python plugin with HTTP

Python and python framework

Moderator: leecollings

Post Reply
galinette
Posts: 68
Joined: Monday 11 December 2017 22:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Python plugin with HTTP

Post by galinette »

Dear all,

I am trying to write a plugin for a nice multichannel electrical consumption device (legrand 412000) which acts as a webserver, and provides real-time AC current measures over 5 channels in JSON format.

I started from the examples from the "Developing a Python plugin" wiki page, but none seem to work on the current Domoticz version. I always have the following message:
'onMessage' failed 'TypeError':'onMessage() takes 2 positional arguments but 4 were given'.
All examples and the documentation as well define onMessage like this:

Code: Select all

def onMessage(Connection, Data):
But it seems that Domoticz call it with 4 arguments. Where can I find documentation (posts about API change, etc...) about this?

Thanks
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin with HTTP

Post by Dnpwwo »

@galinette,

The onMessage interface changed some time ago, the wiki represents the new interface.

I would recommend running the current beta version and using the 2 parameter version although from memory there is an old version of the HTTP example in github history that takes 4 parameters if you really want to stick with 'stable'
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
galinette
Posts: 68
Joined: Monday 11 December 2017 22:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin with HTTP

Post by galinette »

Hi,

I thinks this goes the other way. The old interface has 2 parameters and the new one 4 parameters.
I am using the beta release (3.8789) and the API indeed has 4 parameters for onMessage.
So I think the wiki example is deprecated.

Now I managed to get the google HTTP request example working.

I have a new issue : my HTTP "stub" plugin works on any url (internet, local, ...) except the device I am trying to implement. The Domoticz plugin system crashes upon receiving the answer from the device webserver, and before the onMessage event is triggered. It seems that the plugin system has a problem parsing the HTTP reply.

I'll file a bug, is the forum the best way to report a bug?

Thanks
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin with HTTP

Post by Dnpwwo »

@galinette,

Reproducable crashes are easy to fix. If you post your plugin and the URL I can have a look at it.

As to the parameter thing, there is something wrong at your end somewhere. Are you building from source or downloading pre-built?

If you look at all the example plugins (https://github.com/domoticz/domoticz/tr ... s/examples) they have a definition of:

Code: Select all

def onMessage(Connection, Data):
    global _plugin
    _plugin.onMessage(Connection, Data)
and the Domoticz code that calls it is:

Code: Select all

	// Data is in a dictionary
	if (m_Data)
	{
		pParams = Py_BuildValue("OO", m_pConnection, m_Data);
		Callback(pParams);
		Py_XDECREF(m_Data);
	}
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest