Arduino http请求LED

时间:2017-05-09 19:28:47

标签: arduino

原谅我,我是一个非常新的c / Arduino,我的第一个项目是我在我的服务器上放了一个php文件。当页面返回" ON"我希望内置LED打开,相反,当响应是" OFF"那么LED应该关闭。

尽管响应返回为关闭,LED仍然亮着。

我无法弄清楚为什么会这样

任何帮助都非常感激。

#include <Bridge.h>
#include <HttpClient.h>

void setup() {
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);


  SerialUSB.begin(9600);

  while (!SerialUSB); // wait for a serial connection
}

void loop() {

  // Initialize the client library
  HttpClient client;

  // Make a HTTP request:
  client.get("http://www.***.co.uk/arduino.php");

  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    String response = String(c);
    Serial.print(response);


    if(c == 'OFF'){
      digitalWrite(LED_BUILTIN, LOW);
    }else{
      digitalWrite(LED_BUILTIN, HIGH);
    }
  }
  SerialUSB.flush();

  delay(5000);
}

0 个答案:

没有答案