{"__v":0,"_id":"556746831c38390d006980a9","category":{"__v":4,"_id":"556741d87acd550d0075eacb","pages":["556745611c38390d006980a2","556745c977c15523002fd58a","556746391c38390d006980a7","556746831c38390d006980a9"],"project":"5564f26a1fd04c0d00dc9aaa","version":"5564f26a1fd04c0d00dc9aad","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-28T16:27:04.708Z","from_sync":false,"order":9,"slug":"demos","title":"Demos"},"parentDoc":null,"project":"5564f26a1fd04c0d00dc9aaa","user":"5564f227f0f70f0d00a9ab20","version":{"__v":15,"_id":"5564f26a1fd04c0d00dc9aad","project":"5564f26a1fd04c0d00dc9aaa","createdAt":"2015-05-26T22:23:38.671Z","releaseDate":"2015-05-26T22:23:38.671Z","categories":["5564f26b1fd04c0d00dc9aae","556741d17acd550d0075eaca","556741d87acd550d0075eacb","556742f87acd550d0075ead1","556781cd6976ef0d0099c545","5568d666d33aad0d00ec8d2e","557f6b2d38249b0d00d0d12b","55b67be9c2e909190073ed38","564e56c601e80e0d00396684","56731b714b2a680d00524daf","573612ac652bd80e00a90027","57365e2cf8ebd31700769f50","57366131f8ebd31700769f58","573b93514e029d19000b8669","573bbfdb7ac6f6170033bd35"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-28T16:46:59.726Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"Start by:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"npm install ar-drone\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nCreate a file called \"index.js\" with the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var five = require('johnny-five'), led;\\nvar meshblu = require('meshblu');\\n\\nvar conn = meshblu.createConnection({\\n    \\\"uuid\\\": \\\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\\\",\\n    \\\"token\\\": \\\"yyyyyyyyyyyyyyyyyyyyyyyy\\\"\\n});\\n\\nconn.on('ready', function(data){\\n\\n    console.log(\\\"Connected to Meshblu\\\");\\n    conn.on('message', function(databits){\\n        console.log(databits);\\n        data = JSON.parse(databits);\\n\\n        if (data.payload.fly == \\\"up\\\") {\\n            client.takeoff();\\n        } else if (data.payload.fly == \\\"down\\\") {\\n            client.land();\\n        } else if (data.payload.fly == \\\"stop\\\") {\\n            client.stop();\\n        } else if (data.payload.fly == \\\"spin\\\") {\\n            client.clockwise(0.5);\\n        } else if (data.payload.fly == \\\"flip\\\") {\\n            client.animate('flipLeft', 1000);\\n        } else if (data.payload.red == \\\"on\\\") {\\n            client.animateLeds('blinkRed', 5, 2)\\n        } else if (data.payload.red == \\\"off\\\") {\\n            client.animateLeds('blinkRed', 0, 0)\\n        } else if (data.payload.green == \\\"on\\\") {\\n            client.animateLeds('blinkGreen', 5, 2)\\n        } else if (data.payload.green == \\\"off\\\") {\\n            client.animateLeds('blinkGreen', 0, 0)\\n        } else if (data.payload.demo == true) {\\n            client.takeoff();\\n            client\\n            .after(5000, function() {\\n                this.clockwise(0.5);\\n            })\\n            .after(3000, function() {\\n                this.stop();\\n                this.land();\\n            });\\n        }\\n    });\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nOpen our JS Console. You can interact with your new Node.JS app by typing these commands in your browser's developer console:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Fly demo! You can also send {\\\"fly\\\":\\\"up\\\"} or {\\\"fly\\\":\\\"down\\\"} or {\\\"fly\\\":\\\"spin\\\"} etc as the payload!\\nconn.message({\\n  \\\"devices\\\": \\\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\\\",\\n  \\\"payload\\\": {\\\"demo\\\": true}\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"Use Octoblu to fly a NodeCopter drone!","slug":"fly-a-nodecopter-drone","type":"basic","title":"Fly a NodeCopter Drone"}

Fly a NodeCopter Drone

Use Octoblu to fly a NodeCopter drone!

Start by: [block:code] { "codes": [ { "code": "npm install ar-drone", "language": "text" } ] } [/block] Create a file called "index.js" with the following code: [block:code] { "codes": [ { "code": "var five = require('johnny-five'), led;\nvar meshblu = require('meshblu');\n\nvar conn = meshblu.createConnection({\n \"uuid\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n \"token\": \"yyyyyyyyyyyyyyyyyyyyyyyy\"\n});\n\nconn.on('ready', function(data){\n\n console.log(\"Connected to Meshblu\");\n conn.on('message', function(databits){\n console.log(databits);\n data = JSON.parse(databits);\n\n if (data.payload.fly == \"up\") {\n client.takeoff();\n } else if (data.payload.fly == \"down\") {\n client.land();\n } else if (data.payload.fly == \"stop\") {\n client.stop();\n } else if (data.payload.fly == \"spin\") {\n client.clockwise(0.5);\n } else if (data.payload.fly == \"flip\") {\n client.animate('flipLeft', 1000);\n } else if (data.payload.red == \"on\") {\n client.animateLeds('blinkRed', 5, 2)\n } else if (data.payload.red == \"off\") {\n client.animateLeds('blinkRed', 0, 0)\n } else if (data.payload.green == \"on\") {\n client.animateLeds('blinkGreen', 5, 2)\n } else if (data.payload.green == \"off\") {\n client.animateLeds('blinkGreen', 0, 0)\n } else if (data.payload.demo == true) {\n client.takeoff();\n client\n .after(5000, function() {\n this.clockwise(0.5);\n })\n .after(3000, function() {\n this.stop();\n this.land();\n });\n }\n });\n});", "language": "javascript" } ] } [/block] Open our JS Console. You can interact with your new Node.JS app by typing these commands in your browser's developer console: [block:code] { "codes": [ { "code": "// Fly demo! You can also send {\"fly\":\"up\"} or {\"fly\":\"down\"} or {\"fly\":\"spin\"} etc as the payload!\nconn.message({\n \"devices\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n \"payload\": {\"demo\": true}\n});", "language": "javascript" } ] } [/block]