Relay (lua)

Example: Relay

relay.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <templates version="1.3.5">
  3. <!-- triggers a relay in the PBX -->
  4. <template prio="10" name="@string/relay_title" icon="@drawable/relay">
  5. <keyConfiguration>
  6. <lua>
  7. <code>
  8. local valid = false
  9. local active = false
  10. local on = "##8*26"
  11.  
  12. local function updateLed()
  13. if valid then
  14. if active then
  15. key:setLed( "green", true )
  16. time.sleep("2")
  17. key:setLed( "off")
  18. end
  19. else
  20. key:setLed( "red", true )
  21. end
  22. end
  23.  
  24. local function check_valid()
  25. if identity == "" or relid == "" then
  26. valid = false
  27. else
  28. valid = true
  29. end
  30. end
  31.  
  32. function onKeyUp()
  33. if valid then
  34. sip.invite(on..relid.."#",false,identity,true)
  35. active = true
  36. updateLed()
  37. end
  38. end
  39. check_valid()
  40. updateLed()
  41. </code>
  42. <params>
  43. <!-- These parameters are available by name within the lua-script (code-section).
  44. Their value is passed from the parameters-section (see below) -->
  45. <param name="identity"/>
  46. <param name="relid"/>
  47. </params>
  48. </lua>
  49. </keyConfiguration>
  50. <parameters>
  51. <!-- entered by user in phone-UI or on website when configuring this key-function.
  52. Will then be passed as value to the lua-scripts params-section. -->
  53. <parameter name="@string/identity">
  54. <path>//param[@name="identity"]/value</path>
  55. </parameter>
  56. <parameter name="Relay Id">
  57. <path>//param[@name="relid"]/value</path>
  58. </parameter>
  59. </parameters>
  60. </template>
  61. </templates>