Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
projets:cctv_disco:start [2021/11/22 13:25] admin [Références et liens] |
projets:cctv_disco:start [2022/04/06 17:31] (Version actuelle) risbo [Photos et médias] |
||
---|---|---|---|
Ligne 21: | Ligne 21: | ||
===== Notes techniques et matériaux ===== | ===== Notes techniques et matériaux ===== | ||
- | * Esp 32 | + | * **ESP32 cam** [[https:// |
- | | + | la camera envoie un flux video en wifi...eventuellement avec Motioneye (sur linux) on peut ajouter des fonction de detection mouvement/ |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | * **ESP8266 :** Permet de commander en wifi l' | ||
- | **ESP32 cam** [[https:// | + | |
- | la camera envoie un flux video en wifi...eventuellement avec Motioneye | + | * :!: **Led 4mm** [[https:// |
- | **ESP8266 :** Permet de commander en wifi l' | + | |
+ | | ||
+ | | ||
+ | * Enceinte Bluetooth si besoin son fort | ||
- | **Lecteur mp3** (se declenche avec une arduino ou esp..) necessite une carte micro SD ! | ||
- | [[https:// | ||
- | necessite un ampli et enceinte pour faire :!: un son assez puissant.... ou enceinte bluetooth...batterie integrée.. | ||
- | :!: **Led 4mm** ne seront pas puissante a cette taille.... | ||
- | [[https:// | ||
==== Esp8266 page web controle ==== | ==== Esp8266 page web controle ==== | ||
Ligne 53: | Ligne 48: | ||
- | ===== Photos et médias===== | + | ==== Code ==== |
+ | Code qui cree une pageweb avec deux boutons, déclenchant allumage de deux led et lancant fichier mp3. | ||
+ | L'url de la page est donné en serie. (en l' | ||
+ | |||
+ | <code c+> | ||
+ | // MP3 lib | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | #define MP3_RX 12//RX of Serial MP3 module connect to D7 of wemos | ||
+ | #define MP3_TX 13//TX to D8, wemos | ||
+ | MP3 mp3(MP3_RX, MP3_TX); | ||
+ | |||
+ | int8_t track = 0x01;//the first song in the TF card | ||
+ | int8_t track2 | ||
+ | int8_t volume = 0x1a;// | ||
+ | |||
+ | |||
+ | |||
+ | // Load Wi-Fi library | ||
+ | #include < | ||
+ | |||
+ | // Replace with your network credentials | ||
+ | const char* ssid = " | ||
+ | const char* password = " | ||
+ | |||
+ | // Set web server port number to 80 | ||
+ | WiFiServer server(80); | ||
+ | |||
+ | // Variable to store the HTTP request | ||
+ | String header; | ||
+ | |||
+ | // Auxiliar variables to store the current output state | ||
+ | String output5State = " | ||
+ | String output4State = " | ||
+ | |||
+ | // Assign output variables to GPIO pins | ||
+ | const int output5 = 5; | ||
+ | const int output4 = 4; | ||
+ | |||
+ | // Current time | ||
+ | unsigned long currentTime = millis(); | ||
+ | // Previous time | ||
+ | unsigned long previousTime = 0; | ||
+ | // Define timeout time in milliseconds (example: 2000ms = 2s) | ||
+ | const long timeoutTime = 2000; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | // Initialize the output variables as outputs | ||
+ | pinMode(output5, | ||
+ | pinMode(output4, | ||
+ | // Set outputs to LOW | ||
+ | digitalWrite(output5, | ||
+ | digitalWrite(output4, | ||
+ | |||
+ | // Connect to Wi-Fi network with SSID and password | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | WiFi.begin(ssid, | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | // Print local IP address and start web server | ||
+ | Serial.println("" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | server.begin(); | ||
+ | } | ||
+ | |||
+ | void loop(){ | ||
+ | WiFiClient client = server.available(); | ||
+ | |||
+ | if (client) { // If a new client connects, | ||
+ | Serial.println(" | ||
+ | String currentLine = ""; | ||
+ | currentTime = millis(); | ||
+ | previousTime = currentTime; | ||
+ | while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client' | ||
+ | currentTime = millis(); | ||
+ | if (client.available()) { // if there' | ||
+ | char c = client.read(); | ||
+ | Serial.write(c); | ||
+ | header += c; | ||
+ | if (c == ' | ||
+ | // if the current line is blank, you got two newline characters in a row. | ||
+ | // that's the end of the client HTTP request, so send a response: | ||
+ | if (currentLine.length() == 0) { | ||
+ | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) | ||
+ | // and a content-type so the client knows what's coming, then a blank line: | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(); | ||
+ | |||
+ | // turns the GPIOs on and off | ||
+ | if (header.indexOf(" | ||
+ | Serial.println(" | ||
+ | output5State = " | ||
+ | digitalWrite(output5, | ||
+ | mp3.playWithVolume(track2, | ||
+ | delay(50); | ||
+ | |||
+ | |||
+ | } else if (header.indexOf(" | ||
+ | Serial.println(" | ||
+ | output5State = " | ||
+ | digitalWrite(output5, | ||
+ | mp3.stopPlay(); | ||
+ | delay(50); | ||
+ | |||
+ | |||
+ | } else if (header.indexOf(" | ||
+ | Serial.println(" | ||
+ | output4State = " | ||
+ | |||
+ | //Actions | ||
+ | digitalWrite(output4, | ||
+ | mp3.playWithVolume(track, | ||
+ | delay(50); | ||
+ | |||
+ | |||
+ | } else if (header.indexOf(" | ||
+ | Serial.println(" | ||
+ | output4State = " | ||
+ | digitalWrite(output4, | ||
+ | mp3.stopPlay(); | ||
+ | delay(50); | ||
+ | } | ||
+ | |||
+ | // Display the HTML web page | ||
+ | client.println("< | ||
+ | client.println("< | ||
+ | client.println("< | ||
+ | // CSS to style the on/off buttons | ||
+ | // Feel free to change the background-color and font-size attributes to fit your preferences | ||
+ | client.println("< | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | |||
+ | // Web Page Heading | ||
+ | client.println("< | ||
+ | |||
+ | // Display current state, and ON/OFF buttons for GPIO 5 | ||
+ | client.println("< | ||
+ | // If the output5State is off, it displays the ON button | ||
+ | if (output5State==" | ||
+ | client.println("< | ||
+ | } else { | ||
+ | client.println("< | ||
+ | } | ||
+ | |||
+ | // Display current state, and ON/OFF buttons for GPIO 4 | ||
+ | client.println("< | ||
+ | // If the output4State is off, it displays the ON button | ||
+ | if (output4State==" | ||
+ | client.println("< | ||
+ | } else { | ||
+ | client.println("< | ||
+ | } | ||
+ | client.println("</ | ||
+ | |||
+ | // The HTTP response ends with another blank line | ||
+ | client.println(); | ||
+ | // Break out of the while loop | ||
+ | break; | ||
+ | } else { // if you got a newline, then clear currentLine | ||
+ | currentLine = ""; | ||
+ | } | ||
+ | } else if (c != ' | ||
+ | currentLine += c; // add it to the end of the currentLine | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | // Clear the header variable | ||
+ | header = ""; | ||
+ | // Close the connection | ||
+ | client.stop(); | ||
+ | Serial.println(" | ||
+ | Serial.println("" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{: | ||
Code pour afficher les images du projet : | Code pour afficher les images du projet : | ||
{{gallery>?& | {{gallery>?& |