mshttp_call

list ($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 the raw full response.

LoxBerry Compatibility

This feature first is available with LoxBerry 1.2.5. 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 


The first parameter is the Miniserver number (numbers are equal to LBSystem::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 not be URL-encoded.

Return value

ParameterBeschreibung

1. return

Return "value" from Miniserver

2. returnStatus code
3. return

A string containing of the full response returned by the Miniserver

The function returns an array with three values: The queried "value" (string), The status code (string), and the raw string of the response. 

Use PHP's list function to save the three values to different variables (see example).

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. 

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:
    • 500 Server Error, e.g. if the syntax is wrong, or the element does not exist
    • 403 Forbidden, if the element exists, but your user has no access (Loxone user permissions)
  • 200 if the request was successful

Usage

require_once "loxberry_io.php";
// Only value
list ($value) = mshttp_call(1, "/dev/sps/io/Light_Livingroom/state");

// Value with code
list ($value, $status) = mshttp_call(1, "/dev/sps/io/Light_Livingroom/state");
if ($status != 200) {
	echo "Error retrieving from Miniserver";
} else {
	echo "Value is $value.";
}


// Using the raw response 
list ($value, $status, $resp) = mshttp_call(1, "/dev/sps/io/Energymeter_Washingmachine/state");
echo " Code: " . $status;
echo " Full response: " . $resp;