如何使用Xively从网站发送命令?

时间:2014-07-08 08:25:44

标签: javascript html xively mbed

我正在尝试创建一个简单的网站来获取一些浮点数并将一些命令发送回mbed上编程的ST Nucleo F401RE。我可以使用xivelyjs文档来接收数据流(浮点数),但不知道如何发回任何东西。 这是我获取浮动的代码:

<div><small>Temperature:</small> <span  style="color:black" id="element1"></span></div>
<div><small>Trip Level:</small> <span style="color:black" id="element2"></span></div>
<!-- Include jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- Include XivelyJS -->
<script src="http://d23cj0cdvyoxg0.cloudfront.net/xivelyjs-1.0.4.min.js"></script>
<script>
$(document).ready(function($) 
{

  // Set the Xively API key (https://xively.com/users/YOUR_USERNAME/keys)
  xively.setKey( "KEY" );

  // Replace with your own values
  var feedID        = FEED,          // Feed ID (the last number on the URL on the feed page on Xively)
      datastreamID  = "Temperature";       // Datastream ID
      selector1     = "#element1";   // Your element on the page - takes any valid jQuery selector
      datastreamID2 = "Trip_Level";
      selector2     = "#element2";
// Get datastream data from Xively
  xively.datastream.get (feedID, datastreamID, function ( datastream ) 
  {
    // Display the current value from the datastream
    $(selector1).html( datastream["current_value"] );
    // Getting realtime! The function associated with the subscribe method will be executed every time there is an update to the datastream
    xively.datastream.subscribe( feedID, datastreamID, function ( event , datastream_updated ) 
    {
        // Display the current value from the updated datastream
        $(selector1).html( datastream_updated["current_value"] );
    });
  });

  xively.datastream.get (feedID, datastreamID2, function ( datastream ) 
  {
    $(selector2).html( datastream["current_value"] );
    xively.datastream.subscribe( feedID, datastreamID2, function ( event , datastream_updated ) 
    {
        $(selector2).html( datastream_updated["current_value"] );
    });
  });

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您想使用xively.datastream.put()