Lua API Functions

key.setInfo()

nil key:setTitle/Info/Icon( [setMe:string/default=nil] )

Set or remove custom Strings for this key.

setIcon only works on phones that have a colored screen.

Icon-Values can be:

  • a '@drawable/..'-reference to an icon that's part of the firmware. See debug.getDrawables().
  • a http-url to an icon.
  • a base64 encoded image.

key.setIcon()

nil key:setTitle/Info/Icon( [setMe:string/default=nil] )

Set or remove custom Strings for this key.

setIcon only works on phones that have a colored screen.

Icon-Values can be:

  • a '@drawable/..'-reference to an icon that's part of the firmware. See debug.getDrawables().
  • a http-url to an icon.
  • a base64 encoded image.

key.setLed()

nil key:setLed( color:string [blink:boolean/default=false] )
nil key:setLed{ color:string [blink:boolean/default=false] }

Set LED corresponding to the key to the specified color.

Allowed color-values are “red”, “green”, “yellow” and “off”.

key.setTitle()

nil key:setTitle/Info/Icon( [setMe:string/default=nil] )

Set or remove custom Strings for this key.

setIcon only works on phones that have a colored screen.

Icon-Values can be:

  • a '@drawable/..'-reference to an icon that's part of the firmware. See debug.getDrawables().
  • a http-url to an icon.
  • a base64 encoded image.

sip.invite()

nil sip.invite( uri:string [, pickup:boolean/default=false] [, line:int] [, hidden:boolean/default=false] )
? sip.invite{ uri=string [pickup=boolean/default=false] [line=int] [hidden=boolean/default=false] [returnHttpResult:boolean/default=false] }

Send an invite, aka makes a call to the specified uri. Uri can be just a telephone-number or a complete sip-uri.

Attemps a pickup if pickup-parameter is true.

line is the number of the identity to use. When not set the default identity (see idle-screen) is used.

With hidden=true → call will not be shown on the phones display. It won't have audio either.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.subscribe()

handle:data sip.subscribe(uri:string [, type:int [, line:int]], callback:function)
handle:data sip.subscribe{uri:string  callback:function [line:int]}

Start a sip-subscription of type dialog.

uri is the target of the subscription, i.e. where to subscribe to.

type must be set to '0'.

line is the number of the identity to use for subscription.

It defaults to the currently selected identity (see idle screen of phone).

On incoming Notify-messages the callback is called with three parameters:

  • data:string is the raw content of the notify message
  • url:string is the subscribed url
  • identity:int is the number of the identity that started the subscription

The return value of the callback is ignored.Return value is a handle representing the subscription which can be used for unsubscribe.

sip.unsubscribe()

nil sip.unsubscribe( handle:data )
nil sip.unsubscribe{ handle:data }

Unsubscribe a resource previously subscribed with subscribe().

sip.calls.resume()

