Nonolith Labs
Wiki
wiki cee Simple REST API V1 EditNonolith Connect V1.1 adds a simple REST API for scripting your CEE.
Overview
The Nonolith Connect server runs on http://localhost:9003
Access control
By default, Nonolith Connect listens only for connections coming from the local machine. Requests submitted from a web browser will be rejected unless they come from a file://
, localhost
, or nonolithlabs.com
origin. A Javascript library to allow access from other origins with user permission is coming shortly.
The allow-remote
and allow-any-origin
command line parameters to nonolith-connect
disable these checks. (Not recommended).
Device List
List devices
GET /rest/v1/devices
Example
$ curl http://localhost:9003/rest/v1/devices
Response
{
"com.nonolithlabs.cee~137423432303FFFF60FF91001200" : {
"id" : "com.nonolithlabs.cee~137423432303FFFF60FF91001200",
"model" : "com.nonolithlabs.cee",
"hwVersion" : "1.0",
"fwVersion" : "1.0",
"serial" : "137423432303FFFF60FF91001200"
}
}
Device
Get device info
GET /rest/v1/devices/devid
Note: devid
is the id from the device list response. You can use com.nonolithlabs.cee*
as a devid
if only one device is present. If writing code that may be used by others, it is recommended to allow the device id to specified so multiple devices can be differentiated.
Returns a JSON description of the device, more detailed and device-specific than the one in the master devices list.
Example
$ curl 'http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*'
Response
{
"id" : "com.nonolithlabs.cee~137423432303FFFF60FF91001200",
"model" : "com.nonolithlabs.cee",
"hwVersion" : "1.0",
"fwVersion" : "1.0",
"serial" : "137423432303FFFF60FF91001200",
"sampleTime" : 0.0001,
"mode" : 0,
"samples" : 120001,
"length" : 12.0001,
"continuous" : true,
"raw" : false,
"captureState" : false,
"captureDone" : false,
"channels" : {
"a" : {
"id" : "a",
"displayName" : "A",
"output" : {
"mode" : 0,
"startSample" : 0,
"effective" : false,
"source" : "constant",
"value" : 0
},
"streams" : {
"v" : {
"id" : "v",
"displayName" : "Voltage A",
"units" : "V",
"min" : 0,
"max" : 5,
"outputMode" : 1,
"gain" : 1,
"uncertainty" : 0.002441
},
"i" : {
"id" : "i",
"displayName" : "Current A",
"units" : "mA",
"min" : -200,
"max" : 200,
"outputMode" : 2,
"gain" : 1,
"uncertainty" : 1
}
}
},
"b" : {
"id" : "b",
"displayName" : "B",
"output" : {
"mode" : 0,
"startSample" : 0,
"effective" : false,
"source" : "constant",
"value" : 0
},
"streams" : {
"v" : {
"id" : "v",
"displayName" : "Voltage B",
"units" : "V",
"min" : 0,
"max" : 5,
"outputMode" : 1,
"gain" : 1,
"uncertainty" : 0.002441
},
"i" : {
"id" : "i",
"displayName" : "Current B",
"units" : "mA",
"min" : -200,
"max" : 200,
"outputMode" : 2,
"gain" : 1,
"uncertainty" : 1
}
}
}
}
}
Start/stop streaming
POST /rest/v1/devices/devid
POST parameters
- capture
-
on
,off
-- turn on/off the CEE
Examples
$ curl http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*/ -dcapture=on
$ curl http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*/ -dcapture=off
Device configuration
Get configuration
GET /rest/v1/devices/devid/configuration
Returns a JSON object representing the configuration of the device
Configure device
POST /rest/v1/devices/devid/configuration
Adjust the device configuration. Resets the data buffer and leaves the device paused.
POST parameters
- sampleTime
- Time in seconds per sample.
0.000025
is 40ksps - samples
- Number of samples of history to keep in buffer
- currentLimit
- The current limit, in mA. Value must be 200, 400, or 2000. Be careful.
Channel input stream
Read input data
GET /rest/v1/devices/devid/{a,b}/input
Get input samples from the device. Results are comma-separated channels, newline-separated samples.
GET parameters
- resample
- Time in seconds to average data over (default:
0.01
). Use0
for no resampling. - count
- Number of samples to return, default
1
. Pass-1
for infinite (HTTP reply never ends). - start
- Sample index at which to start, used to synchronize input and output. Default is the latest sample.
- header
- Show a header describing the columns and units (
1
; default), or hide it (0
).
Example
$ curl 'http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*/a/input?resample=1&count=3'
Response
Voltage A (V),Current A (mA)
1.61631, 0
1.61599, 0
1.61562, 0
Note that the response blocks until the samples are available. If the device is not streaming, it may wait indefinitely.
Set gain
POST /rest/v1/devices/devid/{a,b}/input
POST parameters
- gain_v
- The voltage gain. Value is
1
,2
,4
,8
,16
,32
, or64
- gain_i
- The current gain. Value is
0.5
,1
,2
,4
,8
,16
, or32
.
The input GET data will have the gain applied, however, it will be clamped at the limit imposed by the gain (e.g. a voltage gain of 2 means the maximum voltage reading is clamped to 2.5V).
Channel output
Get output configuration
GET /rest/v1/devices/devid/{a,b}/output
JSON format. TODO
Set output
POST /rest/v1/devices/devid/{a,b}/output
Set the output source for a channel a
or b
. Units are as specified by the device resource (V for voltage source, mA for current source.
POST parameters
- mode
-
disabled
= high-impedance, output driver disabled
svmi
= source voltage
simv
= source current
- wave
constant
(default),square
,triangle
,sine
, oradv_square
. Additional specific options for each are explained below.
Constant
For constant
wave:
- value
- The constant value to output.
Example
Set a constant 3V
$ curl 'http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*/a/output' -dmode=svmi -dvalue=3
Square, Triangle, and Sine
For
square
,triangle
, orsine
wave:- value
- The center value of the wave
- amplitude
- the amplitude of the wave (center to peak)
- frequency
- frequency in Hz
- relPhase
0
for the phase to be relative to the stream start,1
(default) for the phase to be based on the previous wave for seamless change in frequency.- phase
- the phase offset in seconds from the beginning of the stream (relPhase=0) or from the previous source (relPhase=1)
Example
Source a full-amplitude, 2.5V ± 2.5V sine wave at 100Hz.
$ curl 'http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*/a/output' -dmode=svmi -dwave=sine -dvalue=2.5 -damplitude=2.5 -dfrequency=100
Rectangle / Pulse Width
The
adv_square
wave type allows square waves that are not symmetrical.- value1
- Value to source for the first part of the cycle
- time1
- Time in seconds to source value1
- value2
- Value to source for the second part of the cycle
- time2
- Time in seconds to source value2
Arbitrary waveform generation
Added in Nonolith Connect 1.2
The
arb
wave allows a user-defined waveform.- points
- Comma separated string of `time:value` pairs for points in the wave. The first time must be 0, and times must be sorted. Trapezoidal interpolation is used between the points. Use two points with the same time value to switch between values immediately.
- repeat
- Number of times to repeat the waveform. `-1` means infinite. Default is `1`.
- phase
- Offset of the start time in seconds. `-1` means to start at the time the source takes effect .
If repeat is disabled, the value of the last point remains until another output source is set.
Example
curl 'http://localhost:9003/rest/v1/devices/com.nonolithlabs.cee*/a/output' -d'wave=arb' -d'mode=svmi' -d'points=0:0,1:3,1.5:3,1.5:1' -d'repeat=0'
results in