|
1、概述
SSDP简单服务发现协议,它是UPnP的核心协议之一。UPnP是零配置网络协议的一种。大众使用的家庭设备一般都支持这个协议,以便用户的主机或手机能够轻松发现这些设备。当一个新的设备(比如说笔记本)加入到网络中时,它可以向本地网络查询特定设备是否存在,这些设备包括互联网网关、音频系统、TV或者打印机等。下面在零知开源平台上进行该功能的测试。
2、软件和硬件
硬件我们本次使用零知-ESP8266;
软件使用零知开发工具(持续更新中),自带示例:
3、方法步骤
(1)先在零知开发工具中打开SSDP示例,或者复制下面的代码到零知开发工具中:
- /**********************************************************
- * 文件: x.ino by 零知实验室([url=http://www.lingzhilab.com]www.lingzhilab.com[/url])
- * -^^- 零知开源,让电子制作变得更简单! -^^-
- * 时间: 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】,可以看到如下信息:
这个设备信息和我们在程序中设置的是一致的:
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打赏
-
查看全部打赏
|