Opensource H/W + Node JS IoT 따라잡기 Day 3
Make
Raspberry Pi Audio
Raspberry Pi Robot
Youtube API
Youtube API 사용하기 https 3/get https://developers.google.com/youtube/v3/getting-started 1. 구글 계정 등록 하기 2. API 요청을 위한 Google Application 등록 https://console.developers.google.com/project 3. Youtube Data API 설정 https://developers.google.com/youtube/v3/ https://github.com/google/google-api-nodejs- client/tree/master/examples
Youtube API 사용하기 https 3/get https://developers.google.com/youtube/v3/getting-started 1. 구글 계정 등록 하기 2. API 요청을 위한 Google Application 등록 https://console.developers.google.com/project 3. Youtube Data API 설정 https://developers.google.com/youtube/v3/ https://github.com/google/google-api-nodejs- client/tree/master/examples
Youtube API 사용하기 https 3/get https://github.com/fvdm/nodejs-youtube/wiki Google API 모듈 설치 $ npm install googleapis NodeJS 선언 var google = require ('googleapis'); google.options ({ auth: 'API KEY' }); var youtube = google.youtube ('v3');
Youtube API 사용하기 youtube.search.list ( { part: 'snippet', type: 'video', q: query, maxResults: 50, order: 'date', safeSearch: 'moderate', videoEmbeddable: true }, function (err, res) { if (err) { return callback (err); } res.items.forEach (function (result) { } });
Youtube API 사용하기 { id: 'THA_5cqAfCQ', urlShort: 'http://youtu.be/THA_5cqAfCQ', urlLong: 'http://www.youtube.com/watch?v=THA_5cqAfCQ', published: '2012-12-03T15:58:45.000Z', title: 'Cheetahs on the Edge — Director's Cut', description: 'Cheetahs are the fastest runners on the planet. Combining the resources of National Geographic and the Cincinnati Zoo, and drawing on the skills of a Hollywo.', images: { default: { url: 'https://i.ytimg.com/vi/THA_5cqAfCQ/default.jpg' }, medium: { url: 'https://i.ytimg.com/vi/THA_5cqAfCQ/mqdefault.jpg' }, high: { url: 'https://i.ytimg.com/vi/THA_5cqAfCQ/hqdefault.jpg' } }, channelTitle: 'NationalGeographic', channelId: 'UCpVm7bg6pXKo1Pr6k5kxG9A', live: 'none', duration: 428, definition: 'hd' }
Raspberry Pi Audio 실습
라즈베리파이 오디오 (Close Ver) 1. 스마트 폰으로 인터넷 음악을 검색 함 2. 라즈베리파이 서버에서 유투브를 통해 해당 결과 검색 3. 검색 결과에서 듣고 싶은 음악을 선택 4. 선택한 영상을 유튜브에서 다운로드 함 5. 다운로드가 완료되면 라즈베리파이 오디오에서 재생시작 6. 재생 정보를 LCD 에 디스플레이 함
필요 부속
Package Install 유튜브 검색을 위한 패키지 v2 – youtube-feeds V3 – youtube-api $ npm install youtube-feeds 유투브 영상 다운로드를 위한 패키지 $ npm install ytdl 미디어 플레이어 설치 $ npm install omxcontrol
Source Code var down = exec("ytdl http://www.youtube.com/watch?v=" + data.name + ' > '+ data.name + '.mp4 -q highest', function(err, stdout, stderr) { if (err){ console.log('Error : ' + err); } else { console.log('download complete, start!'); //omx.quit(); $s.send('play', true ); omx.start(data.name + '.mp4'); } });
Source Code youtube.feeds.videos({q: data.name}, function(err, data){ if(err instanceof Error){ console.log(err); } else { console.log(data.items.length); var arr = []; for(var i = 0 ; i < data.items.length ; i++){ var item = data.items[i]; arr.push({ id : item.id, desc : item.description, title : item.title, date : item.updated, count : item.viewCount }); } } });
Speaker - Module 3.5 mm (Sound) USB (Power)
문제점 1. 라즈베리파이 서버에 접속할 수 있는 근접 거리 (Raspberry Pi WiFi 영역) 에서만 서버에 접속할 수 있음 2. IoT 는 외부/물리적으로 떨어진 공간에서 해당 장치를 제 어해야 하는데, 현 시스템은 불가능 해결책 1. 공인 IP를 라즈베리파이에 적용 -> 공인 IP 의 가격이 비싸서 적용하기 힘듦
라즈베리파이 오디오 (Open Ver) 1. 스마트 폰으로 인터넷 음악을 검색 함 2. 라즈베리파이 서버에서 유투브를 통해 해당 결과 검색 3. 검색 결과에서 듣고 싶은 음악을 선택 4. 선택한 영상을 유튜브에서 다운로드 함 5. 다운로드가 완료되면 라즈베리파이 오디오에서 재생시작 6. 재생 정보를 LCD 에 디스플레이 함
Package Install IoT 개발 지원 module 설치 $ npm install circulus
Source Code // raspberry pi var ccus = require(‘circulus’); // general doc ccus.tts([메세지], [언어]); ccus.receive([method 명], callback); ccus.send([method 명], callback); ccus.set(key, value); ccus.get(key);
Source Code // sensor doc var ccus = require(‘circulus’); var cs = ccus.sensor; cs.getDistance cs.getLight cs.getSound cs.getGyro cs.getTemp cs.getHumidity cs.getEnviorn
Expand your dimension Circulus (http://www.circul.us) Since 2013 Park Jonggun, Lee Yunjai, Ki Yeonah, Lee Jonghee

IoT with Raspberry Pi + Node JS - Chapter 3

  • 1.
    Opensource H/W +Node JS IoT 따라잡기 Day 3
  • 2.
  • 7.
  • 8.
  • 9.
  • 10.
    Youtube API 사용하기 https 3/get https://developers.google.com/youtube/v3/getting-started 1.구글 계정 등록 하기 2. API 요청을 위한 Google Application 등록 https://console.developers.google.com/project 3. Youtube Data API 설정 https://developers.google.com/youtube/v3/ https://github.com/google/google-api-nodejs- client/tree/master/examples
  • 11.
    Youtube API 사용하기 https 3/get https://developers.google.com/youtube/v3/getting-started 1.구글 계정 등록 하기 2. API 요청을 위한 Google Application 등록 https://console.developers.google.com/project 3. Youtube Data API 설정 https://developers.google.com/youtube/v3/ https://github.com/google/google-api-nodejs- client/tree/master/examples
  • 12.
    Youtube API 사용하기 https 3/get https://github.com/fvdm/nodejs-youtube/wiki GoogleAPI 모듈 설치 $ npm install googleapis NodeJS 선언 var google = require ('googleapis'); google.options ({ auth: 'API KEY' }); var youtube = google.youtube ('v3');
  • 13.
    Youtube API 사용하기 youtube.search.list( { part: 'snippet', type: 'video', q: query, maxResults: 50, order: 'date', safeSearch: 'moderate', videoEmbeddable: true }, function (err, res) { if (err) { return callback (err); } res.items.forEach (function (result) { } });
  • 14.
    Youtube API 사용하기 {id: 'THA_5cqAfCQ', urlShort: 'http://youtu.be/THA_5cqAfCQ', urlLong: 'http://www.youtube.com/watch?v=THA_5cqAfCQ', published: '2012-12-03T15:58:45.000Z', title: 'Cheetahs on the Edge — Director's Cut', description: 'Cheetahs are the fastest runners on the planet. Combining the resources of National Geographic and the Cincinnati Zoo, and drawing on the skills of a Hollywo.', images: { default: { url: 'https://i.ytimg.com/vi/THA_5cqAfCQ/default.jpg' }, medium: { url: 'https://i.ytimg.com/vi/THA_5cqAfCQ/mqdefault.jpg' }, high: { url: 'https://i.ytimg.com/vi/THA_5cqAfCQ/hqdefault.jpg' } }, channelTitle: 'NationalGeographic', channelId: 'UCpVm7bg6pXKo1Pr6k5kxG9A', live: 'none', duration: 428, definition: 'hd' }
  • 15.
  • 16.
    라즈베리파이 오디오 (CloseVer) 1. 스마트 폰으로 인터넷 음악을 검색 함 2. 라즈베리파이 서버에서 유투브를 통해 해당 결과 검색 3. 검색 결과에서 듣고 싶은 음악을 선택 4. 선택한 영상을 유튜브에서 다운로드 함 5. 다운로드가 완료되면 라즈베리파이 오디오에서 재생시작 6. 재생 정보를 LCD 에 디스플레이 함
  • 17.
  • 18.
    Package Install 유튜브 검색을위한 패키지 v2 – youtube-feeds V3 – youtube-api $ npm install youtube-feeds 유투브 영상 다운로드를 위한 패키지 $ npm install ytdl 미디어 플레이어 설치 $ npm install omxcontrol
  • 19.
    Source Code var down= exec("ytdl http://www.youtube.com/watch?v=" + data.name + ' > '+ data.name + '.mp4 -q highest', function(err, stdout, stderr) { if (err){ console.log('Error : ' + err); } else { console.log('download complete, start!'); //omx.quit(); $s.send('play', true ); omx.start(data.name + '.mp4'); } });
  • 20.
    Source Code youtube.feeds.videos({q: data.name},function(err, data){ if(err instanceof Error){ console.log(err); } else { console.log(data.items.length); var arr = []; for(var i = 0 ; i < data.items.length ; i++){ var item = data.items[i]; arr.push({ id : item.id, desc : item.description, title : item.title, date : item.updated, count : item.viewCount }); } } });
  • 21.
    Speaker - Module 3.5mm (Sound) USB (Power)
  • 22.
    문제점 1. 라즈베리파이 서버에접속할 수 있는 근접 거리 (Raspberry Pi WiFi 영역) 에서만 서버에 접속할 수 있음 2. IoT 는 외부/물리적으로 떨어진 공간에서 해당 장치를 제 어해야 하는데, 현 시스템은 불가능 해결책 1. 공인 IP를 라즈베리파이에 적용 -> 공인 IP 의 가격이 비싸서 적용하기 힘듦
  • 23.
    라즈베리파이 오디오 (OpenVer) 1. 스마트 폰으로 인터넷 음악을 검색 함 2. 라즈베리파이 서버에서 유투브를 통해 해당 결과 검색 3. 검색 결과에서 듣고 싶은 음악을 선택 4. 선택한 영상을 유튜브에서 다운로드 함 5. 다운로드가 완료되면 라즈베리파이 오디오에서 재생시작 6. 재생 정보를 LCD 에 디스플레이 함
  • 24.
    Package Install IoT 개발지원 module 설치 $ npm install circulus
  • 25.
    Source Code // raspberrypi var ccus = require(‘circulus’); // general doc ccus.tts([메세지], [언어]); ccus.receive([method 명], callback); ccus.send([method 명], callback); ccus.set(key, value); ccus.get(key);
  • 26.
    Source Code // sensordoc var ccus = require(‘circulus’); var cs = ccus.sensor; cs.getDistance cs.getLight cs.getSound cs.getGyro cs.getTemp cs.getHumidity cs.getEnviorn
  • 27.
    Expand your dimension Circulus(http://www.circul.us) Since 2013 Park Jonggun, Lee Yunjai, Ki Yeonah, Lee Jonghee