Personal tools

Difference between revisions of "API"

From PhotoVoltaic Logger new generation

Jump to: navigation, search
m (Parameters)
m (Parameters)
Line 82: Line 82:
 
* all<ref>returns '''all''' readings, ignores start-end range, useful for full backup</ref></tt>
 
* all<ref>returns '''all''' readings, ignores start-end range, useful for full backup</ref></tt>
 
|-
 
|-
| <tt>attributes</tt> || Return channel attributes as 1<sup>st</sup> data set / line || bool<ref name="bool">All of <tt>(1|x|yes|on|true)</tt> are interpreted case-insensitive as TRUE.</ref> || <tt>0</tt> ||
+
| <tt>attributes</tt> || Return channel attributes as 1<sup>st</sup> data set / line || bool<ref name="bool">All of <tt>(1|x|yes|on|true)</tt> are interpreted case-insensitive as TRUE.</ref> || <tt>0</tt> || <tt>yes</tt>
 
|-
 
|-
| <tt>full</tt> || Return all<ref>datetime, timestamp, data, min, max, count, timediff, consumption</ref> data, not only timestamp and value || bool<ref name="bool" /> || <tt>0</tt> ||
+
| <tt>full</tt> || Return all<ref>datetime, timestamp, data, min, max, count, timediff, consumption</ref> data, not only timestamp and value || bool<ref name="bool" /> || <tt>0</tt> || <tt>X</tt>
 
|-
 
|-
| <tt>short</tt> || JSON: Return data as numeric indexed array, not as object with named keys || bool<ref name="bool" /> || <tt>0</tt> ||
+
| <tt>short</tt> || JSON: Return data as numeric indexed array, not as object with named keys || bool<ref name="bool" /> || <tt>0</tt> || <tt>On</tt>
 
|}
 
|}
  
 
<references />
 
<references />

Revision as of 09:51, 28 February 2014

Abstract

An application programming interface (API) is a protocol intended to be used as an interface by software components to communicate with each other." -- Wikipedia:API

The API is implemented as a RESTful API, so it uses HTTP requests to store and read data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

PVLng supports all of them:

  • PUT = create
  • GET = read
  • POST = update
  • DELETE = delete

Data storage

For data storage we have two possibilities:

  • Web front end for the master data, like channels and their relationships
  • HTTP REST API for the operational channel data with HTTP PUT requests

The storage API accepts only one parameter data and routes it to the requested channel.

By default (load live data) system date and time will be used.

The model behind the channel represents the interface to the database.

Data readout

This section describes only the readout of measuring data via API, see the detailed API help for more supported actions.

The data readout from the system must be done with HTTP GET requests.

The readout API analyzes the requests, identifies the channel and returns the extracted data.

The model behind the channel provides a defined interface to query data.

Requested format

The returned content type is detected by the requested file extension

Extension Format Content type
.json JSON (default, if no extension is set) application/json
.csv Semicolon separated values application/csv
.tsv TAB separated values application/tsv
.txt Space separated values
(proposed for single attribute requests)
text/plain

Parameters

All parameters are optional.

Parameter name Description Format default Examples
start Start timestamp for readout string 00:00
  • YYYY-mm-dd HH:ii:ss
  • seconds since 1970
  • relative from now
  • sunrise[1]
end End timestamp for readout string 24:00
  • YYYY-mm-dd HH:ii:ss
  • seconds since 1970
  • relative from now
  • sunset[1]
period Example string <empty>
  • [1-9][0-9]*minutes
  • [1-9][0-9]*hours
  • [1-9][0-9]*days
  • [1-9][0-9]*weeks
  • [1-9][0-9]*month
  • [1-9][0-9]*quarters
  • [1-9][0-9]*years
  • last[2]
  • readlast[3]
  • all[4]
attributes Return channel attributes as 1st data set / line bool[5] 0 yes
full Return all[6] data, not only timestamp and value bool[5] 0 X
short JSON: Return data as numeric indexed array, not as object with named keys bool[5] 0 On
  1. 1.0 1.1 needs the location defined in in config/config.php
  2. returns the last reading for selected start-end range, can be empty, if no data in range, also relevant for meter channels
  3. returns the last reading, ignores start-end range
  4. returns all readings, ignores start-end range, useful for full backup
  5. 5.0 5.1 5.2 All of (1|x|yes|on|true) are interpreted case-insensitive as TRUE.
  6. datetime, timestamp, data, min, max, count, timediff, consumption