Page 1 of 1

Python plugin: updating a device, Domoticz crashes

Posted: Monday 29 May 2023 15:41
by psubiaco
Hi,
Since many months when my python plugin (using the legacy framework) try to update a device, often it crashes Domoticz.

For example, having an incremental counter (used as a rain meter), if the python plugin run

Code: Select all

Devices[Unit].Update(TypeName='Counter Incremental', nValue=0, sValue='276421', Description='ID=ff37.2,IN_COUNTER,', Options={'ValueQuantity': 'Pluviometro', 'ValueUnits': 'mm'})
I get the following errors:

Code: Select all

2023-05-29 15:05:35.101  Error: GetJSonDevices: exception occurred : 'stoll'
2023-05-29 15:05:35.104  Error: Domoticz(pid:17760, tid:17793('EventSystemQueu')) received fatal signal 6 (Aborted)
2023-05-29 15:05:35.104  Error: siginfo address=0x4560, address=(nil)
2023-05-29 15:05:35.115  Error: GetJSonDevices: exception occurred : 'stoll'
2023-05-29 15:05:38.367  Error: Did not find stack frame for thread (LWP 17793)), printing full gdb output:
With other device types I fixed by removing bad options items that were not suitable for that kind of devices (for example, if I have a incremental counter port that want to convert to a digital input port, I have to remove the options relative to the incremental counter device).

In the past, 1 year ago, there was not any trouble even specifing a bad options, Domoticz never crashed.
Hoping that @Dnpwwo or someone else help me finding the best way to avoid crashes.
Thanks a lot.
Paolo

Re: Python plugin: updating a device, Domoticz crashes

Posted: Monday 29 May 2023 22:40
by waltervl
What if you skip the description update part? As this is not common practice the plugin framework is perhaps not anticipating this enough?

Re: Python plugin: updating a device, Domoticz crashes

Posted: Monday 29 May 2023 23:29
by psubiaco
waltervl wrote: Monday 29 May 2023 22:40 What if you skip the description update part? As this is not common practice the plugin framework is perhaps not anticipating this enough?
For Domoticz, the description field is just a silly useless text, while for my plugin the description field is the way that user can configure hardware (digital or analog input, counter, dimmer, ...) so I have to update the description field.
I suppose the problem is on updating Options dictionary (in this case Options is updated with the same content as before).
Unfortunally I cannot say from which version the problem started happening.
I'll try to investigate better on the problem, focusing on Options dict

Re: Python plugin: updating a device, Domoticz crashes

Posted: Tuesday 30 May 2023 0:37
by waltervl
Stoll is a function to convert strings into long integers.
So the total Json string including nvalue and sValue gets perhaps messed up by incorrect values in the description or other part of the Json.

This probably is introduced in the Domoticz version wherethe python framework is reworked to be future proof using Python ABI (if I remember correctly). This was a few stable versions back.