Loading the API

The DragonFly serves a JavaScript library from its own web server. Load it into your page with a script tag, no download or installation needed:

<script src="http://dragonfly/code.js"></script>

Replace dragonfly with the device hostname or IP address if the default hostname doesn't resolve. This file is served directly by the controller. Once loaded, the API functions and data arrays are available in the page's global scope.

Securing the web page. This code is served by the DragonFly's own internal web server, intended for pages on your observatory network. If you plan to expose that page more widely, read Securing the DragonFly web page (PDF) first.

Reading sensor values—sn[]

The sn[] array contains the current reading of each sensor input. There are 8 sensor channels, indexed 0–7:

// Read sensor 0:
var reading = sn[0];

// Values are integers, 0–1023 (analog range).
// Digital interpretation: below 512 = off, 512 or above = on.
PropertyTypeDescription
sn[0]…sn[7]Integer 0–1023Sensor input reading. Analog sensors return a value across the full range. Digital inputs read near 0 (off) or near 1023 (on). Values below 512 are treated as digital "off".

Reading relay states—rl[]

The rl[] array contains the current state of each relay output. There are 8 relays, indexed 0–7:

// Read relay 0 state:
var roofOpen = rl[0];  // true if closed (energised), false if open
PropertyTypeDescription
rl[0]…rl[7]BooleanCurrent relay state. true = relay is closed (energised). false = relay is open.

Sending relay commands—dflyDo()

Use dflyDo() to send a command to a relay:

dflyDo( address, command, relay, timing );
ParameterTypeDescription
addressStringThe controller hostname or IP address. Use "dragonfly" for the default device name, or its IP address (e.g. "192.168.1.100").
commandStringThe relay action to execute. See command list below.
relayIntegerRelay index to act on, 0–7.
timingIntegerTiming parameter in milliseconds. Used by rlpulse. Pass 0 for commands that don't use it.

Commands

CommandDescription
rlchgToggle—flip the relay to the opposite state.
rlpulsePulse—close the relay for the number of milliseconds given in the timing parameter, then open it.
rlopenOpen the relay (de-energise).
rlcloseClose the relay (energise).

Examples

A dragonFLY control panel web page with a last-refreshed timestamp, a sensors section showing roof closed and mount at sky, and a relays section with a roof pulse button and a CCDs on-off toggle.
A finished page built with the API: two sensors read, two relays controlled.

Toggle relay 0

dflyDo( "dragonfly", "rlchg", 0, 0 );

Pulse relay 3 for 2 seconds

dflyDo( "dragonfly", "rlpulse", 3, 2000 );

Read sensor 2 and display it

var val = sn[2];
document.getElementById("sensor-display").textContent = val;

Show relay state as on/off text

var state = rl[1] ? "ON" : "OFF";
document.getElementById("roof-status").textContent = state;