Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 5 additions & 0 deletions badgeuse_nfc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
10 changes: 10 additions & 0 deletions badgeuse_nfc/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
37 changes: 37 additions & 0 deletions badgeuse_nfc/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

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 convention is to give header files names that end with `.h'.

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 changes: 46 additions & 0 deletions badgeuse_nfc/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.

The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").

For example, see the structure of the following example libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for 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

Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
18 changes: 18 additions & 0 deletions badgeuse_nfc/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[env:esp32-c6-devkitm-1]
; On force l'utilisation d'une plateforme qui intègre Arduino 3.x
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
board = esp32-c6-devkitm-1
framework = arduino
monitor_speed = 115200

; Ces deux lignes sont cruciales pour les ESP32-C6 !
; Elles forcent l'affichage du Serial Monitor sur le port USB natif de la puce.
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1

lib_deps =
adafruit/Adafruit PN532 @ ^1.3.0

monitor_dtr = 0
monitor_rts = 0
147 changes: 147 additions & 0 deletions badgeuse_nfc/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_PN532.h>

// ==========================================
// 1. CONFIGURATION RÉSEAU & API
// ==========================================
const char *ssid = "HUAWEI-45D7";
const char *password = "72935939";

// L'URL de ton script PHP sur IONOS (utilise https si possible)
const char *serverName = "https://dev-reservation.campusfab.net/ControlLab/config/pointage.php";
String api_key = "votre_cle_api_secrete"; // Pour sécuriser ton API

// ==========================================
// 2. CONFIGURATION LECTEUR NFC (PN532 en I2C)
// ==========================================
#define SDA_PIN 21
#define SCL_PIN 22

// On passe des broches par défaut (2 et 3) pour IRQ et RESET (même si on ne les câble pas).
// Cela force la librairie à utiliser le mode "I2C Matériel" au lieu d'essayer de bidouiller les broches.
Adafruit_PN532 nfc(2, 3);

// ==========================================
// FONCTIONS UTILITAIRES
// ==========================================

// Fonction pour envoyer la donnée au serveur
void envoyerPointage(String uid_str)
{
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http;

// Début de la connexion
http.begin(serverName);

// On précise qu'on envoie les données comme un formulaire web
http.addHeader("Content-Type", "application/x-www-form-urlencoded");

// Préparation des données (ex: api_key=cle_secrete_123&uid=A1B2C3D4)
String httpRequestData = "api_key=" + api_key + "&uid=" + uid_str;

Serial.print("Envoi en cours pour l'UID: ");
Serial.println(uid_str);

// Envoi de la requête POST
int httpResponseCode = http.POST(httpRequestData);

if (httpResponseCode > 0)
{
Serial.print("Succès ! Code HTTP : ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println("Réponse du serveur : " + payload);
}
else
{
Serial.print("Erreur lors de l'envoi HTTP. Code : ");
Serial.println(httpResponseCode);
}

http.end(); // Libère les ressources
}
else
{
Serial.println("Erreur : ESP32 déconnecté du Wi-Fi");
}
}

// ==========================================
// INITIALISATION
// ==========================================
void setup()
{
Serial.begin(115200);
delay(2000); // Délai plus long pour ESP32-C6

Serial.println("\n\n=== ESP32-C6 DÉMARRÉ ===");
Serial.println("Si vous voyez ce message, le Serial fonctionne !");

// --- Connexion Wi-Fi ---
Serial.print("Connexion au Wi-Fi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("\nConnecté au réseau ! IP: " + WiFi.localIP().toString());

// --- Initialisation NFC ---
Serial.println("Initialisation du bus I2C...");

// ÉTAPE CRUCIALE POUR L'ESP32-C6 : On route le signal I2C sur les broches 21 et 22
Wire.begin(SDA_PIN, SCL_PIN);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (!versiondata)
{
Serial.print("Lecteur PN532 introuvable. Vérifiez le câblage !");
while (1)
; // On bloque ici si pas de lecteur
}

Serial.println("Lecteur NFC trouvé et prêt !");
// Configure la carte pour lire les tags RFID classiques (Mifare)
nfc.SAMConfig();
}

// ==========================================
// BOUCLE PRINCIPALE
// ==========================================
void loop()
{
uint8_t success;
uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0}; // Buffer pour stocker l'UID lu
uint8_t uidLength; // Longueur de l'UID (4 ou 7 octets)

// Attend passivement qu'une carte soit approchée
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

if (success)
{
Serial.println("\n--- CARTE DÉTECTÉE ---");

// Conversion du tableau de bytes (uid) en String Hexadécimal lisible
String uidString = "";
for (uint8_t i = 0; i < uidLength; i++)
{
if (uid[i] < 0x10)
uidString += "0"; // Ajoute un zéro pour garder 2 caractères (ex: 0A)
uidString += String(uid[i], HEX);
}

uidString.toUpperCase(); // Met tout en majuscules (ex: a1b2 -> A1B2)

// Envoi au serveur
envoyerPointage(uidString);

// Délai pour éviter de scanner la même carte 50 fois par seconde si on la laisse posée
delay(3000);
}
}
11 changes: 11 additions & 0 deletions badgeuse_nfc/test/README
Original file line number Diff line number Diff line change
@@ -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