- /**********************************************************
- * 文件: x.ino by 零知实验室(www.lingzhilab.com)
- * -^^- 零知开源,让电子制作变得更简单! -^^-
- * 时间: 2019/05/28 12:22
- * 说明:
- ************************************************************/
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266SSDP.h>
-
- #ifndef STASSID
- #define STASSID "ssid"
- #define STAPSK "passwd"
- #endif
-
- const char* ssid = STASSID;
- const char* password = STAPSK;
-
- ESP8266WebServer HTTP(80);
-
- void setup() {
- Serial.begin(115200);
- Serial.println();
- Serial.println("Starting WiFi...");
-
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- if (WiFi.waitForConnectResult() == WL_CONNECTED) {
-
- Serial.printf("Starting HTTP...\n");
- HTTP.on("/index.html", HTTP_GET, []() {
- HTTP.send(200, "text/plain", "Hello World!");
- });
- HTTP.on("/description.xml", HTTP_GET, []() {
- SSDP.schema(HTTP.client());
- });
- HTTP.begin();
-
- Serial.printf("Starting SSDP...\n");
- SSDP.setDeviceType("upnp:rootdevice");
- SSDP.setSchemaURL("description.xml");
- SSDP.setHTTPPort(80);
- SSDP.setName("Philips hue clone");
- SSDP.setSerialNumber("001788102201");
- SSDP.setURL("index.html");
- SSDP.setModelName("Philips hue bridge 2012");
- SSDP.setModelNumber("929000226503");
- SSDP.setModelURL("http://www.meethue.com");
- SSDP.setManufacturer("Royal Philips Electronics");
- SSDP.setManufacturerURL("http://www.philips.com");
- SSDP.begin();
-
- Serial.printf("Ready!\n");
- } else {
- Serial.printf("WiFi Failed\n");
- while (1) {
- delay(100);
- }
- }
- }
-
- void loop() {
- HTTP.handleClient();
- delay(1);
- }
(2)验证上述代码并上传到零知-ESP8266开发板;
(3)零知-开发工具中打开串口调试窗口,可以看到如下信息:
(4)下面进行测试是否能发现设备:
我们需要下载这个工具:SSDP_Tester.
(也可以给我留言,免费传给你)
安装到安卓手机上,然后在SSDP_Tester工具中点击【LISTEN】,可以看到如下信息:
这个设备信息和我们在程序中设置的是一致的: