zoukankan      html  css  js  c++  java
  • ESP8266零配置网络

    概念: Zeroconf (Zero-configuration networking 零配置联网)

    功能:

    1 自动配置IP地址  (Link-local 地址),

    2 自动配置并解析域名,这项技术被称为 mDNS (Multicast Domain Name Service,多点发送域名服务)

    3 在网络传播和接收自己与其他设备所能提供的服务。DNS-SD(DNS-based Service Discovery  基于DNS的服务探索)

    #include <ESP8266WiFi.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266mDNS.h>
    ESP8266WebServer server(80);
    void setup() {
    Serial.begin(115200);
    // put your setup code here, to run once:
    WiFi.begin("kangtine","87602261");

    while(WiFi.status()!=WL_CONNECTED){
    delay(500);
    Serial.println(".");
    }
    Serial.print("dns 配置中");
    if(WiFi.status() == WL_CONNECTED) //If WiFi connected to hot spot then start mDNS
    {
    if (MDNS.begin("lsq")) { //Start mDNS with name esp8266
    Serial.println("MDNS started");
    }
    }
    Serial.print("Wi-Fi connected,IP:");
    Serial.println(WiFi.localIP());
    server.on("/",[](){
    server.send(200,"text/html","hello from <b>ESP8266</b>.");
    });

    server.onNotFound([](){
    server.send(404,"text/plain","File Not found!");
    });
    server.begin();

    MDNS.addService("http","tcp",80);
    Serial.println("HTTP server started.");

    int n = MDNS.queryService("http","tcp");
    if(n>0){
    for(int i=0;i<n;i++){
    Serial.print(i+1);
    Serial.print(MDNS.hostname(i));
    Serial.print(MDNS.IP(i));
    Serial.print(MDNS.port(i));
    }
    }else{
    Serial.print("no service found");
    }
    }

    void loop() {
    // put your main code here, to run repeatedly:
    MDNS.update();   一开始我没加这一句。始终无法访问。。。后来加着这一句之后才能访问。。。
    server.handleClient();
    }

  • 相关阅读:
    数据库使用时应该避开的坑
    Linux 命令 curl 的用法及参数解析
    分析 Redis 是否适合作为消息队列
    WEB框架对比——Django、Flask、FastAPI
    视频下载神器——you-get
    QtScrcpy——开源的电脑控制手机(投屏+控制)软件
    Python库大全
    Docker 清理数据卷 volumes
    报错解决——失败
    微信电脑端多开
  • 原文地址:https://www.cnblogs.com/Lonelychampion/p/12228940.html
Copyright © 2011-2022 走看看