mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 07:19:24 +00:00
02_HTTPAPI.pm: new API action "readtimestamp"
git-svn-id: https://svn.fhem.de/fhem/trunk@26287 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6a219d6997
commit
9c94ee426d
@ -107,7 +107,7 @@ sub HTTPAPI_CGI($$$) {
|
||||
my $link;
|
||||
return($hash, 503, 'close', "text/plain; charset=utf-8", encode($encoding, "error=503 Service Unavailable")) if(IsDisabled($name));
|
||||
|
||||
if($request =~ m/^(\/$infix)\/(set|get|read|write)\?(.*)$/) {
|
||||
if($request =~ m/^(\/$infix)\/(set|get|read|readtimestamp|write)\?(.*)$/) {
|
||||
$link = $1;
|
||||
$apiCmd = $2;
|
||||
$apiCmdString = $3;
|
||||
@ -148,13 +148,13 @@ sub HTTPAPI_CGI($$$) {
|
||||
} else {
|
||||
return($hash, 400, 'close', "text/plain; charset=utf-8", encode($encoding, "error=400 Bad Request, $request > attribute action is missing"))
|
||||
}
|
||||
} elsif ($apiCmd eq 'read') {
|
||||
} elsif ($apiCmd =~ /^read|readtimestamp$/) {
|
||||
my $readingName;
|
||||
if ($apiCmdString =~ /&reading(\=[^&]*)?(?=&|$)|^reading(\=[^&]*)?(&|$)/) {
|
||||
$readingName = substr(($1 // $2), 1);
|
||||
# url decoding
|
||||
$readingName =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
|
||||
my $readingVal = ReadingsVal($fhemDevName, $readingName, undef);
|
||||
my $readingVal = $apiCmd eq 'readtimestamp' ? ReadingsTimestamp($fhemDevName, $readingName, undef) : ReadingsVal($fhemDevName, $readingName, undef);
|
||||
#readingsSingleUpdate($defs{$name}, 'reponse', "$readingName=$readingVal", 1);
|
||||
if (defined $readingVal) {
|
||||
return($hash, 200, 'close', "text/plain; charset=utf-8", encode($encoding, "$readingName=$readingVal"));
|
||||
@ -384,6 +384,8 @@ sub HTTPAPI_Undef($) {
|
||||
|
||||
Example:
|
||||
<ul>
|
||||
<code>define httpapi HTTPAPI</code> (Configuration with default values)<br>
|
||||
or<br>
|
||||
<code>define httpapi HTTPAPI api 8087 global</code><br>
|
||||
or<br>
|
||||
<code>define httpapi HTTPAPI infix=api1 port=8089 global=local</code><br>
|
||||
@ -446,6 +448,16 @@ sub HTTPAPI_Undef($) {
|
||||
<code><reading name>=<val>|error=<error message></code><br>
|
||||
</ul>
|
||||
</li>
|
||||
<li>API command line for querying the timestamp of a reading<br>
|
||||
Request:
|
||||
<ul>
|
||||
<code>http://<ip-addr>:<port>/<apiName>/readtimestamp?device=<devname>&reading=<name></code><br>
|
||||
</ul>
|
||||
Response:
|
||||
<ul>
|
||||
<code><reading name>=<timestamp>|error=<error message></code><br>
|
||||
</ul>
|
||||
</li>
|
||||
<li>API command line for deleting a reading<br>
|
||||
Request:
|
||||
<ul>
|
||||
|
Loading…
Reference in New Issue
Block a user