Initial commit
This commit is contained in:
5
ESP8266/.gitignore
vendored
Normal file
5
ESP8266/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
39
ESP8266/include/README
Normal file
39
ESP8266/include/README
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
46
ESP8266/lib/README
Normal file
46
ESP8266/lib/README
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
17
ESP8266/platformio.ini
Normal file
17
ESP8266/platformio.ini
Normal file
@@ -0,0 +1,17 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:d1_mini]
|
||||
platform = espressif8266
|
||||
board = d1_mini
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
|
||||
upload_protocol = esptool
|
||||
65
ESP8266/src/main.cpp
Normal file
65
ESP8266/src/main.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
// Remplacez par les informations de votre réseau WiFi
|
||||
const char* ssid = "Le chateau de Chantenay";
|
||||
const char* password = "crevette4ever";
|
||||
|
||||
// Adresse du serveur HTTP sur le PC
|
||||
const char* host = "192.168.1.62"; // Remplacez par l'adresse IP de votre PC
|
||||
const int port = 5000;
|
||||
|
||||
const int buttonPin = D7; // Définir le pin du bouton
|
||||
bool lastButtonState = HIGH; // État précédent du bouton
|
||||
unsigned long lastDebounceTime = 0; // Dernier temps de changement d'état
|
||||
unsigned long debounceDelay = 50; // Délai de débounce (en millisecondes)
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.print("Connexion à ");
|
||||
Serial.print(ssid);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println(" connectée");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(buttonPin); // Lire l'état du bouton
|
||||
|
||||
// Vérifier le débounce
|
||||
if (buttonState != lastButtonState) {
|
||||
lastDebounceTime = millis(); // Réinitialiser le temps de débounce
|
||||
}
|
||||
|
||||
// Si l'état du bouton a changé et que le temps de débounce est passé
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// Si le bouton est pressé (état LOW)
|
||||
if (buttonState == LOW) {
|
||||
Serial.println("Bouton pressé! Envoi de la requête...");
|
||||
WiFiClient client;
|
||||
if (client.connect(host, port)) {
|
||||
client.print(String("GET /execute?box_id=1 HTTP/1.1\r\n") +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Connection: close\r\n\r\n");
|
||||
|
||||
// Attendre et lire la réponse
|
||||
while (client.available()) {
|
||||
String line = client.readStringUntil('\r');
|
||||
Serial.print(line);
|
||||
}
|
||||
client.stop();
|
||||
} else {
|
||||
Serial.println("Échec de la connexion au serveur.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastButtonState = buttonState; // Enregistrer l'état actuel du bouton
|
||||
}
|
||||
11
ESP8266/test/README
Normal file
11
ESP8266/test/README
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||
49
ESP8266/test/buzzer.cpp
Normal file
49
ESP8266/test/buzzer.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
// Remplacez par les informations de votre réseau WiFi
|
||||
const char* ssid = "Le chateau de Chantenay";
|
||||
const char* password = "crevette4ever";
|
||||
|
||||
// Adresse du serveur HTTP sur le PC
|
||||
const char* host = "192.168.1.62"; // Remplacez par l'adresse IP de votre PC
|
||||
const int port = 5000;
|
||||
|
||||
const int buttonPin = D7; // Définir le pin du bouton
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.print("Connexion à ");
|
||||
Serial.print(ssid);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println(" connectée");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (digitalRead(buttonPin) == HIGH) { // Si le bouton est pressé
|
||||
Serial.println("Bouton pressé! Envoi de la requête...");
|
||||
WiFiClient client;
|
||||
if (client.connect(host, port)) {
|
||||
client.print(String("GET /execute HTTP/1.1\r\n") +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Connection: close\r\n\r\n");
|
||||
delay(500); // Attendre la réponse
|
||||
while (client.available()) {
|
||||
String line = client.readStringUntil('\r');
|
||||
Serial.print(line);
|
||||
}
|
||||
client.stop();
|
||||
} else {
|
||||
Serial.println("Échec de la connexion au serveur.");
|
||||
}
|
||||
}
|
||||
delay(100); // Attendre un peu avant de vérifier à nouveau
|
||||
}
|
||||
90
ESP8266/test/main_new.cpp
Normal file
90
ESP8266/test/main_new.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
// Remplacez par les informations de votre réseau WiFi
|
||||
const char* ssid = "Le chateau de Chantenay";
|
||||
const char* password = "crevette4ever";
|
||||
|
||||
// Adresse du serveur HTTP sur le PC
|
||||
const char* host = "192.168.1.62"; // Remplacez par l'adresse IP de votre PC
|
||||
const int port = 5000;
|
||||
|
||||
const int buttonPin = D7; // Définir le pin du bouton
|
||||
const int ledPin = D5; // Définir le pin de la LED
|
||||
|
||||
// Variables pour la gestion de l'état du jeu
|
||||
bool gameActive = false;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
digitalWrite(ledPin, LOW); // Éteindre la LED au démarrage
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.print("Connexion à ");
|
||||
Serial.print(ssid);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println(" connectée");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Lire l'état du bouton
|
||||
if (digitalRead(buttonPin) == HIGH) { // Si le bouton est pressé
|
||||
Serial.println("Bouton pressé! Envoi de la requête...");
|
||||
sendRequest();
|
||||
delay(500); // Attendre la réponse
|
||||
}
|
||||
|
||||
// Vérifier si le jeu est actif
|
||||
if (gameActive) {
|
||||
// Clignoter la LED pendant que le jeu est actif
|
||||
digitalWrite(ledPin, HIGH);
|
||||
delay(250);
|
||||
digitalWrite(ledPin, LOW);
|
||||
delay(250);
|
||||
}
|
||||
}
|
||||
|
||||
void sendRequest() {
|
||||
WiFiClient client;
|
||||
if (client.connect(host, port)) {
|
||||
client.print(String("GET /execute?box_id=1 HTTP/1.1\r\n") +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Connection: close\r\n\r\n");
|
||||
|
||||
while (client.available()) {
|
||||
String line = client.readStringUntil('\r');
|
||||
Serial.print(line);
|
||||
// Gérer les messages reçus pour changer l'état de la LED
|
||||
if (line.indexOf("fastest") >= 0) {
|
||||
// Allumer la LED si le message "fastest" est reçu
|
||||
digitalWrite(ledPin, HIGH);
|
||||
gameActive = false; // Arrêter le clignotement
|
||||
} else if (line.indexOf("second") >= 0) {
|
||||
// Éteindre la LED si le message "second" est reçu
|
||||
digitalWrite(ledPin, LOW);
|
||||
} else if (line.indexOf("game_active") >= 0) {
|
||||
// Si le jeu est actif, activer le clignotement
|
||||
gameActive = true;
|
||||
} else if (line.indexOf("reset_game") >= 0) {
|
||||
// Réinitialiser le jeu et faire clignoter la LED
|
||||
gameActive = false; // Arrêter le clignotement
|
||||
for (int i = 0; i < 5; i++) { // Clignoter 5 fois pour signaler la réinitialisation
|
||||
digitalWrite(ledPin, HIGH);
|
||||
delay(250);
|
||||
digitalWrite(ledPin, LOW);
|
||||
delay(250);
|
||||
}
|
||||
}
|
||||
}
|
||||
client.stop();
|
||||
} else {
|
||||
Serial.println("Échec de la connexion au serveur.");
|
||||
}
|
||||
}
|
||||
53
ESP8266/test/testBouton.cpp
Normal file
53
ESP8266/test/testBouton.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
// Définir les pins
|
||||
const int buttonPin = D1; // Pin du bouton
|
||||
const int ledPin = LED_BUILTIN; // Pin de la LED intégrée (D4 sur la plupart des cartes ESP8266)
|
||||
|
||||
// Variables pour suivre l'état du bouton et de la LED
|
||||
bool ledState = LOW; // État initial de la LED
|
||||
bool lastButtonState = HIGH; // Dernier état du bouton
|
||||
unsigned long lastDebounceTime = 0; // Dernière fois que l'état du bouton a changé
|
||||
unsigned long debounceDelay = 50; // Temps de debounce pour éviter les rebonds du bouton
|
||||
|
||||
void setup() {
|
||||
// Initialiser la communication série
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialiser les pins
|
||||
pinMode(buttonPin, INPUT_PULLUP); // Pin du bouton en entrée avec pull-up interne
|
||||
pinMode(ledPin, OUTPUT); // Pin de la LED en sortie
|
||||
|
||||
// Assurer que la LED est éteinte au démarrage
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Lire l'état du bouton
|
||||
int buttonState = digitalRead(buttonPin);
|
||||
|
||||
// Vérifier si l'état du bouton a changé depuis la dernière lecture
|
||||
if (buttonState != lastButtonState) {
|
||||
lastDebounceTime = millis(); // Réinitialiser le temps de debounce
|
||||
}
|
||||
|
||||
// Si le bouton a été maintenu dans le nouvel état assez longtemps
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// Si le bouton est maintenant pressé (état bas car pin est en pull-up)
|
||||
if (buttonState == LOW && lastButtonState == HIGH) {
|
||||
// Inverser l'état de la LED
|
||||
ledState = !ledState;
|
||||
digitalWrite(ledPin, ledState); // Mettre à jour l'état de la LED
|
||||
|
||||
// Afficher l'état de la LED sur le moniteur série
|
||||
if (ledState == HIGH) {
|
||||
Serial.println("LED allumée");
|
||||
} else {
|
||||
Serial.println("LED éteinte");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sauvegarder l'état du bouton pour la prochaine lecture
|
||||
lastButtonState = buttonState;
|
||||
}
|
||||
Reference in New Issue
Block a user