2022-6-12 14:45:36 [显示全部楼层]
191浏览
查看: 191|回复: 2

[ESP8266/ESP32] 基于wifi实现的人体感应视频播放

[复制链接]
采用的是esp32芯片和红外传感器,制作的硬件
  1. /*
  2. *  This sketch sends a message to a TCP server
  3. *
  4. */
  5. #include <WiFi.h>
  6. #include <WiFiMulti.h>
  7. WiFiMulti WiFiMulti;
  8. int k=1;
  9. void setup()
  10. {
  11.     Serial.begin(115200);
  12.     delay(10);
  13.     pinMode(0, INPUT);
  14.     // We start by connecting to a WiFi network
  15.     WiFiMulti.addAP("xxxx", "xxxxxxx");
  16.     Serial.println();
  17.     Serial.println();
  18.     Serial.print("Waiting for WiFi... ");
  19.     while(WiFiMulti.run() != WL_CONNECTED) {
  20.         Serial.print(".");
  21.         delay(500);
  22.     }
  23.     Serial.println("");
  24.     Serial.println("WiFi connected");
  25.     Serial.println("IP address: ");
  26.     Serial.println(WiFi.localIP());
  27.     delay(500);
  28. }
  29. void loop()
  30. {
  31. //    const uint16_t port = 80;
  32. //    const char * host = "192.168.1.1"; // ip or dns
  33.     const uint16_t port =10002;
  34.     const char * host = "192.168.1.102"; // ip or dns
  35.     Serial.print("Connecting to ");
  36.     Serial.println(host);
  37.     // Use WiFiClient class to create TCP connections
  38.     WiFiClient client;
  39.     if (!client.connect(host, port)) {
  40.         Serial.println("Connection failed.");
  41.         Serial.println("Waiting 5 seconds before retrying...");
  42.         delay(5000);
  43.         return;
  44.     }
  45.     // This will send a request to the server
  46.     //uncomment this line to send an arbitrary string to the server
  47.     //client.print("Send this data to the server");
  48.     //uncomment this line to send a basic document request to the server
  49.     //client.print("GET /index.html HTTP/1.1\n\n");
  50.     if(k!=digitalRead(0))
  51.     {
  52.       k=digitalRead(0);
  53.     client.write(k);
  54.     }
  55.   int maxloops = 0;
  56.   //wait for the server's reply to become available
  57.   while (!client.available() && maxloops < 1000)
  58.   {
  59.     maxloops++;
  60.     delay(1); //delay 1 msec
  61.   }
  62.   if (client.available() > 0)
  63.   {
  64.     //read back one line from the server
  65.     String line = client.readStringUntil('\r');
  66.     Serial.println(line);
  67.   }
  68.   else
  69.   {
  70.     Serial.println("client.available() timed out ");
  71.   }
  72.    // Serial.println("Closing connection.");
  73.    // client.stop();
  74.     //Serial.println("Waiting 5 seconds before restarting...");
  75.     //delay(5000);
  76. }
复制代码
然后用processing做个服务器加播放软件
  1. import processing.net.*;
  2. import VLCJVideo.*;
  3. VLCJVideo video;
  4. int whatClientSaid=1;
  5. PImage img;
  6. int port = 10002;      
  7. Server myServer;        
  8. void setup()
  9. {  
  10.   fullScreen();
  11.   noStroke();
  12.    
  13.   video = new VLCJVideo(this);
  14.   video.open("1.mp4");
  15.   video.play();
  16.   
  17.   img = loadImage("1.jpg");
  18.   
  19.   myServer = new Server(this, port);
  20. }
  21. void draw()
  22. {
  23.   // Get the next available client
  24.   Client thisClient = myServer.available();
  25.   // If the client is not null, and says something, display what it said
  26.   if (thisClient !=null) {
  27.      whatClientSaid = thisClient.read();
  28.     //if (whatClientSaid != null) {
  29.       println(whatClientSaid);
  30.     //}
  31.   }
  32.   image(img, 0,0);
  33.   if(whatClientSaid==0){
  34.   image(video, 0, 0, width, height);
  35.   if(video.isStopped()) video.play();
  36.   }
  37.   
  38.   
  39. }
复制代码


gada888  版主

发表于 2022-6-12 20:56:47

有演示文件就更能让人理解意图
回复

使用道具 举报

telling0000  见习技师

发表于 2022-6-13 00:53:45

的确,需要加入视频更容易让人理解
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2022 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail