Imp Build
A Javascript wrapper for the Electric Imp Build API.
NOTE: Electric Imp's Build API is currently in a closed beta. This note will be removed when the API is ready for public consumption.
Installation
npm install imp-api
Instantation
The imp object must be instantiated with an apiKey - you can optionally pass an apiBase and apiVersion parameter to overload the defaults.
var Imp = ; var imp = "apiKey": "<-- YOUR API KEY -->";
Devices
imp.getDevices(options, callback)
Returns a list of devices associted to the account. You can pass a table with any of the following options to filter the list: device_id
, mac_address
, model_id
, name
.
// get all devices with 'test' in the nameimp
imp.getDevice(deviceId, callback)
Returns information about a specific device.
imp;
imp.assignDevice(deviceId, modelId, callback)
Assigns a device to a specific model, and immediatly starts running the code.
imp;
Passing null
as the modelId will unassign the device from it's current model.
imp.deleteDevice(deviceId, callback)
Deletes a device from your account (note: the next time the device comes online / communicates with the Electric Imp service it will re-register itself with your account).
imp;
Device Logs
imp.getDeviceLogs(deviceId, options, callback)
Returns up to the last 200 messages from a specified device and its agent. You can pass a table with any of the following options to filter the list: since
(), type
().
// Get agent messagesimp;
imp.streamDeviceLogs(deviceId, callback)
Continuously streams logs from the specified device and its agent. Each time new logs appear, the callback will be invoked:
imp;
Models
imp.getModels(options, callback)
Returns a list of models associted to the account. You can pass a table with any of the following options to filter the list: name
.
// get all models with 'test' in the nameimp
imp.getModel(modelId, callback)
Returns information about a specific model.
imp;
imp.createModel(options, callback)
Creates a new model in the associated account.
imp;
imp.restartModel(modelId, callback)
Restarts all devices and agents associated to a model.
imp;
imp.deleteModel(modelId, callback)
Deletes the specified model and all code associated with it - you cannot delete a model that has devices assigned to it.
imp;
Model Revisions
imp.getModelRevisions(modelId, options, callback)
Returns a list of code revisions for the specified model. You can pass a table with any of the following options to filter the list: since
, until
, build_min
, build_max
.
// 1800000 milliseconds = 30 minutesvar thirtyMinutesAgo = Date - 1800000; imp;
imp.getModelRevision(modelId, version, callback)
Returns the code and metadata of a specified version.
imp;
imp.createModelRevision(modelId, model, callback)
Pushes a new revision to the model. After creating a new revision, you need to call restartModel
for the code to be sent to the devices assigned to the specified model. The model object must contain agent_code
and device_code
and can also include release_notes
and marker
(63 characters max that can be used like GIT tags).
var deviceCode = "server.log(\"Device Started!\");";var agentCode = "server.log(\"Agent Started!\");"; var model = "device_code": deviceCode "agent_code": agentCode ; imp;
LICENSE
imp.js is licenced under the MIT License.