eGauge WebAPI (4.6)

eGauge Meter API

Download OpenAPI description
Languages
Servers
Mock server
https://webapi.egauge.net/_mock/webapi/4.6/openapi/
The WebAPI server
https://{devname}.egauge.io/api/

Introduction

The eGauge WebAPI is a JSON-based API that provides access to eGauge meters. It offers secure means to read device data, configure the device, and perform various control operations.

The WebAPI is intended to eventually replace the eGauge XML API. For new applications, developers are encouraged to use WebAPI rather than the legacy XML API.

/auth

The authentication service. Clients can use this to obtain and manage tokens that grant access to the other resources in this API.

The meter uses JSON Web Tokens (JWT or simply token) to restrict access to protected resources. Clients must include such tokens in requests via the HTTP Authorization header. This header must have the form:

Authorization: Bearer JWT

where JWT is a valid token.

Tokens are valid for a limited time; typically for about 10 minutes. However, a meter may revoke a token earlier, e.g., due to a reboot.

Operations

/capture

The capture service allows collecting waveform data for configured input channels.

Operations

Basic Usage

GET /capture&i returns information about the channels for which waveform data can be captured. The returned object might look like this:

{
  "channels": {
    "0": {"name": "L1", "unit": "V"},
    "1": {"name": "L2", "unit": "V"},
    "4": {"name": "S1", "unit": "A"}
    }
}

This response indicates that three channels are available. The meter-internal channel numbers are 0, 1, and 4. As the name values indicate, those channels correspond to meter inputs L1, L2, and S1, respectively. The first two channels return samples as volts (V) and the third returns samples as amperes (A).

GET /capture?n&d=1e-3&c=0&c=4 initiates a capture for 1ms of samples on channels 0 and 4 and returns a cookie (token) to be used to retrieve the capture samples. The response for this request might look like this:

{"state": "armed", "cookie": 1875353535}

State armed indicates that the meter successfully processed the capture request and is waiting for the trigger to occur. Cookie 1875353535 is a random integer to be used when retrieving the sampled data, as shown next.

GET /capture?n=1875353535 can now be used to fetch the samples. The response might look as shown below:

  {
    "state": "full", "ts_freq": 1000000, "first_sample": "1619637288.061",
    "ch_mask": [17, 0],
    "r": [
      {"t": 495514564, "d": [135.059]},
      {"t":        82, "d": [-0.0146239]},
      {"t":      1354, "d": [105.454, -0.00731193]}
    ]
  }

