• 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
'FUNCTION' undeclared, v7 compilation fails
#1
The latest commit of v7 development fails to compile due to a problem with function.c (FUNCTION undeclared).

Quote:
Code:
[ 59%] Building C object CMakeFiles/pilight.dir/libs/pilight/events/function.c.o
/home/pi/pilight/libs/pilight/events/function.c: In function ‘event_function_init’:
/home/pi/pilight/libs/pilight/events/function.c:68:30: error: ‘FUNCTION’ undeclared (first use in this function)
      plua_module_load(path, FUNCTION);
                             ^~~~~~~~
/home/pi/pilight/libs/pilight/events/function.c:68:30: note: each undeclared identifier is reported only once for each function it appears in
/home/pi/pilight/libs/pilight/events/function.c: In function ‘event_function_exists’:
/home/pi/pilight/libs/pilight/events/function.c:147:36: error: ‘FUNCTION’ undeclared (first use in this function)
 return plua_module_exists(module, FUNCTION);
                                   ^~~~~~~~
/home/pi/pilight/libs/pilight/events/function.c:148:1: warning: control reaches end of non-void function [-Wreturn-type]
}
 
Reply
#2
Should be fixed.
 
Reply
#3
Thanks. Installation now succeeds.

Unfortunalely pilight doesn't start.  It reports an invalid rule because 'DATE_ADD' doesn't exist. 
pilight-daemon -D doesn't show that event functions are being loaded.

