{"id":5363,"date":"2017-02-16T09:00:54","date_gmt":"2017-02-16T00:00:54","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=5363"},"modified":"2017-08-07T17:11:42","modified_gmt":"2017-08-07T08:11:42","slug":"raspberry-pi%e3%81%aeip%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%82%92chibibitmicrobit%e3%81%a7%e9%80%9a%e7%9f%a5%e3%81%99%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/microbit\/5363","title":{"rendered":"Raspberry Pi\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092Micro:bit(chibi:bit)\u3067\u901a\u77e5\u3059\u308b\u3002"},"content":{"rendered":"<p>Raspberry Pi\u306b\u52d5\u7684\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u305fIP\u30a2\u30c9\u30ec\u30b9\u3092\u3001chibi:bit\u306b\u901a\u77e5\u3057\u3066\u78ba\u8a8d\u3067\u304d\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"550\" data-dnt=\"true\">\n<p lang=\"ja\" dir=\"ltr\">raspberry pi \u306eip\u30a2\u30c9\u30ec\u30b9\u3092chibi:bit\u3067\u901a\u77e5\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u305f\u3002<a href=\"https:\/\/twitter.com\/hashtag\/microbit?src=hash&amp;ref_src=twsrc%5Etfw\">#microbit<\/a> <a href=\"https:\/\/t.co\/UqpqmmL57y\">pic.twitter.com\/UqpqmmL57y<\/a><\/p>\n<p>&mdash; \u6e05\u6c34\u6b63\u884c (@_shimizu) <a href=\"https:\/\/twitter.com\/_shimizu\/status\/829708103343955968?ref_src=twsrc%5Etfw\">February 9, 2017<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>DHCP\u3067\u914d\u5e03\u3055\u308c\u305f\u30a2\u30c9\u30ec\u30b9\u3092\u78ba\u8a8d\u3059\u308b\u3068\u304d\u306a\u3069\u306b\u4f7f\u3048\u307e\u3059\u3002<br \/>\nRaspberry Pi\u3068chibi:bit\u9593\u306e\u901a\u4fe1\u306b\u306fBLE\u3092\u3064\u304b\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u524d\u6e96\u5099<\/h2>\n<p>BLE\u3092\u901a\u3058\u3066chibi:bit\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u305f\u3081\u306b\u3001Raspberry Pi\u306bnode.js\u3068<br \/>\n\u4eca\u56de\u4f7f\u7528\u3057\u305fRaspberry Pi 3\u306b\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067node.js\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u53e4\u304b\u3063\u305f\u306e\u3067\u3001\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u30d8\u30eb\u30d7\u3092\u53c2\u8003\u306bver.6.x\u306enode.js\u3092\u518d\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/nodejs.org\/en\/download\/package-manager\/#debian-and-ubuntu-based-linux-distributions\">Installing Node.js via package manager | Node.js<\/a><\/p>\n<pre class=\"lang:sh decode:true \" >curl -sL https:\/\/deb.nodesource.com\/setup_6.x | sudo -E bash -\r\nsudo apt-get install -y nodejs<\/pre>\n<p>node.js\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u7d42\u308f\u3063\u305f\u3089\u3001micro:bit\u306eBLE\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<br \/>\nnode-bbc-microbit\u306fnoble\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092Raspberry Pi \u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5148\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/sandeepmistry\/noble#ubuntudebianraspbian\">noble<\/a><\/p>\n<pre class=\"lang:sh decode:true \" >sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev<\/pre>\n<p><a href=\"https:\/\/github.com\/sandeepmistry\/node-bbc-microbit\">node-bbc-microbit: Control a BBC micro:bit from Node.js using BLE<\/a><\/p>\n<pre class=\"lang:sh decode:true \" >npm install bbc-microbit<\/pre>\n<p>chibi:bit\u5074\u3067\u306f\u3001node-bbc-microbit\u306eREADME\u306b\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u300c<a href=\"https:\/\/github.com\/sandeepmistry\/node-bbc-microbit#flashing-microbit-firmware\">Flashing micro:bit firmware<\/a>\u300d\u306e\u5de5\u7a0b\u3092\u6e08\u307e\u305b\u3066\u304a\u3044\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n<p>chibi:bit\u306eA\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001LED\u306bRaspberry Pi\u306eIP\u30a2\u30c9\u30ec\u30b9\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >var os = require('os')\r\nvar BBCMicrobit = require('bbc-microbit')\r\nvar BUTTON_VALUE_MAPPER = ['Not Pressed', 'Pressed', 'Long Press']\r\n\r\n\r\nconsole.log('chibi:bit\u3092\u691c\u7d22\u3057\u3066\u3044\u307e\u3059')\r\nvar discoverMcrobit = new Promise(function(resolve, reject){\r\n    BBCMicrobit.discover(function(microbit) {\r\n        console.log('\\tchibi:bit\u3092\u767a\u898b\u3057\u307e\u3057\u305f: id = %s, address = %s', microbit.id, microbit.address)\r\n        microbit.on('disconnect', function() {\r\n          console.log('\\t\u63a5\u7d9a\u30a8\u30e9\u30fc\uff01\uff1achibi:bit\u306b\u63a5\u7d9a\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f')\r\n          process.exit(0);\r\n        })\r\n    \r\n        resolve(microbit)\r\n    })    \r\n})\r\n\r\nvar subscribeButtons = function(microbit){\r\n    return new Promise(function(resolve, reject){\r\n        microbit.connectAndSetUp(function() {\r\n          console.log('\\t\u63a5\u7d9a\u3057\u307e\u3057\u305f')\r\n        \r\n            microbit.subscribeButtons(function() {\r\n                console.log('\\t\u30dc\u30bf\u30f3\u5165\u529b\u3092\u53d7\u4ed8\u4e2d')\r\n                resolve(microbit)\r\n            })\r\n        })\r\n    })    \r\n}\r\n\r\nvar onClickButtons = function(microbit){\r\n    return new Promise(function(resolve, reject){\r\n        microbit.on('buttonAChange', function(value) {\r\n            console.log('\\ton -&gt; button A change: ', BUTTON_VALUE_MAPPER[value])\r\n            if (BUTTON_VALUE_MAPPER[value] === \"Pressed\")\r\n                microbit.writeLedText(getLocalAddress().ipv4[0].address, function() {\r\n                    console.log('\u30c6\u30ad\u30b9\u30c8\u9001\u4fe1\uff1a \"%s\"', getLocalAddress().ipv4[0].address)            \r\n                })                        \r\n        })\r\n        \r\n        microbit.on('buttonBChange', function(value) {\r\n            console.log('\\ton -&gt; button B change: ', BUTTON_VALUE_MAPPER[value])\r\n            if (BUTTON_VALUE_MAPPER[value] === \"Pressed\")\r\n                microbit.writeLedText(getLocalAddress().ipv6[0].address, function() {\r\n                    console.log('\u30c6\u30ad\u30b9\u30c8\u9001\u4fe1\uff1a \"%s\"', getLocalAddress().ipv6[0].address)            \r\n                })                        \r\n        })\r\n\t\t\r\n\t\tresolve(microbit)\r\n    })    \r\n}\r\n\r\n\/\/ip\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3059\u308b\r\nfunction getLocalAddress() {\r\n    var ifacesObj = {}\r\n    ifacesObj.ipv4 = []\r\n    ifacesObj.ipv6 = []\r\n    var interfaces = os.networkInterfaces()\r\n\r\n    for (var dev in interfaces) {\r\n        interfaces[dev].forEach(function(details){\r\n            if (!details.internal){\r\n                switch(details.family){\r\n                    case \"IPv4\":\r\n                        ifacesObj.ipv4.push({name:dev, address:details.address})\r\n                    break;\r\n                    case \"IPv6\":\r\n                        ifacesObj.ipv6.push({name:dev, address:details.address})\r\n                    break;\r\n                }\r\n            }\r\n        })\r\n    }\r\n    return ifacesObj\r\n}\r\n\r\n\r\n\r\ndiscoverMcrobit.then(subscribeButtons).then(onClickButtons)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Raspberry Pi\u306b\u52d5\u7684\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u305fIP&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5316,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-5363","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microbit","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=5363"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5363\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/5316"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=5363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=5363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=5363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}