More Related Content
Similar to 【最新版誘導用】駅すぱあとWebサービス&sakura.io体験ハンズオン (20)
More from さくらインターネット株式会社 (20)
【最新版誘導用】駅すぱあとWebサービス&sakura.io体験ハンズオン
- 6. Agenda
7
1. マイコンおよびプログラムの構築
₋ マイコン(Arduino)による開発環境の準備
₋ 照度センサおよびさくらの通信モジュールの繋ぎ込み
₋ 試験用プログラムの流し込み
2. sakura.ioの設定
₋ プロジェクトの作成
₋ さくらの通信モジュールの登録
₋ 連携サービスの設定
3. Webへのデータ連携(Node-RED ⇒駅すぱあとWebサービス)
₋ Node-REDサーバ用インスタンスの作成
₋ WebSocketを利用したデータ連携フロー作成
₋ 駅すぱあとWebサービスおよびSlackとの連携フロー作成
- 16. cds(照度センサー)サンプル
const int cdsPin = A0;
boolean flg = 0;
void setup() {
Serial.begin(9600);
Serial.println("OK");
}
void loop() {
int cdsAnalogVal;
uint32_t cdsSimpleVal = 0;
String msg = "";
cdsAnalogVal = analogRead(cdsPin);
cdsSimpleVal = map(cdsAnalogVal, 0, 1023, 0, 255);
if(cdsSimpleVal > 100){
msg = "Lighted : ";
flg = 0;
}else{
msg = "Darken : ";
if(flg == 0){
Serial.print("* ");
flg = 1;
}
}
Serial.print(msg);
Serial.println(cdsSimpleVal);
delay(500);
}
17
- 19. cds(照度センサー)とWebSocket
#include <SakuraIO.h>
SakuraIO_I2C sakuraio;
const int cdsPin = A0;
boolean sendFlg = 0;
void setup() {
Serial.begin(9600);
Serial.println("Waiting to come online");
for (;;) {
if ( (sakuraio.getConnectionStatus() & 0x80) == 0x80 ) break;
Serial.print(".");
delay(300);
}
Serial.println("OK");
}
void loop() {
int cdsAnalogVal;
uint32_t cdsSimpleVal = 0;
String msg = "";
cdsAnalogVal = analogRead(cdsPin);
cdsSimpleVal = map(cdsAnalogVal, 0, 1023, 0, 255);
if(cdsSimpleVal > 100){
msg = "Lighted : ";
sendFlg = 0;
}else{
msg = "Darken : ";
if(sendFlg == 0){
sakuraio.enqueueTx(1, cdsSimpleVal);
sakuraio.send();
Serial.print("* ");
sendFlg = 1;
}
}
Serial.print(msg);
Serial.println(cdsSimpleVal);
delay(500);
}
20