nil sip.calls.resume( [call:call-object/callId-string], [call2:call-object/callId-string] )
? sip.calls.resume{ [call:call-object/callId-string] [call2:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Resumes a call or a conference.

If you omit the callId's, the first found held call or conference will be resumed.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.terminate()

nil sip.calls.terminate( [call:call-object/callId-string], [call2:call-object/callId-string]])
? sip.calls.terminate{ [call:call-object/callId-string] [call2:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Terminates (hangup) a call or conference.

If you omit the callId's, the active call or conference will be terminated.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.accept()

nil sip.calls.accept( [call:call-object/callId-string] )
? sip.calls.accept{ [call:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Accepts an incoming call.

If you omit the callId, the first ringing call found will be accepted.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.listen()

handle:data sip.calls.listen( callback:function )
handle:data sip.calls.listen{ callback:function }

Subscribe for call changes.

Returns handle which can be passed to stop_listen.

The callback is called with two multiple parameters, first one names the change:

  • 'add', call-obj - there is a new call
  • 'remove', call-obj - call was deleted
  • 'remote_update', call-obj - either number or name of call have changed, see call:getRemote()
  • 'state_changed', call-obj - state of call changed (e.g.: put on hold), see call:getState()
  • 'transferred', call-obj - call got transferred → new party on the other end
  • 'conferenced', call-obj, call-obj - both calls are now in a conference
  • 'unconferenced', call-obj, call-obj - both calls are no longern in a conference
  • 'transfer_initiated', call-obj, call-obj - starting attended transfer, both remote parties of both calls are being connected.
  • 'transfer_failed', call-obj, call-obj - attended transfer failed
  • 'transfer_done', call-obj, call-obj - attended transfer was successful
  • 'transfer_done', call-obj, target:string - blind transfer was successful

Call objects can be used to query or modify the call.

The return value of the callback is ignored.

sip.calls.get_all()

calls:array sip.calls.get_all()

Returns a table (array) of calls

sip.calls.hold()

nil sip.calls.hold( [call:call-object/callId-string], [call2:call-object/callId-string] )
? sip.calls.hold{ [call:call-object/callId-string] [call2:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Holds a call or a conference.

If you omit the callId's, the active call or conference will be held.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.transfer()

nil sip.calls.transfer( [call:call-object/callId-string], number:string )
? sip.calls.transfer{ number:string [call:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Transfers a call to a specified number.

You may set the callId to nil in which case the the phone will make a guess which call is ment.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.join()

nil sip.calls.join( [call:call-object/callId-string], [call2:call-object/callId-string] )
? sip.calls.join{ [call:call-object/callId-string] [call2:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Joins two calls, aka a transfer. This phone will no longer be involved in the calls.

If you omit one or both call's, the phone will make a guess which calls are ment.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.conference()

nil sip.calls.conference( [call:call-object/callId-string], [call2:call-object/callId-string] )
? sip.calls.conference{ [call:call-object/callId-string] [call2:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Joins two calls into a lokal conference, aka where audio is mixed on this phone.

Conferences may be dissolved by only holding or terminating one of the conference members

If you omit one or both callId's, the phone will make a guess which calls are ment.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.make()

nil sip.calls.make( uri:string [, pickup:boolean/default=false] [, line:int] [, hidden:boolean/default=false] )
? sip.calls.make{ uri:string [pickup:boolean/default=false] [line:int] [hidden:boolean/default=false] [returnHttpResult:boolean/default=false] }

Makes a call to the specified uri. Uri can be just a telephone-number or a complete sip-uri.

Attemps a pickup if pickup-parameter is true.

Line is the number of the identity to use. When not set the default identity (see idle-screen) is used.

With hidden=true → call will not be shown on the phones display. It won't have audio either.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.dtmf()

nil sip.calls.dtmf( [call:call-object/callId-string], dtmf:string )
? sip.calls.dtmf{ dtmf:string [call:call-object/callId-string] [returnHttpResult:boolean/default=false] }

Sends a dtmf-sequence on an active call.

You may set the callId to nil in which case the active call is used, if there is one.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

sip.calls.stop_listen()

nil sip.calls.stop_listen( handle:data )
nil sip.calls.stop_listen{ handle:data }

Stop listening for calls previously started with listen().

sip.identities.is_active()

boolean sip.identities.is_active( idIdx:int )
boolean sip.identities.is_active{ idIdx:int }

Returns whether an Identity is registered or not.

idIdx is the number of the identity to check (1-based index).

sip.identities.stop_listen()

nil sip.identities.stop_listen( handle:data )
nil sip.identities.stop_listen{ handle:data }

Stop listening for account state changes previously started with accounts.listen().

sip.identities.listen()

handle:data sip.identities.listen( callback:function )
handle:data sip.identities.listen{ callback:function }

Subscribe for account state changes.

Returns handle which can be passed to stop_listen.

The callback is called with no parameters.

The return value of the callback is ignored.

debug.getDocu()

string debug.getDocu( thing:lua-object )
string debug.getDocu{ thing:lua-object }

Returns the documentation for the provided function, table or other lua-object.

May return nil when no documentation exists.

debug.log()

nil debug.log( message:string [, debug_level:string/default=i] )
? debug.log{ message:string [debug_level:string/default=i] [returnHttpResult:boolean/default=false] }

Log the provided message into androids LogCat-system.

debug_level = e/w/i/d/v → i.e. a one-char String (only first char is looked at) that marks the severity of the log: error, warning, info, debug or verbose.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

on D100/200 there is a setting that limits logs to only show errors and warnings by default. To enable logs up to debug, you need to set Access → Extended Logging.
verbose logs usually do not show up, unless you use androids adb-tool to connect to your phone and increase the log sensitivity with `adb shell setprop log.tag.LuaScript VERBOSE`.

debug.getLoadableLibs()

table<string> debug.getLoadableLibs()

Returns a list of all Libraries that can be called into any LuaScript using require(“[libname]”).

These include baked-in modules like the penlight library as well as the LuaLibraries which are part of the settings.

debug.getDrawables()

table<string> debug.getDrawables()

Returns a list of all drawables that can be used e.g. for key.setIcon().

system.toast()

nil system.toast( text:string )
? system.toast{ text:string [returnHttpResult:boolean/default=false] }

Shows the provided text as a toast.

If you set returnHttpResult to true, the function will return the result of the operation.

Result consists of multiple values, see http.listen()-callback-description for details.

returns nil unless returnHttpResult==true

http.post()

nil xml.post(url:string [, callback:function [, content:string [, headers:table]]])

Send an http post request to the provided url.

See http.request() for details.

http.put()

nil xml.put(url:string [, callback:function [, content:string [, headers:table]]])

Send an http put request to the provided url.

See http.request() for details.

http.request()

nil xml.request(url:string [, callback:function [, method:string/default=GET [, content:string]], headers:table])

Send an http request to the provided url.

The url-parameter must start with http:// or https://.

You can pass credentials for authorization challenges via: http://username:password@...

The callback receives 3 parameters: callback(responseCode:int [, content:string, headers:table]).

  • when the request was unsuccessful, the callback gets called with just the http error code.

The method-parameter should be either GET, POST, DELETE or PUT.

The content-parameter is appended as the body of the http-request.

You can optionally supply request headers as a table mapping string keys to string values.

http.get()

nil xml.get(url:string [, callback:function [, headers:table]])

Send an http get request to the provided url.

See http.request() for details.

http.listen()

handle:data http.listen(path:string, callback:function [, exclusive:boolean/default=false])

Listen for HTTP requests under https://<your-phone-IP>/api/v1/exec/<path>.

The request has to be authenticated (via Login or token).

Returns handle which can be passed to stop_listen.

If the parameter <exclusive> is true and there already exists a handler for the supplied <path>,

the function returns nil and the handler is not installed.

The request goes to the supplied callback function, which is called with these parameters:

  • the requested path as a string, aka same as the original path-parameter
  • the request body as a string
  • the request headers as a table with string keys and values
  • another table, with additional infos like 'request_method', 'query_string' and 'query_map'

If <exclusive> is true, then the callback can return the HTTP response code,

the response body and a map of additional headers to include in the response.

If the code is nil, 200 is sent. If the body is nil, an empty body is sent.

If <exclusive> is false, any return value from the callback is ignored.

http.stop_listen()

nil http.stop_listen(handle:data)

Stop listening for HTTP requests. Parameter handle must be the return value from previous call to http.listen().

dialog.show()

nil dialog.show( text:string )

Shows the provided text in fullscreen.

function is deprecated and may get removed in future, use system.toast() instead.

xml.eval()

XmlObj xml.eval(xml:str)

Convert the provided xml-string into a xml object.

xml.append()

XmlObj xml.append(XmlObj, tableOrTag:table)
XmlObj xml.append(XmlObj, tableOrTag:string)

Create new XmlObj like `xml.new()` and append it to the child elements of the provided XmlObj.

The children are stored at index 1 and up in the XmlObj.Returns the new child.

xml.appendtext()

XmlObj xml.appendtext(XmlObj, text:string)

Append a plain-text element to the child elements ot the provided XmlObj.

The children are stored at index 1 and up in the XmlObj.Returns the provided XmlObj.

xml.tostring()

string xml.tostring(XmlObj)

Return string representation of the provided XmlObj.

xml.find()

XmlObj xml.find(XmlObj [, tag[, key[, value]]])

Find a XmlObj within the provided XmlObj. The provided XmlObj is checked as well as it's children and any of their children recursivly. The first match is returned or nil if no match was found.

Tag can be nil or “” to find an element with any tag.

If key is not nil or “”, the element must have an attribute with this key.

If value is not nil, the attribute must have this value.

xml.new()

XmlObj xml.new(tableOrTag:table)
XmlObj xml.new(tableOrTag:string)

Create a new xml object.

If `tableOrTag` is a table, use and convert it to a xml object (i.e. keep the data as is and add a metatable for object-like access).

If `tableOrTag` is a string, use as the tag of the XmlObj.

XmlObj's have their tag stored at index [0].

At index [1] and above all children are stored. These are either XmlObj's themselfes or a string representing plain-text content.

xml.tag()

string xml.tag(XmlObj)
nil xml.tag(XmlObj, tag:string)

Returns or sets the tag of the XmlObj.If `tag` nil, returns the tag of the provided XmlObj.

If `tag` is a string, changes the tag of the XmlObj.

json.object()

JsonObj json.object([base:table])

Create a new json object.

If base is set, copy all its string-key-value pairs to JsonObj[key.tostring()] = value.tostring().

Values of type table get skipped.

json.eval()

JsonObj json.eval(json:string)

Parse a string and return a json object.

json.insert()

nil json.insert(array:JsonAry [, index:int], value:data)

With an index inserts the provided value at the marked position into the JsonAry.

Without an index adds the provided value at the end of the JsonAry.

The value should be either a JsonObj, a JsonAry or a string.

json.array()

JsonAry json.array([base:array])

Create a new json array.

If base is set, copy all its indexed values to JsonAry[idx] = value.tostring().

Values of type table get skipped.

json.tostring()

string json.tostring(stringMe:JsonObj)
string json.tostring(stringMe:JsonAry)

Return string representation of the provided json object or array.

bluetooth.unregisterRangeCheck()

nil bluetooth.unregisterRangeCheck(addr:string, callback:function)
nil bluetooth.unregisterRangeCheck{addr:string, callback:function}

Unregister from updates on the signal-strength (rssi) of a bluetooth device.

bluetooth.registerRangeCheck()

nil bluetooth.registerRangeCheck(addr:string, callback:function)
nil bluetooth.registerRangeCheck{addr:string, callback:function}

Register for updates on the signal-strength (rssi) of a bluetooth device.

You'll need a paired bluetooth 4 device to receive rssi-updates.

Provide the bluetooth-mac-address as addr-parameter.

The callback receives two parameters: callback(status:string, rssi:int).

  • the callback gets called in a fixed interval once the device connects for the first time.
  • status will either be “OK” or “NOT FOUND”.
  • rssi is an int or NIL if not in range.

bluetooth.getDevices()

{} bluetooth.getDevices()

Returns a dictionary of all known bluetooth devices. Keys are the addresses and the value holds the name.Returns NIL on error, e.g. missing bluetooth dongle.

time.sleep()

nil time.sleep(sleepInSeconds:number)

sleeps up to 5 minutes

function is deprecated and may get removed in future, use time.callbackIn() instead.

time.unregister()

nil time.unregister(callback)

unregister to get a callback every passing minute

time.register()

nil time.register(callback)

register to get a callback every passing minute

time.callbackIn()

nil time.callbackIn(callback, delayInSeconds)

register LuaFunction callback, to be called in delayInSeconds

time.callbackIn(callMe, 0.1) will call callMe in 100 milliseconds.

smallest resolution is 1 ms

async.async()

async.async()

Create a new async object. The object has two functions:

complete(...) -> set the return values of await()
... await([timeout]) -> wait for and return the values given to complete()
    timeout is specified in seconds
    the function will never wait longer than 5 minutes even if no timeout is given

example:

local function http_get_sync(url)
  local async = async.async()
  http.get(url, function(code, response, headers)
      async.complete(response)
  end)
  local res, response = async.await()
  return response
end

Returns async object

phoneInfo.getBrand()

string phoneInfo.getBrand()

Returns either Auerswald or Fontevo

phoneInfo.getMacAddress()

string phoneInfo.getMacAddress()

Returns the mac address of the phone.

phoneInfo.getIPs()

array<string> phoneInfo.getIPs()

Returns a table/array of all IPs the phone has.IPv4's get listed up front, followed by all IPv6's

phoneInfo.getModel()

string phoneInfo.getModel()

Returns the model of the phone, e.g.: D400

phoneInfo.getFwVersion()

string phoneInfo.getFwVersion()

Returns the firmware version, e.g.: 1.6A

config.unregister()

nil config.unregister( path:string, callback:function )
nil config.unregister{ path:string callback:function }

Unregister callback function for the specified path.

path is the xPath to a setting or group of settings.

config.set()

nil config.set( path:string, value:string )
nil config.set{ path:string value:string}

Set a setting-value.

path is the xPath to the desired setting.

value holds the new desired value.

config.get()

string config.get( path:string )
string config.get{ path:string }

Get a setting-value.

path is the xPath to the desired setting.

config.register()

nil config.register( path:string, callback:function )
nil config.register{ path:string callback:function }

Register to be informed of changing setting(s).

path is the xPath to a setting or group of settings.

callback will be called with one parameter:

  • path:string → the xPath of the changed setting(s)

return-value of callback is ignored.