c语言 - 最简单的桥接示例不起作用 - Arduino Yun



我试图修改温度Web面板示例(在arduino-1.5.6-rw/libraries/Bridge/examples/TemperatureWebPanel中找到)用于光传感器。不幸的是,似乎连最简单的接收和传输结果在wifi上都不起作用!我甚至注释掉了工作部分,只是将一些文本发送回浏览器,但我仍然在浏览器中看不到任何内容:

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
// Listen on default port 5555, the webserver on the Yun
// will forward there all the HTTP requests for us.
YunServer server;
String startString;
long hits = 0;
void setup() {
  Serial.begin(9600);
  // For debugging, wait until the serial console is connected.
  /*delay(4000);
  while(!Serial);
  Bridge.begin();
*/
  // Bridge startup
  pinMode(13, OUTPUT);
  Bridge.begin();
  digitalWrite(13, HIGH);
  pinMode(A0, INPUT);

  // 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;
  }
  Serial.println("yeahn");
  Serial.println(startTime);
}
void loop() {
  // Get clients coming from server
  Serial.println("an");
  YunClient client = server.accept();
  // There is a new client?
  if (client) {
    Serial.println("Client!n");
    // read the command
    String command = client.readString();
    client.print('(This should definitely be sent over bridge)');
    /*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(A0);
      // convert the reading to millivolts:
      client.print("Current time on the Yún: ");
      client.println(timeString);
      client.print("<br>Current value: ");
      client.print(sensorValue);
      client.print("<br>This sketch has been running since ");
      client.print(startString);
      client.print("<br>Hits so far: ");
      client.print(hits);
    }*/
    // Close connection and free resources.
    client.stop();
    hits++;
  }
  delay(50); // Poll every 50ms
}

我在串行监视器中多次看到"a",但从未在arduino.local/arduino/temperature url中看到任何内容,只是一个空白响应。

此外,过了一段时间后,似乎Yun与网络断开了连接,无法通过http或ssh访问。考虑到ssh是与这台计算机通信的主要方式,如何调试这样的问题呢?

在我自己的配置上一步一步调试后,我发现代码从来没有超过Bridge.begin()。

进一步调查后,我发现默认的Bridge波特率250000不再匹配内核波特率115200。

变为:Bridge.begin(115200)

要确定您的内核速度,从终端运行cat /proc/cmdline到您的Yun

查看此链接获取更多信息:https://groups.google.com/forum/#!味精/linino/-rSmpjX4UOM/Cnjv-uzrlfgJ

如果这不是你的问题,考虑添加调试信息(例如…Bridge.cpp等实际源文件中的Serial.print()。不幸的是,似乎Arduino/Linino开发人员经常进行突破性的更改,并且没有资源来更新文档,示例等。

如果你在Windows上,不要使用'arduino '。"本地",因为Windows有问题要解决这个主机。你试过IP地址了吗?您必须通过wifi传输脚本,而不是通过串行(在arduino Ide中,您必须更改端口)。你已经创建了路径'arduino/www/'

你需要一个微型SD卡插入到你的Yún,在根目录下有一个名为"arduino"的文件夹。在"arduino"文件夹中,必须有一个名为"www"的目录。您需要通过WiFi上传草图,以传输本地"www"文件夹的内容。你不能通过USB传输文件。上传后,您可以打开您最喜欢的浏览器并访问http://arduino.local/sd/TemperatureWebPanel。

必须打开http://YUNS_IP/sd/TemperatureWebPanel

如果您正在使用Yun Shield,则需要注释掉串行命令或删除对串行的所有引用,因为桥接器和串行端口都共享相同的硬件串行。我遇到了同样的问题,没有连接

serial.begin(115...)替换为Bridge.begin()

最新更新