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 14:12] admin [Code] |
projets:cctv_disco:start [2022/04/06 17:31] (Version actuelle) risbo [Photos et médias] |
||
---|---|---|---|
Ligne 49: | Ligne 49: | ||
==== Code ==== | ==== Code ==== | ||
- | Pour l' | + | Code qui cree une pageweb |
+ | L'url de la page est donné en serie. (en l' | ||
<code c+> | <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;//0~0x1e (30 adjustable level) | ||
+ | |||
// Load Wi-Fi library | // Load Wi-Fi library | ||
#include < | #include < | ||
+ | |||
// Replace with your network credentials | // Replace with your network credentials | ||
const char* ssid = " | const char* ssid = " | ||
const char* password = " | const char* password = " | ||
+ | |||
// Set web server port number to 80 | // Set web server port number to 80 | ||
WiFiServer server(80); | WiFiServer server(80); | ||
+ | |||
// Variable to store the HTTP request | // Variable to store the HTTP request | ||
String header; | String header; | ||
+ | |||
// Auxiliar variables to store the current output state | // Auxiliar variables to store the current output state | ||
String output5State = " | String output5State = " | ||
String output4State = " | String output4State = " | ||
+ | |||
// Assign output variables to GPIO pins | // Assign output variables to GPIO pins | ||
const int output5 = 5; | const int output5 = 5; | ||
const int output4 = 4; | const int output4 = 4; | ||
+ | |||
// Current time | // Current time | ||
unsigned long currentTime = millis(); | unsigned long currentTime = millis(); | ||
Ligne 83: | Ligne 94: | ||
// Define timeout time in milliseconds (example: 2000ms = 2s) | // Define timeout time in milliseconds (example: 2000ms = 2s) | ||
const long timeoutTime = 2000; | const long timeoutTime = 2000; | ||
+ | |||
void setup() { | void setup() { | ||
Serial.begin(115200); | Serial.begin(115200); | ||
Ligne 92: | Ligne 103: | ||
digitalWrite(output5, | digitalWrite(output5, | ||
digitalWrite(output4, | digitalWrite(output4, | ||
+ | |||
// Connect to Wi-Fi network with SSID and password | // Connect to Wi-Fi network with SSID and password | ||
Serial.print(" | Serial.print(" | ||
Ligne 108: | Ligne 119: | ||
server.begin(); | server.begin(); | ||
} | } | ||
+ | |||
void loop(){ | void loop(){ | ||
WiFiClient client = server.available(); | WiFiClient client = server.available(); | ||
+ | |||
if (client) { // If a new client connects, | if (client) { // If a new client connects, | ||
Serial.println(" | Serial.println(" | ||
Ligne 133: | Ligne 144: | ||
client.println(" | client.println(" | ||
client.println(); | client.println(); | ||
- | | + | |
// turns the GPIOs on and off | // turns the GPIOs on and off | ||
if (header.indexOf(" | if (header.indexOf(" | ||
Ligne 139: | Ligne 150: | ||
output5State = " | output5State = " | ||
digitalWrite(output5, | digitalWrite(output5, | ||
+ | mp3.playWithVolume(track2, | ||
+ | delay(50); | ||
+ | |||
+ | | ||
} else if (header.indexOf(" | } else if (header.indexOf(" | ||
Serial.println(" | Serial.println(" | ||
output5State = " | output5State = " | ||
digitalWrite(output5, | digitalWrite(output5, | ||
+ | mp3.stopPlay(); | ||
+ | delay(50); | ||
+ | |||
+ | | ||
} else if (header.indexOf(" | } else if (header.indexOf(" | ||
Serial.println(" | Serial.println(" | ||
output4State = " | output4State = " | ||
+ | |||
+ | // | ||
digitalWrite(output4, | digitalWrite(output4, | ||
+ | mp3.playWithVolume(track, | ||
+ | delay(50); | ||
+ | |||
+ | | ||
} else if (header.indexOf(" | } else if (header.indexOf(" | ||
Serial.println(" | Serial.println(" | ||
output4State = " | output4State = " | ||
digitalWrite(output4, | digitalWrite(output4, | ||
+ | mp3.stopPlay(); | ||
+ | delay(50); | ||
} | } | ||
- | | + | |
// Display the HTML web page | // Display the HTML web page | ||
client.println("< | client.println("< | ||
Ligne 163: | Ligne 190: | ||
client.println(" | client.println(" | ||
client.println(" | client.println(" | ||
- | | + | |
// Web Page Heading | // Web Page Heading | ||
client.println("< | client.println("< | ||
- | | + | |
// Display current state, and ON/OFF buttons for GPIO 5 | // Display current state, and ON/OFF buttons for GPIO 5 | ||
client.println("< | client.println("< | ||
Ligne 175: | Ligne 202: | ||
client.println("< | client.println("< | ||
} | } | ||
- | + | ||
// Display current state, and ON/OFF buttons for GPIO 4 | // Display current state, and ON/OFF buttons for GPIO 4 | ||
client.println("< | client.println("< | ||
Ligne 185: | Ligne 212: | ||
} | } | ||
client.println("</ | client.println("</ | ||
- | | + | |
// The HTTP response ends with another blank line | // The HTTP response ends with another blank line | ||
client.println(); | client.println(); | ||
Ligne 206: | Ligne 233: | ||
} | } | ||
} | } | ||
- | |||
</ | </ | ||
- | ===== Photos et médias===== | + | {{: |
Code pour afficher les images du projet : | Code pour afficher les images du projet : | ||
{{gallery>?& | {{gallery>?& |