ESP8266WebServer返回空响应(Sonoff Basic)

时间:2019-01-05 09:42:49

标签: arduino arduino-esp8266

我正在尝试通过Arduino用自定义固件刷新Sonoff Basic开关。

一旦我添加了一个额外的server.on(...)处理程序,它就会从返回有效的200响应变为返回空的响应(请参见随附的屏幕截图)。

我一直在遵循本教程:https://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/,在某一时刻它运行良好,然后突然停止了-我不确定为什么。我一直无法使它重新工作。

当我运行下面的代码而没有其他代码(由START / END注释标记)时,它工作得很好。一旦我尝试向server.on()添加第二个端点,它就会返回一个空响应。

/*********
  Rui Santos
  Complete project details at http://randomnerdtutorials.com  
*********/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

MDNSResponder mdns;

// Replace with your network credentials

const char* ssid     = "ssid";
const char* password = "password";

int gpio13Led = 13;
int gpio12Relay = 12;
bool switchOn = false;

ESP8266WebServer server(80);

void setup(void){

  pinMode(gpio13Led, OUTPUT);
  digitalWrite(gpio13Led, HIGH);
  pinMode(gpio12Relay, OUTPUT);
  digitalWrite(gpio12Relay, HIGH);

  Serial.begin(115200); 
  delay(5000);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    digitalWrite(gpio13Led, LOW);
    delay(250);
    digitalWrite(gpio13Led, HIGH);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

  server.on("/", [](){
    server.send(200, "text/plain", "ready");
    Serial.println("ready");
  });
// ADDITIONAL CODE START
  server.on("/on", [](){
    server.send(200, "text/plain", "on");
    Serial.println("on");
  });
// ADDITIONAL CODE END
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
} 

理想情况下,我希望能够具有所需的server.on()数量-我什至尝试仅使用单个处理程序并使用不同的查询参数,但是返回相同的错误。

200 response empty response 1 empty response 2

0 个答案:

没有答案