Tracking du dossier VHard (les différents code des ESP, matériels embarqués.. etc)

This commit is contained in:
Jérémy CHOMAZ 2025-05-11 18:17:33 +02:00
parent c75dc90ad4
commit 7d8ed224aa
8 changed files with 294 additions and 11 deletions

View File

@ -0,0 +1,97 @@
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/1";
const char* mqtt_message = "{\"buzzer_id\": 1, \"color\": \"#2867d4\"}";
//hostname wifi et client id mqtt
const char* esp_name = "BUZZER-1";
#define PIN D2 // Pin de données connectée à la bande WS2812B
#define NUM_LEDS 1 // Nombre de LEDs dans la bande
#define BRIGHTNESS 127 // Luminosité (127 = ~50%)
// Déclaration des broches
#define BUTTON_PIN D8
WiFiClient espClient;
PubSubClient client(espClient);
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void blinkWhileConnecting() {
static unsigned long previousMillis = 0;
static bool ledState = false;
const long interval = 300; // clignotement toutes les 300ms
while (WiFi.status() != WL_CONNECTED) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledState = !ledState;
strip.setPixelColor(0, ledState ? strip.Color(255, 255, 255) : 0); // Jaune ON/OFF
strip.show();
}
yield(); // permet à l'ESP de ne pas bloquer le watchdog
}
// Une fois connecté, on allume la LED en fixe
strip.setPixelColor(0, strip.Color(0, 0, 255));
strip.show();
}
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connexion au WiFi...");
WiFi.hostname(esp_name);
WiFi.begin(ssid, password);
blinkWhileConnecting(); // Clignotement pendant la connexion
Serial.println("\nWiFi connecté");
Serial.print("Adresse IP: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
while (!client.connected()) {
Serial.print("Connexion au broker MQTT...");
if (client.connect(esp_name)) {
Serial.println("connecté");
} else {
Serial.print("échec, rc=");
Serial.print(client.state());
Serial.println("; nouvelle tentative dans 5 secondes");
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.setPixelColor(0, strip.Color(255, 255, 255));
strip.show();
setup_wifi();
client.setServer(mqtt_server, 1883);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Vérifier si le bouton est pressé
if (digitalRead(BUTTON_PIN) == HIGH) {
Serial.println("Bouton pressé, envoi du message...");
client.publish(mqtt_topic, mqtt_message);
delay(200); // Anti-rebond pour éviter les publications multiples
}
}

View File

@ -3,8 +3,8 @@
#include <Adafruit_NeoPixel.h>
// Configurations WiFi et MQTT
const char* ssid = "SaucissonLand";
const char* password = "47C619A574D41311C811EB563C";
const char* ssid = "fablab";
const char* password = "geek make code do";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/3";
const char* mqtt_message = "{\"buzzer_id\": 3, \"color\": \"#D4D100\"}";
@ -39,7 +39,7 @@ void blinkWhileConnecting() {
}
// Une fois connecté, on allume la LED en fixe
strip.setPixelColor(0, strip.Color(0, 255, 0));
strip.setPixelColor(0, strip.Color(255, 255, 0));
strip.show();
}

View File

@ -0,0 +1,97 @@
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/2";
const char* mqtt_message = "{\"buzzer_id\": 2, \"color\": \"#d42828\"}";
//hostname wifi et client id mqtt
const char* esp_name = "BUZZER-2";
#define PIN D2 // Pin de données connectée à la bande WS2812B
#define NUM_LEDS 1 // Nombre de LEDs dans la bande
#define BRIGHTNESS 127 // Luminosité (127 = ~50%)
// Déclaration des broches
#define BUTTON_PIN D8
WiFiClient espClient;
PubSubClient client(espClient);
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void blinkWhileConnecting() {
static unsigned long previousMillis = 0;
static bool ledState = false;
const long interval = 300; // clignotement toutes les 300ms
while (WiFi.status() != WL_CONNECTED) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledState = !ledState;
strip.setPixelColor(0, ledState ? strip.Color(255, 255, 255) : 0); // Jaune ON/OFF
strip.show();
}
yield(); // permet à l'ESP de ne pas bloquer le watchdog
}
// Une fois connecté, on allume la LED en fixe
strip.setPixelColor(0, strip.Color(255, 0, 0));
strip.show();
}
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connexion au WiFi...");
WiFi.hostname(esp_name);
WiFi.begin(ssid, password);
blinkWhileConnecting(); // Clignotement pendant la connexion
Serial.println("\nWiFi connecté");
Serial.print("Adresse IP: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
while (!client.connected()) {
Serial.print("Connexion au broker MQTT...");
if (client.connect(esp_name)) {
Serial.println("connecté");
} else {
Serial.print("échec, rc=");
Serial.print(client.state());
Serial.println("; nouvelle tentative dans 5 secondes");
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.setPixelColor(0, strip.Color(255, 255, 255));
strip.show();
setup_wifi();
client.setServer(mqtt_server, 1883);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Vérifier si le bouton est pressé
if (digitalRead(BUTTON_PIN) == HIGH) {
Serial.println("Bouton pressé, envoi du message...");
client.publish(mqtt_topic, mqtt_message);
delay(200); // Anti-rebond pour éviter les publications multiples
}
}

View File

@ -0,0 +1,97 @@
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/4";
const char* mqtt_message = "{\"buzzer_id\": 4, \"color\": \"#28d42e\"}";
//hostname wifi et client id mqtt
const char* esp_name = "BUZZER-4";
#define PIN D2 // Pin de données connectée à la bande WS2812B
#define NUM_LEDS 1 // Nombre de LEDs dans la bande
#define BRIGHTNESS 127 // Luminosité (127 = ~50%)
// Déclaration des broches
#define BUTTON_PIN D8
WiFiClient espClient;
PubSubClient client(espClient);
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void blinkWhileConnecting() {
static unsigned long previousMillis = 0;
static bool ledState = false;
const long interval = 300; // clignotement toutes les 300ms
while (WiFi.status() != WL_CONNECTED) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledState = !ledState;
strip.setPixelColor(0, ledState ? strip.Color(255, 255, 255) : 0); // Jaune ON/OFF
strip.show();
}
yield(); // permet à l'ESP de ne pas bloquer le watchdog
}
// Une fois connecté, on allume la LED en fixe
strip.setPixelColor(0, strip.Color(0, 255, 0));
strip.show();
}
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connexion au WiFi...");
WiFi.hostname(esp_name);
WiFi.begin(ssid, password);
blinkWhileConnecting(); // Clignotement pendant la connexion
Serial.println("\nWiFi connecté");
Serial.print("Adresse IP: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
while (!client.connected()) {
Serial.print("Connexion au broker MQTT...");
if (client.connect(esp_name)) {
Serial.println("connecté");
} else {
Serial.print("échec, rc=");
Serial.print(client.state());
Serial.println("; nouvelle tentative dans 5 secondes");
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.setPixelColor(0, strip.Color(255, 255, 255));
strip.show();
setup_wifi();
client.setServer(mqtt_server, 1883);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Vérifier si le bouton est pressé
if (digitalRead(BUTTON_PIN) == HIGH) {
Serial.println("Bouton pressé, envoi du message...");
client.publish(mqtt_topic, mqtt_message);
delay(200); // Anti-rebond pour éviter les publications multiples
}
}

View File

@ -4,8 +4,6 @@
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
//const char* ssid = "SaucissonLand";
//const char* password = "47C619A574D41311C811EB563C";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/1";
const char* mqtt_message = "{\"buzzer_id\": 1, \"color\": \"#2867D4\"}";

View File

@ -4,8 +4,6 @@
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
//const char* ssid = "SaucissonLand";
//const char* password = "47C619A574D41311C811EB563C";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/4";
const char* mqtt_message = "{\"buzzer_id\": 4, \"color\": \"#D4D100\"}";

View File

@ -4,8 +4,6 @@
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
//const char* ssid = "SaucissonLand";
//const char* password = "47C619A574D41311C811EB563C";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/2";
const char* mqtt_message = "{\"buzzer_id\": 2, \"color\": \"#D42828\"}";

View File

@ -4,8 +4,6 @@
// Configurations WiFi et MQTT
const char* ssid = "fablab";
const char* password = "geek make code do";
//const char* ssid = "SaucissonLand";
//const char* password = "47C619A574D41311C811EB563C";
const char* mqtt_server = "192.168.73.20";
const char* mqtt_topic = "vulture/buzzer/pressed/3";
const char* mqtt_message = "{\"buzzer_id\": 3, \"color\": \"#28D42E\"}";