Arduino YUN × APIで 遊んでみる (株)MOONGIFT 中津川篤司
Arduino YUN × APIで遊んでみる
(株)MOONGIFT 中津川篤司
自己紹介
@a_nakatsugawa
fb.me/moongift
株式会社MOONGIFT 代表取締役
2004年1月よりオープンソース・ソフトウェアを毎日紹介するブログ MOONGIFT を運営。
http://www.moongift.jp/
中津川 篤司
@moongift fb.me/moongift.fan
Arduino YÚN
約1万円(スイッチサイエンスさん価格)
これまでの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めんどい
これまでのArduino
ネットワークがない
これまでのArduino
スペックが貧弱
Arduino YÚN
ネットワーク!無線LANもあるよ!
Linuxだよ!
試してみる
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); }
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
デモ
mBaaSに飛ばしてみる
Pythonと言えば…
やること
pipをインストール
pip install py_nifty_cloud
設定ファイルを書く
# cat nifty_cloud.yml
APPLICATION_KEY: '120...e76d' CLIENT_KEY: 'b5f...4c8'
テストスクリプト#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)
実行してみる
#pythontest.py:InsecurePlatformWarning201
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);}
デモ
ご静聴ありがとう ございました