Arduino Yún 桥:简单命令失败
Arduino Yún Bridge: simple command failing
我创建了以下草图,几乎完全基于 arduino.cc 提供的 Bridge 教程。
我不知道为什么示例 Bridge 脚本对我有用(通过卷曲 URI arduino.local/arduino/digital/13/1
之类的 URI 来切换引脚 13 上的 LED),但是当我卷曲时,这个更简单的草图会响应我的失败字符串"无法识别的命令:你好"arduino.local/arduino/hello/
。
我错过了什么?
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
YunServer server;
void setup() {
Serial.begin(9600);
// Bridge startup
pinMode(13,OUTPUT);
digitalWrite(13, HIGH);
Bridge.begin();
digitalWrite(13, LOW);
server.begin();
}
void loop() {
// Get clients coming from server
YunClient client = server.accept();
// There is a new client?
if (client) {
// Process request
process(client);
// Close connection and free resources.
client.stop();
}
delay(50); // Poll every 50ms
}
void process(YunClient client) {
// read the command
String command = client.readStringUntil('/');
if (command == "hello") {
client.println(F("I will do your bidding"));
return;
}
client.print(F("Unrecognized command: "));
client.println(command);
}
最终,我想使用一个更长的随机字符串作为键 - 代替"hello" - 允许我从存储密钥的设备激活连接的组件(例如,将URI存储为主屏幕上的按钮的智能手机)。
我在示例中遗漏的是这些 Stream 函数的确切行为:
String command = client.readStringUntil('/');
if (command == "hello") { ... }
仅当"hello"不是 URI 的最后一段时,该条件才成立。 让我失望的是 Bridge 示例代码中的 mode 命令。 它解析了最后一个段(期望"输入"或"输出"),如下所示:
String mode = client.readStringUntil('r');
这很令人困惑,因为我没有想到云服务器会在我卷曲时剥离最后的'/'
:
$ curl "arduino.local/arduino/digital/hello/" -v
博士:
使用 readStringUntil('r')
分析 URI 的最后一段。
相关文章:
- 如何使用 c++ 在命令行中创建一个简单的字符控制器?
- 从命令提示符使用 MSBuild 调试简单的C++可执行文件
- 如何解析具有简单语法的输入命令
- 使用 QT 创建器通过树莓派上的 Wifi 执行简单的终端命令
- 有没有一种简单的方法可以将系统命令的输出转换为字符串
- gl_invalid_operation错误1218(0x0502)使用简单的OpenGl命令GlverTex2i,gl
- 简单命令行程序中的分段错误
- 使用命令行和C++的简单计算器
- 如何使用 CreateProcess 执行简单的命令行
- C++简单的钩子和隐藏命令提示符
- 将任意数量的任意类型的值组合为单个字符串的简单命令
- 我将创建一个简单的命令解释器,允许用户像在任何命令行中一样输入命令,但在 2 个参数后发生错误
- 在 C++ 中将命令行参数作为函数调用的简单方法
- 在C++中,有没有一种简单的方法可以通过iostream::cin获取带有参数的命令调用
- Arduino Yún 桥:简单命令失败
- c中的fork()命令——这段简单代码的输出是什么
- C++ 简单时钟减法命令
- 简单的OpenCV命令可以在调试模式下工作,但不能在发布模式下工作
- 简单的HowTo在调试器中启动OSX上的C++命令行工具
- 无法用Visual Studio 2015命令行工具编译和链接简单的c++程序