Help us understand the problem. What is going on with this article?

HueをブラウザなJavaScriptで操作するメモ

More than 3 years have passed since last update.

SuperAgentを使ってみます。

index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/1.2.0/superagent.min.js"></script>
    <script src="app.js"></script>
  </body>
</html>

app.js
var request = window.superagent;
var IPURL = 'https://www.meethue.com/api/nupnp';
var hueapi = ''; //
var USERNAME = 'lig-n0bisuke';
var flag = true;

//Hue操作ようのAPIエンドポイント作成
function createEndpoint(ip){
  return 'http://'+ip+'/api/'+USERNAME+'/lights/';
}

request
  .get(IPURL)
  .set('Accept', 'application/json')
  .end(function(err, res){
    var ipadress = res.body[0].internalipaddress; //HueのIPアドレス
    hueapi = createEndpoint(ipadress);
  });

function ctrlHue(id, flag){
  if(hueapi === '')return;

  request
    .put(hueapi+id+'/state')
    .send({on: flag})
    .set('Accept', 'application/json')
    .end(function(err, res){
      console.log(res.body[0]);
    });
}

setInterval(function(){
  flag = !flag;
  ctrlHue(1, flag);
},2000);

これで2秒ごとに点滅してくれます。

n0bisuke
プロトタイピング専門スクール「プロトアウトスタジオ」で教えたりしてます。 プロフ -> https://dotstud.io/members/n0bisuke
https://protoout.studio
dotstudio
全ての人がモノづくりを楽しむ世界を目指して活動しています。
https://dotstud.io
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした