cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Luascript Service

adityaku
1-Newbie

Luascript Service

Hi All,

I want to write a service in Lua script, for the below conditions:

Accepts three inputs – a (integer), b(minute, integer), and c (integer, 1-3)

  • Sets d property to zero, for a greater than 0.  Hold it at zero if a > 0, tasker should not increment or change d property, if a > 0.
  • Places text message in LSR log window as below:
    • if C value is 1 then “Green”
    • if C value is 2 then “Yellow”
    • if C value is 3 then “Red"

How to do this ? I am getting an error while writing this as i am new to lua.

Thanks,

Aditya

6 REPLIES 6

Aditya,


Can you show us the code you already have? I think with the logic you described you can do this with a while loop with a repeat function. If you can show me how far you got I should be able to help get it working.

First defined the service as below:

serviceDefinitions.RemoteService (

  input { name="a", baseType="INTEGER" },

  input { name="b", baseType="INTEGER" },

  input { name="c", baseType="INTEGER" },

  output { baseType="NOTHING" },

  description { "Values" }

)

services.RemoteService = function(me, headers, query, data)

if not a then

return 400, "You must provide the 'a' parameter"

else

return 200, me.setProperty("d",0,0,0)

end

I have proceeded like this but getting in error  in this piece of code itself.

Aditya,

I'm assuming that you're working from this tutorial:

Defining and Implementing Custom Services at the Edge

If that's the case, you're probably getting one of two errors.

1. lua: user.lua:15: 'end' expected (to close 'function' at line 9) near <eof>

     -This is because you are missing an 'end' to close the function. You have one to close the if statement, but the function is still open

2. attempt to index global 'serviceDefinitions' (a nil value)

     stack traceback:

             user.lua:1: in main chunk

             : in ?

     -This is because the data in the service you defined is provided from outside the script (from the Edge service.) Essentially, there is nothing input into the input lines leaving it empty, hence the complaint of a nil value.

     For this reason, the lua script in the example from the tutorial will not work outside the context of the Edge server. It might be a good idea to go though all the steps of that tutorial and set up an Edge Enhanced Thing to work with if you're not doing that already.

Note: I also found this tutorial on scope very useful when researching this issue: Tutorial: Scope for beginners | Corona Labs

Aditya,

Any update on this? Was my post helpful?

Thanks Jeremy!!

Can you please help me

can  anyone help on this

Top Tags