Network

Various functions to do network communication

Mail

Allows sending mails

API

userdata pilight.network.mail()

Creates a new mail object

userdata getUserdata()

Returns a persistent userdata table for the lifetime of the mail object.

string getFrom()

Returns the sender.

string getHost()

Returns the mail server host.

string getMessage()

Returns the mail message.

string getPassword()

Returns the mail server password.

number getPort()

Returns the mail server port.

number getSSL()

Returns the mail server ssl.

boolean getStatus()

After the mail was sent this function can be used in the callback to check if the mail was sent successfully to the server.

string getTo()

Returns the recipient.

string getUser()

Returns the mail server user.

boolean setCallback(string callback)

The name of the callback being triggered by the mail library. The mail object will be passed as the only parameter of this callback function.

boolean setUserdata(userdata table)

Set a new persistent userdata table for the lifetime of the mail object. The userdata table cannot be of another type as returned from the getData functions.

boolean setFrom()

Sets the sender.

boolean setHost()

Sets the mail server host.

boolean setMessage()

Sets the mail message.

boolean setPassword()

Sets the mail server password.

boolean setPort()

Sets the mail server port.

boolean setSSL()

Sets the mail server ssl.

boolean setTo()

Sets the recipient.

boolean setUser()

Sets the mail server user.

boolean send()

Send the mail

Example

local M = {}

function M.callback(mail)
  print(mail.getStatus());
end

function M.run()
  local mailobj = pilight.network.mail();

  mailobj.setSubject("foo");
  mailobj.setFrom("order@pilight.org");
  mailobj.setTo("info@pilight.nl");
  mailobj.setMessage("bar");
  mailobj.setHost("127.0.0.1");
  mailobj.setPort(25);
  mailobj.setUser("pilight");
  mailobj.setPassword("test");
  mailobj.setSSL(0);
  mailobj.setCallback("callback");
  mailobj.send();

  return 1;
end

return M;

HTTP

Do HTTP GET or POST requests

API

userdata pilight.network.http()

Creates a new http object

userdata getUserdata()

Returns a persistent userdata table for the lifetime of the mail object.

string getMimetype()

Returns the mimetype of the received data. This means it does not returns the mimetype set by the setMimetype() function.

string getData()

Returns the data received from the url. This means it does not returns the data set by the setData() function.

string getUrl()

Returns the url.

number getCode()

After the HTTP request was sent this function can be used in the callback to check if the return HTTP code.

number getSize()

After the HTTP request was sent this function can be used in the callback to get the size of the received content.

boolean setCallback(string callback)

The name of the callback being triggered by the http library. The http object will be passed as the only parameter of this callback function.

boolean setUserdata(userdata table)

Set a new persistent userdata table for the lifetime of the http object. The userdata table cannot be of another type as returned from the getUserdata functions.

boolean setUrl(string url)

Sets the request URL. Examples:

boolean setMimetype(string mimetype)

Sets the mimetype of the data being posted.

boolean setData(string data)

Sets the data to be posted.

boolean get()

Send a GET request to the URL.

boolean post()

Send a POST request to the URL with the data set.

Example

local M = {}

function M.callback(http)
  print(http.getCode());
  print(http.getMimetype());
  print(http.getSize());
  print(http.getData());
end

function M.run()
  local httpobj = pilight.network.http();

  httpobj.setUrl("http://127.0.0.1:10080/")
  httpobj.setCallback("callback");
  httpobj.get();

  return 1;
end

return M;