Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Background

...

  • An HTTP POST request to a monitoring server within the local network
  • The application should have a configurable monitoring server IP address and port.
  • Example of payload / body: '{ "arg": { "version": "1.0.1", "localtime": "2018-11-16T12:34:23.234Z" } }'
  • Request header has to contain "Content-type: application/json"
  • Configurable heartbeat interval with a default of 120 seconds
  • Configurable on/off state to enable or disable the heartbeat
  • The overall experience is not impacted by a slow response from the monitoring service.

...

  • arg: object  containing:
    • version: string – release number (following semantic versioning)
    • localtime: string – local time of the device (ISO8601) YYYY-MM-DDTHH:mm:ss.sssZ

Testing

You can test your heartbeat by posting to port 443 on httpson https://heartbeatdev.exhibition.tepapa.govt.nz/heartbeat/<product-name>

Please note this is an interim testing endpoint using SSL - you do not need to support SSL in your interactive, an HTTP endpoint will be available soon.

Unity3D Example Code

As an example, we used the following example as an implementation prototype to send a heartbeat request to Te Papa's HTTP monitoring endpoint.

Parameters

  • bodyJson: string - the JSON string of the payload following the implementation specification
  • heartbeatURL: string - URL, incl. protocol, domain name/IP, post and path on server
  • heartbeatTimeout: int - HTTP timeout (in seconds)

Please consider that heartbeatURL and heartbeatTimeout shall be configurable as well as the interval (in seconds) of the heartbeat.

Code Block
languagec#
themeEclipse
titleHeartbeat example
[...]
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes( bodyJson );

UnityWebRequest request = new UnityWebRequest( heartbeatURL, "POST");

request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.chunkedTransfer = false; 
request.timeout = heartbeatTimeout;

request.SetRequestHeader("Content-Type", "application/json");

yield return request.SendWebRequest();

if (request.isNetworkError || request.isHttpError) {
    if (!request.error.Contains("no data in response")) {
        Debug.Log("Heartbeat:" + request.error));
    }
}
[...]