State full indicates that the capture buffer is full and therefore the response contains sample values. The frequency of the counter used to generate the timestamps is 1MHz ("ts_freq": 1000000) and the realtime Unix timestamp of the first sample is 28 April 2021, 19:14:48 UTC (first_sample": "1619637288.061"). The ch_mask member is an array of 32-bit integers. If a bit is set in this mask, data for that channel is included in the response. In our case, the channel mask has only bits 0 and 4 set in the first integer (17), indicating that channels 0 and 4 are contained in the sampled data (in order from smallest to largest channel numbers). The timestamp t of the first sample is 495514564 and the subsequent samples were acquired 82 and 1354 timestamp ticks after the corresponding previous sample. Thus, the reconstructed sample values for the channels are:

Timestamp [µs]Channel 0 value [V]Channel 1 value [A]
495514564135.059
495514646-0.01462390
495516000105.454-0.00731193

Note how the sample values are returned strictly in order from lowest number to highest numbered channel: 0, 4, 0, 4. Also note how there is a separate entry in the result array r for each unique timestamp. Each data array (d) may have just a single entry or multiple entries if there are multiple sample values with the same timestamp.

Python Example

A Python program illustrating the use of this service can be found here. This program takes advantage of class egauge.webapi.device.Capture to handle the details of encoding the HTTP requests and decoding the responses.

Capture waveform data

Request

Query
Cinteger>= 0

The channel number to use as the trigger.

Mstring

The trigger mode to use. any triggers immediately, rise triggers when a rising edge crosses the trigger level, fall triggers when a falling edge crosses the trigger level, gt triggers when the trigger channel's sample value is greater than the trigger level, and lt triggers when it is less than the trigger level.

Enum"any""rise""fall""gt""lt"
Lnumber

The trigger level.

Rboolean

If present, this query parameter cancels a pending capture and resets the state to available. If a value for query parameter n is also specified, only the matching capture is canceled. Otherwise, any pending capture is canceled.

Tnumber>= 0

Trigger timeout in milliseconds. After starting a capture, if the trigger condition is not satisfied within this timeout period, the capture is auto-triggered.

cinteger>= 0

Channel number to be captured. This query parameter can be specified multiple times to capture multiple channels. If not specified, all configured channels are captured by default.

dnumber

Capture duration in seconds. If less than or equal to 0, the maximum number of samples are acquired. This maximum is implementation dependent but, generally, a fixed size buffer is used to store all samples of all channels, so the more channels are being captured, the lower the upper bound for this value. If the value is greater than this upper bound, it is automatically capped at that value.

iboolean

Return a channel info object, describing each channel that may be captured, its name and its physical unit.

ninteger>= 0

Non-blocking operation. If the query parameter has no value or an empty string value, this requests that a capture is initiated without waiting for the result to be available (asynchronous operation). In this case, a cookie object is returned which contains a token. The token can be used in subsequent requests to fetch the result of the capture or to check on its status.

If a value is specified, it must be a token returned in an earlier cookie object response. In this case, the capture status is reported via a progress object if it is still pending or a capture result object if the capture is complete.

pnumber

Pre-trigger duration in seconds. Specifies how many seconds of samples before the trigger point should be acquired. If omitted, this defaults to 0 seconds of pre-trigger data.

rboolean

If present, this query parameter requests that the sample values should be returned as raw (digital) sample values rather than as values converted to the channel's physical unit.

tbooleanDeprecated

If present, this query parameter requests that the data should be returned as plain text rather than as JSON.

curl -i -X GET \
  'https://webapi.egauge.net/_mock/webapi/4.6/openapi/capture?C=0&L=0&M=any&R=true&T=0&c=0&d=0&i=true&n=0&p=0&r=true&t=true' \
  -H 'Authorization: Bearer <YOUR_JWT_HERE>'

Responses

Capture response.

Bodyapplication/json
One of:
channelsobjectrequired

Map of available (configured) channels. For each channel number, the name name and the physical unit of the sample values are given.

Example: {"0":{"name":"L1","unit":"V"},"4":{"name":"S1","unit":"A"}}
channels.​^[0-9]+$objectpattern property
errorstring(ErrorString)

A message describing the first error that occurred. This member is present only if an error occurred.

Response
application/json
{ "channels": { "0": { … }, "4": { … } }, "error": "Error message (present if an error occurred)." }

/cmd

The service provides the ability to execute various operations for their side effects, such as rebooting the meter. Unless stated otherwise, the resources in this service are available only to users with the save right (see /auth/rights).

Operations

/config

The meter configuration service.

The endpoints under /config provide common method semantics and atomicity guarantees as described below.

Operations

/config/alert

The alert configuration of the meter.

Operations

/config/alert/custom

Up to 32 custom alerts.

Custom alerts consist of an arbitrary boolean condition that is checked at certain times. When the condition evaluates to true, the alert is triggered.

Operations

/config/alert/custom/{idx}

The custom alert.

Operations

/config/alert/custom/{idx}/cond

The boolean condition consists of three parts: lhs op rhs. lhs and rhs are arbitrary expressions and op must be a comparison operator.

Operations

/config/alert/custom/{idx}/cond/lhs

An eScript expression that returns the value to use on the left hand side of the comparison.

Operations

/config/alert/custom/{idx}/cond/op

The comparison-operator to use for comparing the left-hand-side expression lhs against the right-hand side expression rhs. It may be one of:

  • <: Condition is true if lhs is less than rhs.
  • <=: Condition is true if lhs is less-than-or-equal to rhs.
  • =: Condition is true if lhs is equal to rhs.
  • !=: Condition is true if lhs differs from rhs.
  • >=: Condition is true if lhs is greater-than-or-equal to rhs.
  • >: Condition is true if lhs is greater than rhs.
Operations

/config/alert/custom/{idx}/cond/rhs

An eScript expression that returns the value that to use on the right hand side of the comparison.

Operations

/config/alert/custom/{idx}/detail

Alert detail message. This may be up to 255 bytes in length. The following sequences within this string get replaced as follows:

  • %% is replaced by a single percent character.
  • %l is replaced by the value of the lhs expression.
  • %r is replaced by the value of the rhs expression.
  • %L is replaced by the lhs expression string.
  • %R is replaced by the rhs expression string.
Operations

/config/alert/custom/{idx}/frequency

The frequency with which this custom alert should be checked. Possible values are:

  • sec: The alert will be checked once a second.
  • min: The alert will be checked once a minute.
  • hr: The alert will be checked once an hour.
  • dy: The alert will be checked once a day.
  • wk: The alert will be checked once a week.
  • mon: The alert will be checked once a month.
  • an: The alert will be checked once a year.
Operations

/config/alert/custom/{idx}/name

The user-selected name of this custom alert.

Operations

/config/alert/custom/{idx}/priority

The priority of this custom alert. Zero is the lowest, seven the highest priority.

Operations

/config/alert/reporter

The alert reporting configuration. Alerts may be reported via a web server or via an email server.

Operations

/config/alert/reporter/mail

The configuration for reporting alerts via email server. If alert reporting via web server is enabled (/config/alert/reporter/web/uri is not empty), reporting via email server is disabled.

Operations

/config/alert/reporter/mail/server

The hostname of a mail server that speaks the SMTP protocol. If this is set to an empty string, the meter will attempt to deliver mail directly to the destination host. Many Internet service providers block direct mail delivery, so leaving this string empty generally results in alert emails getting blocked.

Operations

/config/alert/reporter/mail/user

The user name to provide to the email server for authentication purposes.

Operations

/config/alert/reporter/mail/password

The password to provide to the email server for authentication purposes.

This resource is write-only.

Operations

/config/alert/reporter/mail/from-address

The "From" email address to use when sending an email alert. If set to an empty string, the email server will use a default address.

Operations

/config/alert/reporter/mail/to

The email destinations to send the alerts to.

Operations

/config/alert/reporter/mail/to/{idx}

An email destination to send the alerts to.

Operations

/config/alert/reporter/mail/to/{idx}/address

The destination email address to send the alert to.

Operations

/config/alert/reporter/mail/to/{idx}/format

The reporting format to use for this destination. Valid values are:

  • short: Report only the newest alert with the highest priority.

  • full: Report all unacknowledged alerts that are pending in order from highest to lowest priority.

Operations

/config/alert/reporter/mail/to/{idx}/min-priority

The minimum priority that is required for a new alert to generate an email. When an email is generated, other lower priority alerts may also be included if they are unacknowledged and the reporting format allows it.

Operations

/config/alert/reporter/web

The configuration for reporting alerts via web server.

Operations

/config/alert/reporter/web/min-priority

The minimum priority that is required for a new alert to generate a report to the web server. When a report is generated, all other unacknowledged alerts are also reported, even if they have a priority lower than the value indicated by this resource.

Operations

/config/alert/reporter/web/options

The options to use when sending an alert report to the web server.

This resource is available only if /config/alert/reporter/web/service is an empty string.

Multiple options can be specified in the string by separating them with a comma. Supported options are:

  • deflate: Use HTTP Content-Encoding deflate when transmitting the alert report.

  • gzip: Use HTTP Content-Encoding gzip when transmitting the alert report.

  • secure: Only send the alert report if the server's HTTP certificate can be verified by the meter. This option is ignored if /config/net/http/client/insecure is true.

Operations

/config/alert/reporter/web/password

The password to be provided to the web server for authentication purposes.

This resource is write-only

Operations

/config/alert/reporter/web/service

The name of the alert service provider to use for reporting alerts.

To set this to a non-empty value please use the service activation command since that ensures the service provider knows to expect alerts from this meter. The body of the activation request should contain member service set to the string alert and provider set to name of the desired service provider.

Operations

/config/alert/reporter/web/uri

Operations

/config/alert/reporter/web/user

The user name to provide to the web server for authentication purposes. If this string is not empty, the user name and the password are both sent to the web server using HTTP Basic authorization. For security reasons, this should only be used when connecting to the server via an encrypted connection (https).

This resource is available only if /config/alert/reporter/web/service is an empty string.

Operations

/config/alert/sys-prio

The priority of each system-generated alert. /sys/alert provides a description of these alerts.

Operations

/config/alert/sys-prio/{idx}

The priority of this system alert.

Operations

/config/bacnet

Operations

/config/bacnet/server

The BACnet server configuration.

Operations