Top Banner
Arduino YUN × APIで 遊んでみる (株)MOONGIFT 中津川篤司
21

Arduino yun × apiで遊んでみる

Apr 11, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Arduino yun × apiで遊んでみる

Arduino YUN × APIで遊んでみる

(株)MOONGIFT 中津川篤司

Page 2: Arduino yun × apiで遊んでみる

自己紹介

@a_nakatsugawa

fb.me/moongift

株式会社MOONGIFT 代表取締役

2004年1月よりオープンソース・ソフトウェアを毎日紹介するブログ MOONGIFT を運営。

http://www.moongift.jp/

中津川 篤司

@moongift fb.me/moongift.fan

Page 3: Arduino yun × apiで遊んでみる

Arduino YÚN

約1万円(スイッチサイエンスさん価格)

Page 4: Arduino yun × apiで遊んでみる

これまでのArduino// create an array of notes // the numbers below correspond to // the frequencies of middle C, D, E, and F int notes[] = {262, 294, 330, 349};

void setup() { //start serial communication Serial.begin(9600); }

void loop() { // create a local variable to hold the input on pin A0 int keyVal = analogRead(A0); // send the value from A0 to the Serial Monitor Serial.println(keyVal);

// play the note corresponding to each value on A0 if (keyVal == 1023) { // play the first frequency in the array on pin 8

Processingめんどい

Page 5: Arduino yun × apiで遊んでみる

これまでのArduino

ネットワークがない

Page 6: Arduino yun × apiで遊んでみる

これまでのArduino

スペックが貧弱

Page 7: Arduino yun × apiで遊んでみる

Arduino YÚN

ネットワーク!無線LANもあるよ!

Linuxだよ!

Page 8: Arduino yun × apiで遊んでみる

SSHサーバ立ってる!

$ ssh [email protected]

# python --version Python 2.7.3

# lua

Page 9: Arduino yun × apiで遊んでみる

試してみる

Page 10: Arduino yun × apiで遊んでみる

Arduino側#include <Bridge.h> #include <Process.h>

const int pinLight = A0;

void setup() { Bridge.begin(); Serial.begin(9600); }

void loop() { Process p; int sensorValue = analogRead(pinLight); p.runShellCommand("/tmp/slack.sh "+String(sensorValue)); Serial.println(p); delay(2000); }

Page 11: Arduino yun × apiで遊んでみる

Linux側

/usr/bin/curl -k -X POST --data-urlencode \ 'payload={"channel": "#meetup", \ ”username": "webhookbot", "text": \ ”Value is '"$1"'", "icon_emoji": \ ":ghost:"}' https://hooks.slack.com/ services/xxxx4

Page 12: Arduino yun × apiで遊んでみる

デモ

Page 13: Arduino yun × apiで遊んでみる

mBaaSに飛ばしてみる

Page 14: Arduino yun × apiで遊んでみる

Pythonと言えば…

Page 15: Arduino yun × apiで遊んでみる

やること

pipをインストール

pip install py_nifty_cloud

Page 16: Arduino yun × apiで遊んでみる

設定ファイルを書く

# cat nifty_cloud.yml

APPLICATION_KEY: '120...e76d' CLIENT_KEY: 'b5f...4c8'

Page 17: Arduino yun × apiで遊んでみる

テストスクリプト#cattest.py

#importfrompy_nifty_cloud.nifty_cloud_request             importNiftyCloudRequestncr=NiftyCloudRequest('/tmp/nifty_cloud.yml')path='/classes/TestClass'method='POST'#postanewrecodevalues={'key':'test'}response=ncr.post(path=path,query=values)print(response.status_code)

Page 18: Arduino yun × apiで遊んでみる

実行してみる

#pythontest.py:InsecurePlatformWarning201

Page 19: Arduino yun × apiで遊んでみる

Processingと連携する#include<Bridge.h>#include<Process.h>voidsetup(){:}

voidloop(){intsensorValue=analogRead(pinLight);Processp;p.runShellCommand("/usr/bin/python/tmp/test.py”+String(sensorValue));while(p.running());while(p.available()){intresult=p.parseInt();Serial.println(result);}delay(5000);}

Page 20: Arduino yun × apiで遊んでみる

デモ

Page 21: Arduino yun × apiで遊んでみる

ご静聴ありがとう ございました