Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助获取从yun上的html滑块到arduino值的值吗_Arduino_Arduino Yun - Fatal编程技术网

需要帮助获取从yun上的html滑块到arduino值的值吗

需要帮助获取从yun上的html滑块到arduino值的值吗,arduino,arduino-yun,Arduino,Arduino Yun,我的设置:arduino leonardo+云盾 我正在努力实现的目标: 在yun提供的html上通过一根电线显示温度。允许用户通过html页面上的滑块设置目标温度,并在函数“goaltemp”中设置变量值 这是我的html: <!DOCTYPE html> <html> <head> <title>AngularJS / Arduino</title> <meta name="vi

我的设置:arduino leonardo+云盾

我正在努力实现的目标: 在yun提供的html上通过一根电线显示温度。允许用户通过html页面上的滑块设置目标温度,并在函数“goaltemp”中设置变量值

这是我的html:

    <!DOCTYPE html>
<html>
    <head>
        <title>AngularJS / Arduino</title>
        <meta name="viewport" content="width=device-width">

        <script type="text/javascript" src="zepto.min.js"></script>
        <script type="text/javascript">
        function refresh() {
            $('#content').load('/arduino/temperature');
        }
        var value;
        function sendVal() {
            $.get('/arduino/goaltemp' + value, function(){
                    }
                );
            }
            function updateVal(val) {
            value = val;
            $("#val").text(value);
            sendVal();
            }
        </script>

    </head>
    <body onload="setInterval(refresh, 2000);">
      <span id="content">0</span>
      <p>Goal Temperature:
      <input type="range" min="0" max="230" onchange="updateVal(this.value);">
      <p id="val">0</p>
      </p>


    </body>
</html>

安古拉鲁斯/阿杜伊诺
函数刷新(){
$('#content')。加载('/arduino/temperature');
}
var值;
函数sendVal(){
$.get('/arduino/goaltemp'+值,函数(){
}
);
}
函数updateVal(val){
值=val;
$(“#val”)。文本(值);
sendVal();
}
0
目标温度:

0

这是我的arduino草图:

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

#include <SevSeg.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//*****Temp Read
  //code from http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
  //Orange Stripe is PWR: 3-5V, 
  //White Stripe is GND
  //Blue Stripe is data.

  // Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
  // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  OneWire oneWire(ONE_WIRE_BUS);
  //Powerswitch Tail
  const int powerPin = A0;
  boolean powerOn = false;
  // Pass our oneWire reference to Dallas Temperature. 
  DallasTemperature sensors(&oneWire);

// Listen on default port 5555, the webserver on the Yún
// will forward there all the HTTP requests for us.
YunServer server;
String startString;
long hits = 0;

void setup() {
  //Serial.begin(9600);

  // Bridge startup
  Bridge.begin();

  // Listen for incoming connection only from localhost
  // no one from the external network could connect
  server.listenOnLocalhost();
  server.begin();

  // get the time that this sketch started:
  Process startTime;
  startTime.runShellCommand("date");
  while (startTime.available()) {
    char c = startTime.read();
    startString += c;
  }
}

void loop() {
  int temp = (sensors.getTempFByIndex(0));
  sensors.requestTemperatures(); // Send the command to get temperatures

  // Get clients coming from server
  YunClient client = server.accept();

  // There is a new client?
  if (client) {
    // read the command
    String command = client.readString();
    command.trim();        //kill whitespace
    Serial.println(command);
    // is "temperature" command?
    if (command == "temperature") {
      // get the time from the server:
      Process time;
      time.runShellCommand("date");
      String timeString = "";     
      while (time.available()) {
        char c = time.read();
        timeString += c;
      }
      Serial.println(timeString);
      int sensorValue = analogRead(A1);
      // convert the reading to millivolts:
      // convert the millivolts to temperature celsius:
      // print the temperature:
      //client.print("Current time on the Y&uacute;n: ");
      //client.println(timeString);
      client.print("<br>Current temperature: ");
      client.print(temp);
      client.print(" &deg;F");
      //client.print("<br>This sketch has been running since ");
      //client.print(startString);
      client.print("<br>Hits so far: ");
      client.print(hits);
    }
      if (command == "goaltemp") {
      int value = client.parseInt();
      client.print("<br>The Goal Temperature is ");
      client.print(value);
      client.print(" &deg;F");
      }

    // Close connection and free resources.
    client.stop();
    hits++;
  }

  delay(50); // Poll every 50ms
}
#包括
#包括
#包括
#包括
#包括
#包括
//*****临时读取
//代码来自http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
//橙色条纹为PWR:3-5V,
//白色条纹为GND
//蓝色条纹是数据。
//数据线插入Arduino上的针脚2
#定义一条线\u总线2
//设置oneWire实例以与任何oneWire设备通信(不仅仅是Maxim/Dallas温度IC)
单线单线(单线总线);
//动力开关尾部
const int powerPin=A0;
布尔powerOn=false;
//将我们的单线参考传递到达拉斯温度。
达拉斯温度传感器(单线);
//在默认端口5555(Yún上的Web服务器)上侦听
//将为我们转发所有HTTP请求。
云服务器;
字符串开始字符串;
长点击率=0;
无效设置(){
//Serial.begin(9600);
//网桥启动
Bridge.begin();
//仅侦听来自本地主机的传入连接
//外部网络中的任何人都无法连接
listenOnLocalhost();
server.begin();
//获取此草图开始的时间:
过程启动时间;
startTime.runShellCommand(“日期”);
while(startTime.available()){
char c=startTime.read();
startString+=c;
}
}
void循环(){
int temp=(sensors.getTempFByIndex(0));
sensors.requestTemperations();//发送命令以获取温度
//从服务器获取客户端
YunClient client=server.accept();
//有新客户吗?
如果(客户){
//阅读命令
String命令=client.readString();
command.trim();//清除空白
Serial.println(命令);
//是“温度”命令吗?
如果(命令==“温度”){
//从服务器获取时间:
处理时间;
time.runShellCommand(“日期”);
字符串timeString=“”;
while(time.available()){
char c=time.read();
时间串+=c;
}
Serial.println(timeString);
int传感器值=模拟读数(A1);
//将读数转换为毫伏:
//将毫伏转换为摄氏温度:
//打印温度:
//client.print(“Yú;n:”)上的当前时间;
//client.println(timeString);
客户端打印(
当前温度:); 客户端打印(临时); 客户。打印(“°;F”); //client.print(“
此草图已运行至今”); //客户端打印(开始字符串); client.print(“
到目前为止点击:”); 客户端打印(点击次数); } 如果(命令==“goaltemp”){ int value=client.parseInt(); client.print(“
目标温度为”); 客户。打印(值); 客户。打印(“°;F”); } //紧密连接和免费资源。 client.stop(); hits++; } 延迟(50);//每50毫秒轮询一次 }

温度报告目前效果很好。但是,我不知道如何将html中滑块的值传递给arduino。任何建议或帮助都将不胜感激

您是否在此处查看了示例代码和文档:?这里的示例代码介绍了您正在尝试执行的操作

具体来说,请注意代码作者如何使用不同的函数分解URL参数的处理,如下所示:

void process(YunClient client) {
  String command = client.readStringUntil('/');

  if (command == "digital") {
    digitalCommand(client);
  }
  if (command == "analog") {
    analogCommand(client);
  }
  if (command == "mode") {
    modeCommand(client);
  }
}
在每个处理函数中,只需执行
client.readStringUntil('/')
即可解析树。最终,您将获得goaltemp值

提示,您可能希望将URL格式化为
/arduino/goaltemp/20
——这将使解析更容易

祝你好运