为什么我的代码永远不会重新启动命令
Why my code never get the command reboot?
它一直失败,失败,失败。
Arduino YUN 我有这个代码。如果发现值"reboot",它必须转到站点并获得值"reboot",则执行操作,如果"reboot"不执行任何其他操作。
有时重新启动命令可以正常工作,但它并不总是有效,这让我很难过。
有谁知道为什么我的代码不起作用?
#include <Bridge.h>
#include <HttpClient.h>
String result = String("");
void setup() {
delay(5000);
pinMode(2, OUTPUT);
Bridge.begin();
digitalWrite(2, HIGH);
}
void loop() {
HttpClient client;
// PIN 2
client.get("http://www.example.com/output.php?value=reboot");// output.php outputs the value reboot and the reset the value to empty string. after 10 second php puts the value to reboot and then put the value to empty.
result = "";
while (client.available()) {
char c = client.read();
result = result + c;
}
if(result.indexOf("reboot") >= 0) {// this keeps failing, sometime working and sometime not working
digitalWrite(2, LOW);
delay(3000);
digitalWrite(2, HIGH);
}
delay(7000);
}
它有效。
#include <Bridge.h>
#include <HttpClient.h>
String result = String("");
void setup() {
delay(5000);
pinMode(2, OUTPUT);
Bridge.begin();
digitalWrite(2, HIGH);
}
boolean was_on = false;
void loop() {
HttpClient client;
// PIN 2
client.get("http://ok.example.com/ajax/light");
delay(500);
result = "";
while (client.available()) {
char c = client.read();
result = result + c;
}
if(result.indexOf("reboot") >= 0) {
digitalWrite(2, LOW);
delay(2000);
was_on = true;
} else {
if(was_on) {
digitalWrite(2, HIGH);
delay(1000);
was_on = false;
}
}
delay(3000);
}
相关文章:
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- 如何使用 ctypes 停止和重新启动从 Python 运行的C++代码
- 重新启动后,线程无法在 while 循环中再次运行
- 在程序和基于文本的游戏和C++内重新启动程序
- 在程序/基于文本的游戏/C++内重新启动程序
- 为什么使用 exec() 重新启动程序不能正常工作?
- 即使在我关闭应用程序并重新启动它后,如何保持我的 ID 被阻止?
- 有没有办法在不重新启动或注销的情况下加载游标?
- IO服务重新启动后,Boost最后期限计时器持续触发
- 在C++中重新启动随机数序列
- 稍后在构造函数中重新启动异常指令删除此指令
- 如何获取代码::块以在代码::块重新启动后保持库的配置?
- 我想在我设置的几秒钟后重新启动我的程序
- 如何使重新启动此循环,当用户输入 1 时,并在 0 时停止
- UDP 服务器每 5 秒重新启动一次
- 有没有办法检查内存缓存是否已重新启动?
- (Windows 10) 在不更新的情况下重新启动C++
- Live555MediaServer 在每个新连接时重新启动流。为什么将"reuseSource"设置为 true 无法按预期工作?
- 为什么我的代码永远不会重新启动命令
- 如何重新启动C++命令提示符应用程序