Update

Update a device record

Update will alter the device record in Meshblu. Allows the use of $set, $inc, $push, etc. operators as documented in the MongoDB API

var ws = new WebSocket("wss://meshblu.octoblu.com/ws/v2"); ws.send(JSON.stringify([ "update", [ { "uuid":"26de691f-8068-4cdc-907a-4cb5961a1aba", "token":"2e924d1a9cad175ba91f120ede720d50010cd966" }, { "$set": { "color": "blue" } } ] ]));
var MeshbluWebsocket = require('meshblu-websocket'); var MeshbluConfig = require('meshblu-config'); var meshbluConfig = new MeshbluConfig().toJSON(); var meshblu = new MeshbluWebsocket(meshbluConfig); meshblu.connect(function(error){ if (error) { console.error(error.message); } meshblu.subscribe({uuid: meshbluConfig.uuid}); meshblu.on('config', function(data){ console.log('config', data); }); meshblu.updateDangerously({ uuid: meshbluConfig.uuid, token: meshbluConfig.token }, { '$push': { stuff: { foo: 'bar' } } }); });

❗️

Risk of Token Deletion

If a request is made without any operators prefixed by '$', it is assumed to be the new, full representation of the device. This means that all operators that are not mentioned, such as the token, will be unset.

var ws = new WebSocket("wss://meshblu.octoblu.com/ws/v2"); ws.send(JSON.stringify([ "update", [ { "uuid":"26de691f-8068-4cdc-907a-4cb5961a1aba", "token":"2e924d1a9cad175ba91f120ede720d50010cd966" }, { "name": "in deep, deep trouble" } ] ])); # This will unset the token and owner, making the device completely unaccessible!

Success

If you successfully update you will receive a config and an updated message

📘

Subscribe Required

Be sure to subscribe in order to receive the config message.

[ "config", { "uuid":"26de691f-8068-4cdc-907a-4cb5961a1aba", "token":"2e924d1a9cad175ba91f120ede720d50010cd966", "status":200 } ] [ "updated", { "uuid":"26de691f-8068-4cdc-907a-4cb5961a1aba" } ]

Failure

On update failure, you will receive a error message

[ "error", { "frame":["config",{"uuid":"26de691f-8068-4cdc-907a-4cb5961a1aba","token":"2e924d1a9cad175ba91f120ede720d50010cd966","status":200}], "message": "failed to update" } ]

Did this page help you?