• 小爱同学 控制自定义 局域网灯


    继电器--------i02


    #include <ESP8266WiFi.h>
    #define LED 0
    // 以上烧写程序配网方式可以换成微信扫码配网,等等,具体操作可查看博客相关例子
    WiFiServer server(80); // 服务器端口号
    void smartConfig()
    {
    WiFi.mode(WIFI_STA);
    Serial.println(" Wait for Smartconfig");
    WiFi.beginSmartConfig();
    while (1)
    {
    Serial.print(".");
    digitalWrite(LED, 0);
    delay(500);
    digitalWrite(LED, 1);
    delay(500);
    if (WiFi.smartConfigDone())
    {
    Serial.println("SmartConfig Success");
    Serial.printf("SSID:%s ", WiFi.SSID().c_str());
    Serial.printf("PSW:%s ", WiFi.psk().c_str());
    break;
    }
    }
    }
    void setup() {
    Serial.begin(115200);
    delay(10);
    pinMode(2, OUTPUT);
    digitalWrite(2, 1);
    // Connect to WiFi network
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    smartConfig(); //微信智能配网
    delay(500);
    Serial.println("");
    Serial.println("WiFi connected");
    // Start the server
    server.begin();
    Serial.println("Server started @ ");
    // Print the IP address & instructions
    Serial.println(WiFi.localIP());
    //打印出IP地址,后期可以制作显示器来外部硬件显示ip
    Serial.println("To control GPIO, open your web browser.");
    Serial.println("To set GPIO 0 high, type:");
    Serial.print(WiFi.localIP());
    Serial.println("/gpio/1");
    Serial.println("To set GPIO 0 low, type:");
    Serial.print(WiFi.localIP());
    Serial.println("/gpio/0");
    Serial.println("To toggle GPIO 0, type:");
    Serial.print(WiFi.localIP());
    Serial.println("/gpio/4");
    }
    void loop() {
    // Check if a client has connected
    WiFiClient client = server.available();
    if (!client) {
    delay(100);
    return;
    }
    String req = client.readStringUntil(' ');
    Serial.println(req);
    client.flush();
    // Match the request
    int val;
    // 下面开始判断ip进行动作指令
    if (req.indexOf("/gpio/10") != -1)
    digitalWrite(2, 1);
    else if (req.indexOf("/gpio/11") != -1)
    digitalWrite(2, 0);
    else {
    Serial.println("invalid request");
    client.print("HTTP/1.1 404 ");
    client.stop();
    return;
    }
    client.flush();
    // Prepare the response
    String s = "HTTP/1.1 200 OK Content-Type: text/html <!DOCTYPE HTML> <html> Welcome donghui space!jiaru qqqun:47684062 ";
    s += "</html> ";
    // Send the response to the client
    client.print(s);
    delay(1);
    Serial.println("Client disonnected");
    }

    ![在这里插入图片描述](https://img-blog.csdnimg.cn/20181028141618956.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzIzMzE4OQ==,size_27,color_FFFFFF,t_70)
    手机 访问IP+程序里字符


    外观图 懒得写教程![在这里插入图片描述](https://img-blog.csdnimg.cn/20181028142032410.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzIzMzE4OQ==,size_27,color_FFFFFF,t_70)

  • 相关阅读:
    leetCode 87.Scramble String (拼凑字符串) 解题思路和方法
    《代码阅读》读书笔记(一)
    用VMware 8安装Ubuntu 12.04具体过程(图解)
    模板方法
    POJ 2528 Mayor&#39;s posters 离散化+线段树
    <Linux> Xen虚拟机镜像的安装
    Android中的动画详解系列【2】——飞舞的蝴蝶
    jQuery:多个AJAX/JSON请求对应单个回调
    Android中的动画详解系列【1】——逐帧动画
    Android自定义组件系列【4】——自定义ViewGroup实现双侧滑动
  • 原文地址:https://www.cnblogs.com/zdh6/p/9865509.html
Copyright © 2020-2023  润新知