Node.jsã使ã£ã¦shellã³ãã³ããå©ã
Raspberry Piã«å ¥ããNode.jsã使ã£ã¦ãã·ã§ã«ãå©ãæ¹æ³ã®ã¡ã¢ã
åèã«ããã®ã¯ã以ä¸ã®ããã°ã
Node.jsã§shellã³ãã³ããå©ã - PolyPeaceLight
Node.jsããSlackã«æ稿ããPythonã¹ã¯ãªãããåããã¦ã¿ãã
ã¾ãã¯ãé©å½ãªãã£ã¬ã¯ããªã«ç§»åããjsãã¡ã¤ã«ãä½ãã
$ vi shelltest.js
 以ä¸ã®ãµã³ãã«ã³ã¼ããæ¸ãã
var exec = require('child_process').exec;
var child;
child = exec("python slacktest.py", function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null {
console.log('exec error: ' + error);
}
});
ã¡ãªã¿ã«ãslacktest.pyã¯ä»¥ä¸ã®ãããªã³ã¼ãã«ãªã£ã¦ããã
#Slack Post Test
from slacker import Slacker
token = "Your Token èªåã®ãã¼ã¯ã³ã«å¤ãã¦ã"
slacker = Slacker(token)
channel_name = "#" + "general"
message = "API test by Script"
slacker.chat.post_message(channel_name, message, username='test')
ãããã¿ã¼ããã«ãã
$ node shelltest.js
ã¨ãã¤ã¨ã
æ稿ã§ãããã¨ã確èªã§ããã
Node.jsããRaspberry Pi 3ã®ã«ã¡ã©ãåããã¦ã¿ãã
ã次ã¯ããå°ãè¤éãªã¹ã¯ãªãããåãããã¨ã«ææ¦ãããåèã«ããã®ã¯ãã®ãµã¤ãã
Raspberry Pi, Camera and Node.js - Live Streaming with Websockets #IoT | The Jackal of Javascript
é©å½ãªãã¡ã¤ã«åã®jsãã¡ã¤ã«ãä½ãã
$ vi raspistilltest.js
 以ä¸ã®ãããªã³ã¼ããæ¸ãã
var spawn = require('child_process').spawn;
var proc;
var args = ["-w","640","-h","480","-o","/home/pi/Pictures/image_stream.jpg"]
proc = spawn('raspistill',args);
raspistillã³ãã³ããå®è¡ããã ãã®ãã¡ã¤ã«ã«ãªãã/home/pi/Picutres/image_stream.jpgãã§ãã¦ããã°æåã«ãªãã
$ node raspistilltest.js
 å®è¡ããã¨ãã
ã§ããï¼image_stream.jpgã確èªã§ããã
raspistillã§æ®å½±âãããä½ããCloud Visionã§èå¥ãã
ããããçµã¿åããããã¨ã§ãNode.jsãç¨ãã¦ãraspistillã§æ®å½±ãè¡ãããã®ç»åãGoogle Cloud Visionã§å¤å¥ããããã°ã©ã ãä½ã£ãã
ã¾ããcloudvisionã®ãã£ã¬ã¯ããªã«ç§»åããé©å½ãªååã®jsãã¡ã¤ã«ãä½ãã
$ cd /home/pi/projects/cloudvision
$ vi cameratest.js
次ã«ã³ã¼ããæ¸ãã¦ãããå 容ã¨ãã¦ã¯ãä¸è¨raspistillã®é ã§èª¬æããã³ã¼ãã¨ãCloudVisionã®è¨äºã§ç´¹ä»ããã³ã¼ãã®çµã¿åããã ã
var spawn = require('child_process').spawn;
var proc;
var args = ["-w", "640", "-h", "480","-o","/home/pi/Pictures/image_stream.jpg"]
proc = spawn('raspistill', args);
'use strict'
const vision = require('node-cloud-vision-api')
// init with auth
vision.init({auth: 'Your API Key'})
// construct parameters
const req = new vision.Request({
 image: new vision.Image('/home/pi/Pictures/image_stream.jpg'),
 features: [
   //new vision.Feature('FACE_DETECTION', 4),
   new vision.Feature('LABEL_DETECTION', 10),
 ]
})
// send single request
vision.annotate(req).then((res) => {
 // handling response for each request
 console.log(JSON.stringify(res.responses))
}, (e) => {
 console.log('Error: ', e)
})
ãããä¿åãã
$ node cameratest.js
ã¨ãã¦å®è¡ããã¨ãä¸ã®ãããªåçãæ®å½±ããã
ã³ã³ã½ã¼ã«ã«ã¯ä»¥ä¸ãåºåãããã
è¦ã«ããã®ã§ãããã¤ãçµæãæ¸ãåºãã¦ã¿ãã¨ã
- meal (ã飯)
- breakfast (æé£)
- furniture (å®¶å ·)
ãªã©ã®çµæã確èªã§ããããã ã
- sink (ã·ã³ã¯)
- plumbing fixture (é 管ã®é¨å)
- swimming pool (ã¹ã¤ãã³ã°ãã¼ã«)
ã¨ã®çµæãåºã¦ããã
ãããããã®åçã¾ãããã«æ®ãã¦ããç¬
Â
Â
Â