捣蛋鬼z 2023-07-05 21:53 采纳率: 0%
浏览 33
已结题

ESP32 WiFi点灯web控制主体代码错误

主题代码

#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)
                    ^
  • 写回答

8条回答 默认 最新

  • cyjbj 2023-07-05 23:01
    关注
    获得1.20元问题酬金

    一楼正解

    评论

报告相同问题?

问题事件

  • 系统已结题 7月13日
  • 修改了问题 7月5日
  • 创建了问题 7月5日

悬赏问题

  • ¥50 H5+js 动态数字画廊怎么做?
  • ¥20 外向内全景图像拼接相关项目和论文咨询
  • ¥15 求解,高等数学上,可不可以讲一下思路
  • ¥20 请写个前端案例学习使用
  • ¥500 求Java Socks5 转发实现
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥20 笔记本电脑 处理器是AMD的r7
  • ¥15 需要在vitis下实现彩调视频图像累加,并输出
  • ¥15 解决不了的LNK2019错误
  • ¥20 MATLAB仿真三相桥式全控整流电路