hardware meetup
TRANSCRIPT
Intel Edison
ウェアラブルコンピュータ開発用のシングルボードコンピュータ
デュアルコアの Intel Atom 500MHz
メモリ 1 GB
Linux 搭載
通信用の Bluetooth と Wi-Fi を備える
Copyright © Classmethod, Inc.
仕組み
Copyright © Classmethod, Inc.
* Web サーバー(Python)
* 実行プログラム(Arduino)
* Linux
0.5 秒おきにファイルパス監視ファイルがあれば特定の処理実行
リクエストによってファイル生成/削除
* iOS アプリ
スイッチ ON / OFF によってリクエストを送信
Web サーバー
Copyright © Classmethod, Inc.
#!/usr/bin/python
import CGIHTTPServer CGIHTTPServer.test()
* サーバー起動プログラム(server.py)
#!/usr/bin/env python
f = open('/home/root/python/output/led', 'w') f.write('') f.close()
* LED 点灯 API(led_on.py)
実行プログラム
Copyright © Classmethod, Inc.
void checkLed() { char filePath[] = "/home/root/python/output/led"; FILE *file;
if ((file = fopen(filePath, "r")) == NULL) { Serial.println("LED file not exists."); digitalWrite(ledPin, LOW); } else { Serial.println("LED file exists!!"); digitalWrite(ledPin, HIGH); } }
iOS アプリ
Copyright © Classmethod, Inc.
static NSString *const kBaseURL = @"http://tanason.local:8000/cgi-bin/";
- (void)sendRequestWithResource:(NSString *)resource { NSString *url = [NSString stringWithFormat:@"%@%@", kBaseURL, resource];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * response, NSData * data, NSError * error) { if (error) { NSLog(@"error = %@", error); } else { NSLog(@"Success!!"); } }]; }
まとめ
iPhone から Edison の操作は HTTP 通信で行う
Web サーバーは Python が簡単
ファイルの存在有無で任意の処理を実行させる
ファイル生成 / 削除時はパーミッションに注意
Copyright © Classmethod, Inc.