基于wifi实现的人体感应视频播放
采用的是esp32芯片和红外传感器,制作的硬件/*
*This sketch sends a message to a TCP server
*
*/
#include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti WiFiMulti;
int k=1;
void setup()
{
Serial.begin(115200);
delay(10);
pinMode(0, INPUT);
// We start by connecting to a WiFi network
WiFiMulti.addAP("xxxx", "xxxxxxx");
Serial.println();
Serial.println();
Serial.print("Waiting for WiFi... ");
while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
}
void loop()
{
// const uint16_t port = 80;
// const char * host = "192.168.1.1"; // ip or dns
const uint16_t port =10002;
const char * host = "192.168.1.102"; // ip or dns
Serial.print("Connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("Connection failed.");
Serial.println("Waiting 5 seconds before retrying...");
delay(5000);
return;
}
// This will send a request to the server
//uncomment this line to send an arbitrary string to the server
//client.print("Send this data to the server");
//uncomment this line to send a basic document request to the server
//client.print("GET /index.html HTTP/1.1\n\n");
if(k!=digitalRead(0))
{
k=digitalRead(0);
client.write(k);
}
int maxloops = 0;
//wait for the server's reply to become available
while (!client.available() && maxloops < 1000)
{
maxloops++;
delay(1); //delay 1 msec
}
if (client.available() > 0)
{
//read back one line from the server
String line = client.readStringUntil('\r');
Serial.println(line);
}
else
{
Serial.println("client.available() timed out ");
}
// Serial.println("Closing connection.");
// client.stop();
//Serial.println("Waiting 5 seconds before restarting...");
//delay(5000);
}然后用processing做个服务器加播放软件
import processing.net.*;
import VLCJVideo.*;
VLCJVideo video;
int whatClientSaid=1;
PImage img;
int port = 10002;
Server myServer;
void setup()
{
fullScreen();
noStroke();
video = new VLCJVideo(this);
video.open("1.mp4");
video.play();
img = loadImage("1.jpg");
myServer = new Server(this, port);
}
void draw()
{
// Get the next available client
Client thisClient = myServer.available();
// If the client is not null, and says something, display what it said
if (thisClient !=null) {
whatClientSaid = thisClient.read();
//if (whatClientSaid != null) {
println(whatClientSaid);
//}
}
image(img, 0,0);
if(whatClientSaid==0){
image(video, 0, 0, width, height);
if(video.isStopped()) video.play();
}
}
有演示文件就更能让人理解意图 的确,需要加入视频更容易让人理解
页:
[1]