Zum Ende der Metadaten springen
Zum Anfang der Metadaten

($value, $respcode, $data) = mshttp_call($msno, $command);

 

Sends a HTTP REST request to the specified Miniserver and returns the status code and value, and also a hashref to the datastructure of the response.

LoxBerry Compatibility

This feature first is available with LoxBerry 1.2.4. Set your LB_MINIMUM version in your plugin.cfg accordingly.


This function is the "raw", generic Miniserver REST function. To send or query data, you should prefer LoxBerry::IO::mshttp_send and LoxBerry::IO::mshttp_get.


The first parameter is the Miniserver number (numbers are equal to LoxBerry::System::get_miniservers, starting with 1).

The second parameter is a string with the full command, but without hostname, e.g. /dev/sps/io/Livingroom/state.

Parameter

ParameterRequiredBeschreibung
$msnoxNumber of the Miniserver


$commandxThe full command. The parameter must be URL-encoded correctly (slashes of the url must not be encoded, but parameters do).

Return value

ParameterBeschreibung

1. return

Return "value" from Miniserver

2. returnStatus code
3. return

A hash reference to the data structure returned by the Miniserver.

As the first return only includes the "value" property, the hashref includes all data.

The function returns three values: The queried "value" (string), The status code (string), and the full, parsed response (hashref). 

Status codes not in the 2xx range (below 200 and from 300 upwards) are an error. Normally, Loxone returns a "code" 200 for ok.

As Loxone Miniserver most commonly returns a HTTP statuscode of "200 OK" in the HTTP header - also with wrong syntax or non-existing elements, the function parses the result and returns the "code", a value the Miniserver returns inside of the response XML. 

Therefore, the function may return

  • a LoxBerry-own "error code" in the 6xx area (e.g. "601" for "Miniserver not defined")
  • the HTTP statuscode, if a real HTTP header errorcode is returned
  • the Loxone "code" of the response XML (for errors, most used is the 500)
  • 200 if the request was successful

Usage

use LoxBerry::IO;
# Only value
my ($value) = mshttp_call(1, "/dev/sps/io/Light_Livingroom/state");

# Value with code
my ($value, $status) = mshttp_call(1, "/dev/sps/io/Light_Livingroom/state");
if ($status ne "200") {
	print STDERR "Error retrieving from Miniserver";
} else {
	print STDERR "Value is $value.";
}


# Data structure
my ($value, $status, $resp) = mshttp_call(1, "/dev/sps/io/Energymeter_Washingmachine/state");
print " Code: " . $resp->{Code};
print " value: " . $resp->{value};
print " output AQ9: " . $resp->{output}->{AQ9}->{value};
  • Keine Stichwörter