• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Protocol options defined as JSON_ARRAY getting lost
#1
I tried to add a protocol option that can have multiple values. To do this, I defined the option type as JSON_ARRAY.

Now, if I add a device to the config with that protocol and define some array values like shown  below, it works, but just once.

Code:
"myoption" : [ "value1", "value2" ],

When pilight starts, the array is available in the protocol and its values can be accessed, but when pilight is stopped, the setting has disappeared from the config.

If this intentional, I will have to use a different, less elegant solution like a csv string. But in that case imho the deamon should report ARRAY options as being invalid and should not silently remove them from the config.
 
Reply
#2
True, can you help me reproduce it.
 
Reply
#3
Sure.

A fairly easy way to reproduce it, is to add a fake option to an existing protocol, let's say a generic_label:

Code:
options_add(&generic_label->options, "x", "arrayoption", OPTION_HAS_VALUE, DEVICES_SETTING, JSON_ARRAY, NULL, NULL);

And then create a config with just one generic_label device:

Code:
{
    "devices": {
        "testlabel": {
            "protocol": [ "generic_label" ],
            "id": [{
                "id": 1
      }],
            "label": "",
            "color": "black",
            "arrayoption": [ "val1", "val2" ]
        }
    },
    "rules": {
    },
    "gui": {
    },
    "settings": {
    },
    "hardware": {
    },
    "registry": {
    }
}

If you run pilight-deamon  with this config once , you will see no errors. After stopping pilight, the "arrayoption" setting is no longer in the config.

Running a second time (with "arrayoption" gone) will not give any errors either, even though the setting is not optional. The order of the options in the config has no influence on this behaviour.

I hope this is helpfull.
 
Reply
#4
I've added the requested error message. Implementing this feature would be too much work.
 
Reply
#5
Happy New Year!

Ok, thanks. I will use a csv string instead then.
 
Reply
#6
Imho the check contains a mistake and is incomplete.Unsure

First, the condition should be true if jsettings->key is NOT "id"
Second, not only "id" is an array, but also "protocol".

So I think the check should be:

PHP Code:
 if(jsettings->tag == JSON_ARRAY && strcmp(jsettings->key"id") != && strcmp(jsettings->key"protocol") != ) { 
Am I right?
 
Reply
#7
Yes, seems i was too tired yesterday Smile
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  regex mask for protocol options not working Niek 2 1,390 01-06-2019, 12:20 AM
Last Post: Niek
  [Solved] connection to main pilight daemon lost TopdRob 20 3,786 09-17-2017, 04:30 PM
Last Post: curlymo
  [Solved] dimmer protocol kaku_dimmer does not react on dimmervalue apartmedia 25 3,583 09-16-2017, 10:29 PM
Last Post: apartmedia

Forum Jump:


Browsing: 1 Guest(s)