主题代码
#include <WiFi.h>
const int led1Pin = 2;
boolean led1Flag = false;
String led1State = "OFF";
String receline = "";
String receAll = "";
const char* ssid = "开始上";
const char* password = "12345678";
WiFiServer server(80);
WiFiClient newClient;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
Serial.println("现出原型吧:");
WiFi.softAP(ssid,password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("你的原型是:");
Serial.println(myIP);
Serial.println();
server.begin();
pinMode(led1Pin,OUTPUT);
}
void loop() {
newClient = server.available();
if(newClient)
{
Serial.print("你的原型是个蛆啊:");
Serial.println(newClient.remoteIP());
while(newClient.connected())
{
if(newClient.available() > 0)
{
char c = newClient.read();
Serial.print(c);
receAll += c;
if(c == '\n')
{
if(receline.length() == 0)
{
getCommand();
pageDisplay();
break;
}
else
{
receline = "";
}
}
else if(c != '\r')
{
receline += c;
}
}
}
newClient.stop();
Serial.println("现出蛆了啊");
}
ledControl();
receAll = "";
}
void getCommand()
{
if((receAll.indexof("GET/LED1_on")) >= 0)
led1Flag = true;
else if((receAll.indexof("GET/LED1_off")) >= 0)
led1Flag = false;
led1State = (led1Flag)?"ON":"OFF";
}
void ledControl()
{
digitalWrite(led1Pin,led1Flag);
}
void pageDisplay()
{
newClient.println("HTTP/1.1 200 OK");
newClient.println("Content-type;text/html");
newClient.println();
newClient.print("<!DOCTYPE html>");
newClient.print("<html>");
newClient.print("<head>");
newClient.print("<title>三界的上神体</title>");
newClient.print("<meta charset = "utf-8">");
newClient.print("<style>html{text-align:center;}</style>");
newClient.print("</head>");
newClient.print("<body><br>");
newClient.print("<h2>三界的上神体</h2>");
newClient.print("<p>GPIO2 - "+ led1State +"</p>");
newClient.print("<P><a href = "/LED1_on"><button>打开</button></a></P>");
newClient.print("<P><a href = "/LED1_off"><button>关闭</button></a></P>");
newClient.print("</body></html>");
newClient.println();
}
错误码
H:\8266xm\xxdd82663\xxdd82663.ino: In function 'void getCommand()':
H:\8266xm\xxdd82663\xxdd82663.ino:76:15: error: 'class String' has no member named 'indexof'
if((receAll.indexof("GET/LED1_on")) >= 0)
^
H:\8266xm\xxdd82663\xxdd82663.ino:78:20: error: 'class String' has no member named 'indexof'
else if((receAll.indexof("GET/LED1_off")) >= 0)
^