スマホ操作
※直接OLEDのQRコードを読む方法もあります。
[obnizアカウントの登録]
obniz 【https://iot.obniz.com/】
[🈪]を選択
[アプリ開発]
[アプリ名]
[プログラムを編集]下記プログラム
[➤]実行
                
                   
●2秒毎に温度センサー読取り
●リレーをオン・オフ制御
プログラム
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://unpkg.com/obniz@3.x/obniz.js" crossorigin="anonymous" ></script>
  </head>
  <body>
    <div id="obniz-debug"></div>
    <div class="container">
      <div class="text-left">
        <h3>Control Relay</h3>
        <button class="btn btn-primary" id="on">Relay ON</button>
        <button class="btn btn-primary" id="off">Relay OFF</button>                 
        <h3>Temperature</h3>         
        <h3 id="print"></h3>  
      </div>
    </div>
    <script>
      //type in your obniz ID
      var obniz = new Obniz("OBNIZ_ID_HERE"); 
      //during obniz connection
      obniz.onconnect = async function() {        
        // 温度センサーをobnizに接続       
        var tempsens = obniz.wired("SHT31", {vcc:0, gnd:1, scl:2, sda:3});        
        // Read Value. 温度を取得&表示 
        setInterval(async function(){
        var temp = await tempsens.getTempWait();
        console.log(temp);
       $("#print").text(temp.toPrecision(3));        
        },2000);
        var grove_relay = obniz.wired("Grove_Relay", {gnd:9, vcc:10, signal:11});        
        //if the "on" button is clicked
        $("#on").click(function() {
          grove_relay.on();          
        });
        //if the "off" button is clicked
        $("#off").click(function() {
          grove_relay.off();          
        }  );
      };
    </script>
  </body>
</html>





 
0 件のコメント:
コメントを投稿