Code:
root@pilight-master:/home/pi# pilight-daemon -D -C /etc/pilight/config_segfault.json
[Jan 06 10:40:20:138714] pilight-daemon: DEBUG: removed protocol ping
[Jan 06 10:40:20:140337] pilight-daemon: DEBUG: stopped protocol threads
[Jan 06 10:40:20:141993] pilight-daemon: DEBUG: freed options struct
[Jan 06 10:40:20:143903] pilight-daemon: DEBUG: loaded protocol ping.so v2.1
[Jan 06 10:40:20:146530] pilight-daemon: DEBUG: loaded protocol arctech_contact_switch.so v0.1
[Jan 06 10:40:20:149571] pilight-daemon: DEBUG: loaded protocol generic_counter.so v0.1
[Jan 06 10:40:20:152489] pilight-daemon: DEBUG: removed protocol generic_label
[Jan 06 10:40:20:154102] pilight-daemon: DEBUG: freed options struct
[Jan 06 10:40:20:156239] pilight-daemon: DEBUG: loaded protocol generic_label.so v1.3
[Jan 06 10:40:20:158259] pilight-daemon: DEBUG: loaded protocol webswitch.so v1.1
[Jan 06 10:40:20:161222] pilight-daemon: DEBUG: removed protocol wunderground
[Jan 06 10:40:20:162851] pilight-daemon: DEBUG: stopped protocol threads
[Jan 06 10:40:20:164662] pilight-daemon: DEBUG: freed options struct
[Jan 06 10:40:20:165591] pilight-daemon: DEBUG: loaded protocol wunderground.so v1.13
[Jan 06 10:40:20:168564] pilight-daemon: DEBUG: loaded protocol generic_http.so v1.0
[Jan 06 10:40:20:172097] pilight-daemon: DEBUG: loaded protocol generic_pending_switch.so v0.1
[Jan 06 10:40:20:174928] pilight-daemon: INFO: wunderfulInit
[Jan 06 10:40:20:177459] pilight-daemon: DEBUG: loaded protocol wunderful.so v1.0
[Jan 06 10:40:20:180899] pilight-daemon: DEBUG: loaded protocol generic_http_result.so v1.0
[Jan 06 10:40:20:185372] pilight-daemon: DEBUG: loaded event action count.so v0.1
[Jan 06 10:40:20:188559] pilight-daemon: DEBUG: loaded event action write.so v1.0
[Jan 06 10:40:20:191253] pilight-daemon: DEBUG: removed event action sendmail
[Jan 06 10:40:20:193466] pilight-daemon: DEBUG: loaded event action sendmail.so v1.1
[Jan 06 10:40:20:196735] pilight-daemon: DEBUG: loaded event action http.so v0.3
[Jan 06 10:40:20:199808] pilight-daemon: DEBUG: removed event action label
[Jan 06 10:40:20:201593] pilight-daemon: DEBUG: loaded event action label_blink.so v2.2
[Jan 06 10:40:20:210996] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/lt.lua v1.0
[Jan 06 10:40:20:214071] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/and.lua v1.0
[Jan 06 10:40:20:217265] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/ge.lua v1.0
[Jan 06 10:40:20:220741] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/notin.lua v1.0
[Jan 06 10:40:20:223869] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/modulus.lua v1.0
[Jan 06 10:40:20:226983] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/or.lua v1.0
[Jan 06 10:40:20:229892] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/ne.lua v1.0
[Jan 06 10:40:20:233148] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/intdivide.lua v1.0
[Jan 06 10:40:20:236430] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/gt.lua v1.0
[Jan 06 10:40:20:239529] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/plus.lua v1.0
[Jan 06 10:40:20:242747] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/le.lua v1.0
[Jan 06 10:40:20:245786] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/minus.lua v1.0
[Jan 06 10:40:20:248881] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/in.lua v1.0
[Jan 06 10:40:20:251884] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/multiply.lua v1.0
[Jan 06 10:40:20:255110] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/divide.lua v1.0
[Jan 06 10:40:20:258172] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/eq.lua v1.0
[Jan 06 10:40:20:265141] pilight-daemon: ERROR: rule #1 invalid: function "DATE_ADD" does not exist
[Jan 06 10:40:20:266769] pilight-daemon: ERROR: rule #1 invalid: invalid action
[Jan 06 10:40:20:268541] pilight-daemon: INFO: rule #1 was parsed until: ... 1 THEN label DEVICE label TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE), %Y-%m-%d %H:%M:%S, %H:%M) DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 DAY), %Y-%m-%d %H:%M:%S, %H:%M)
[Jan 06 10:40:20:270391] pilight-daemon: INFO: rule #1 segfault was parsed in 0.010480 seconds
[Jan 0


Because you ported the functions to lua, I had a look at /usr/local/pilight/functions/ and indeed there were no lua files in there. It appears that the function lua files are in /usr/local/pilight_events/functions. This seems inconstent with the location of the lua operators. 

I wondered what would happen if I moved the functions to /usr/local/pilight/functions/

 Then I got this:

Code:
[Jan 06 10:53:29:303456] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/eq.lua v1.0
[Jan 06 10:53:29:309766] pilight-daemon: ERROR: rule #1 invalid: invalid action
[Jan 06 10:53:29:311364] pilight-daemon: INFO: rule #1 was parsed until: ... 1 THEN label DEVICE label TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE), %Y-%m-%d %H:%M:%S, %H:%M) DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 DAY), %Y-%m-%d %H:%M:%S, %H:%M)
[Jan 06 10:53:29:312915] pilight-daemon: INFO: rule #1 segfault was parsed in 0.007296 seconds
[J

This is the config demonstrating the issue:

Code:
{
    "devices": {
          "testlabel": {
            "protocol": [ "generic_label" ],
            "id": [{
                "id": 1
            }],
            "label": "",
            "color": "black"
        }
    },
    "rules": {
        "segfault": {
            "rule": "IF 1 == 1 THEN label DEVICE label TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE), %Y-%m-%d %H:%M:%S, %H:%M) DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 DAY), %Y-%m-%d %H:%M:%S, %H:%M)",
            "active": 1
        
        }
    },

    "rules": { },
    "gui": { },
    "settings": {
        "standalone": 1,
        "log-level": 6,
        "pid-file": "/var/run/pilight.pid",
        "log-file": "/var/log/pilight.log",
        "webserver-enable": 1,
        "webserver-root": "/usr/local/pilight/webgui",
        "webserver-http-port": 5001,
        "webserver-cache": 1,
        "whitelist": "",
        "gpio-platform": "none"
    },
    "hardware": { },
    "registry": { }
}



Finally, another thing I noticed is this:

Code:
[Jan 06 10:40:20:210996] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/lt.lua v1.0
[Jan 06 10:40:20:214071] pilight-daemon: DEBUG: loaded event action /usr/local/pilight/operators/and.lua v1.0

Shouldn't it say "loaded event operator" instead of "loaded event action"?
 
Reply
#4
I should indeed test this more thoroughly :p

1. I fixed the lua installation path.
2. I fixed the lua loaded log message.
3. The config error is because you configure a testLabel device while you are using a label device in your rules.
 
Reply
#5
Thanks.

The label error was indeed my mistake, but after solving that, I am still getting the "invalid action" error.

Config:

Code:
{
    "devices": {
        "mylabel": {
            "protocol": [ "generic_label" ],
            "id": [{
                "id": 1
            }],
            "label": "",
            "color": "black"
        }
    },
    "rules": {
        "test": {
            "rule": "IF 1 == 1 THEN label DEVICE mylabel TO test",
            "active": 1
        },
        "segfault": {
            "rule": "IF 1 == 1 THEN label DEVICE mylabel TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE) %Y-%m-%d %H:%M:%S, %H:%M)",
            "active": 1
        }
    },
    "gui": {},
    "settings": {
        "standalone": 1,
        "log-level": 6,
        "pid-file": "/var/run/pilight.pid",
        "log-file": "/var/log/pilight.log",
        "webserver-enable": 1,
        "webserver-root": "/usr/local/pilight/webgui",
        "webserver-http-port": 5001,
        "webserver-cache": 1,
        "gpio-platform": "none"
    },
    "hardware": {},
    "registry": {
        "webserver": {
            "ssl": {
                "certificate": {
                    "secure": 0,
                    "location": "/etc/pilight/pilight.pem"
                }
            }
        },
        "pilight": {
            "version": {
                "current": "7.0"
            }
        }
    }
}

The first rule succeeds, but the second one (with the date functions) still fails.

Code:
[Jan 06 16:56:45:285686] pilight-daemon: INFO: rule #1 test was parsed in 0.002251 seconds
[Jan 06 16:56:45:290138] pilight-daemon: ERROR: rule #2 invalid: invalid action
[Jan 06 16:56:45:291662] pilight-daemon: INFO: rule #2 was parsed until: ... 1 THEN label DEVICE mylabel TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE) %Y-%m-%d %H:%M:%S, %H:%M)
[Jan 06 16:56:45:293150] pilight-daemon: INFO: rule #2 segfault was parsed in 0.005521 seconds
[
I also tried putting quotation marks around the format string, but that made no difference.
 
Reply
#6
You miss a komma:
Code:
            "rule": "IF 1 == 1 THEN label DEVICE mylabel TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE), %Y-%m-%d %H:%M:%S, %H:%M)",

After the DATE_ADD function.
 
Reply
#7
You are right, but that wasjust  a typo in the post I made after trying with quotation marks.

With that comma back in I get the same:

Code:
[Jan 07 00:05:19:364375] pilight-daemon: INFO: rule #1 test was parsed in 0.002978 seconds
[Jan 07 00:05:19:369166] pilight-daemon: ERROR: rule #2 invalid: invalid action
[Jan 07 00:05:19:370695] pilight-daemon: INFO: rule #2 was parsed until: ... 1 THEN label DEVICE mylabel TO DATE_FORMAT(DATE_ADD(2015-01-01 21:00:00, +1 MINUTE), %Y-%m-%d %H:%M:%S, %H:%M)
[Jan 07 00:05:19:372469] pilight-daemon: INFO: rule #2 segfault was parsed in 0.006152 seconds
[
 
Reply
#8
I did a few additional commits, a fresh clone myself, and it now passes.
 
Reply
#9
Thanks again. Indeed it is working well now.

I even managed to get my very first serious lua script working with pilight: the HTTP_QUERY_EXTRACT function. Smile

When I was working on it, I was wondering if it is possible to add logging to pilight.log from within lua scripts. So like we do in c modules, with DEBUG/INFO/NOTICE. If that is not already possible I think that would be a usefull addition.
 
Reply
#10
Logging from lua is not possible at the moment. Need to look into that.

Core question remains. Does the mail functionality work again?

Once you can confirm i will release a new version with some bugfixes.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  Function with single argument is causing an error Niek 1 2,561 08-04-2018, 02:46 PM
Last Post: curlymo
  Bug in str_replace function Niek 7 1,519 03-11-2018, 02:37 PM
Last Post: curlymo
  Failure if function result is longer than function itself Niek 2 882 03-03-2018, 09:15 PM
Last Post: Niek
  [Solved] callback not executing when dns lookup fails Niek 1 805 10-08-2017, 11:44 AM
Last Post: curlymo
  [Solved] Sunriseset v7 fails after update and gives negative values PPacman 7 1,840 09-06-2017, 06:25 PM
Last Post: curlymo

Forum Jump:


Browsing: 1 Guest(s)