Clavier alarme

Aprés si tu veux utiliser le dahua rien ne t’empêche de prendre un contrôleur qui va avec et tu lui colle un smart implant

1 « J'aime »

Ok je commence a comprendre un peu ^^

J’ai pensé partir sur ça:

Avec un contrôleur qui gère les sorties wiegand

L’installation comporterait deux claviers RFID mais le contrôleur rester cher quand même
Merci

Pour connecter un lecteur de badge wiegand, un arduino fait très bien l’affaire. Il y a une bibliothèque wiegand qui permet avec un peu de codage d’envoyer (par exemple) le code tapé ou le badge lu en MQTT vers un broker.

J’ai commandé le lecteur, j’ai un Arduino. Je demanderai sûrement des conseils
Merci beaucoup

1 « J'aime »

Bonjour, j’ai bien reçu le clavier. et j’ai ressorti mon arduino de test.
J’ai télécharger le plugin badger:
apparemment on peut récupérer le sketch arduino+ W5100 mais rien ne se s’ouvre quand je clique dessus.

Voilà mon sketch Arduino. A adapter au type d’Ethernet W5100 et à ton environnement.

#include <SPI.h>
#include <Ethernet.h>
#include <Wiegand.h> 

#define SERRURE 4 /* PIN sur lequel est connecté le relai */
#define LUMIERE 9 /* PIN sur lequel la lumière du clavier est connectée */
#define pirPIN 6

int pirState = LOW;
int pirVal = LOW;

String wgPINCODE ="";

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x0E, 0xBE, 0xFE, 0x32, 0x12, 0x99 };

#include <PubSubClient.h>
long stayon = 500;

void callback(char* topic, byte* payload, unsigned int length);

const char* mqtt_server = "192.168.x.t";
const char* mqtt_input = "porte/input";
const char* mqtt_output = "porte/output";
IPAddress ipEth(192, 168, x, y);
IPAddress ipDNS(192, 168, x, z);
IPAddress subnet(255, 255, 255, 0);

void callback(char* topic, byte* payload, unsigned int length);

WIEGAND wg;
EthernetClient ethClient;
PubSubClient client(mqtt_server, 1883, callback, ethClient);
long lastMsg = 0;

char message_buff[100];

void setup() {
  Serial.begin(115200);
  setup_eth();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  wg.begin(2,3); /* vert et blanc sur sont 2 et 3 */
  pinMode(SERRURE, OUTPUT);
  pinMode(LUMIERE, OUTPUT);
  pinMode(pirPIN, INPUT);
  digitalWrite(SERRURE, LOW);   
  digitalWrite(LUMIERE, HIGH);  
}

void setup_eth() {

/*  
   if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
  }
*/
  Ethernet.begin(mac, ipEth, ipDNS);

  Serial.println(Ethernet.localIP());
  
}

void callback(char* topic, byte* payload, unsigned int length) {
  payload[length] = '\0';
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
  String message((char*)payload);

  if (message == "open") {
    digitalWrite(SERRURE, HIGH);   
    digitalWrite(LUMIERE, LOW);   
    delay(stayon);
    digitalWrite(SERRURE, LOW);   
    digitalWrite(LUMIERE, HIGH);   
  } 
  if (message == "confirm") {
    digitalWrite(LUMIERE, LOW);   
    delay(stayon);
    digitalWrite(LUMIERE, HIGH);   
  }
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("GarageWiegand")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.subscribe(mqtt_input);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}
void loop() {
  if (!client.connected()) {
    reconnect();
  }

  pirVal = digitalRead(pirPIN);

  
  if (pirVal == HIGH) { // check if the input is HIGH
 //         Serial.println("pirVal  High!");

    delay(150);
    if (pirState == LOW) {
      Serial.println("Motion detected!");
      client.publish(mqtt_output,"moveon");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  }
  else {
 //             Serial.println("pirVal  low!");

    if (pirState == HIGH) {
        Serial.println("Motion stopped!");
        client.publish(mqtt_output,"moveoff");
        pirState = LOW;
    }
  }
  
  if(wg.available()) {
    if ( wg.getWiegandType() == 8 || wg.getWiegandType() == 4 )
       {
          unsigned long wgCODE = wg.getCode();
          if  (wgCODE == 13 )
            {
              char wgCodeChar[16];
//              sprintf(wgCodeChar, "%s", wgPINCODE);
              wgPINCODE.toCharArray(wgCodeChar, 16);
              client.publish(mqtt_output,wgCodeChar);
              Serial.println(wgPINCODE);
              Serial.println(wgCodeChar);
              wgPINCODE = "";
            }
          else if ( wgCODE == 27 )
            {
              wgPINCODE = "";
            }
          else
          {
            wgPINCODE+= String(wgCODE);
            if (wgPINCODE.length() > 15 )
              wgPINCODE = "";
          }
       }
       else
       {
          unsigned long wgCode = wg.getCode();
          char wgCodeChar[16];
          sprintf(wgCodeChar,"%lu",wgCode); 
          Serial.println(wgCodeChar); 
          Serial.println(wg.getCode());
          client.publish(mqtt_output,wgCodeChar);
       }
  }
  client.loop();
}

Donc, ça envoie le code tapé ou le badge en MQTT (porte/output). Et si tu envoies open en MQTT au topic porte/input ça ferme le relai et allume la led du clavier.

Dans le même sketch, j’ai la gestion d’un détecteur de mouvement. Là aussi, envoi de l’info en MQTT.

Je n’utilise plus badger. Je me débrouille en sketch Arduino et je préfère faire le truc moi-même.

Voilà mon clavier.
Pour l’instant il est juste alimenté,
Ton code est adaptable par rapport à mon clavier?

Wiegand W0 est data 0
Wiegand W1 est data 1?

Merci

J’avance petit a petit mais surement. J’ai réussi a téléverser ton code. j’ai donc toutes les librairies bonnes. oufff.
j’essaye d’adapter le code maintenant:

#include <SPI.h>
#include <Ethernet.h>
#include <Wiegand.h>

#define SERRURE 4 /* PIN sur lequel est connecté le relai /
#define LUMIERE 9 /
PIN sur lequel la lumière du clavier est connectée */
#define pirPIN 6

int pirState = LOW;
int pirVal = LOW;

String wgPINCODE =«  »;

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac = { 0x0E, 0xBE, 0xFE, 0x32, 0x12, 0x99 };

#include <PubSubClient.h>
long stayon = 500;

void callback(char* topic, byte* payload, unsigned int length);

const char* mqtt_server = « 192.168.x.t »;
const char* mqtt_input = « porte/input »;
const char* mqtt_output = « porte/output »;
IPAddress ipEth(192, 168, 1, 71);
IPAddress ipDNS(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);

void callback(char* topic, byte* payload, unsigned int length);

WIEGAND wg;
EthernetClient ethClient;
PubSubClient client(mqtt_server, 1883, callback, ethClient);
long lastMsg = 0;

char message_buff[100];

void setup() {
Serial.begin(115200);
setup_eth();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
wg.begin(2,3); /* vert et blanc sur sont 2 et 3 */
pinMode(SERRURE, OUTPUT);
pinMode(LUMIERE, OUTPUT);
pinMode(pirPIN, INPUT);
digitalWrite(SERRURE, LOW);
digitalWrite(LUMIERE, HIGH);
}

void setup_eth() {

/*
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(« Ethernet cable is not connected. »);
}
*/
Ethernet.begin(mac, ipEth, ipDNS);

Serial.println(Ethernet.localIP());

}

void callback(char* topic, byte* payload, unsigned int length) {
payload[length] = ‹ \0 ›;
Serial.print(« Message arrived [ »);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
String message((char*)payload);

if (message == « open ») {
digitalWrite(SERRURE, HIGH);
digitalWrite(LUMIERE, LOW);
delay(stayon);
digitalWrite(SERRURE, LOW);
digitalWrite(LUMIERE, HIGH);
}
if (message == « confirm ») {
digitalWrite(LUMIERE, LOW);
delay(stayon);
digitalWrite(LUMIERE, HIGH);
}
}

void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(« Attempting MQTT connection… »);
// Attempt to connect
if (client.connect(« GarageWiegand »)) {
Serial.println(« connected »);
// Once connected, publish an announcement…
client.subscribe(mqtt_input);
} else {
Serial.print(« failed, rc= »);
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}

pirVal = digitalRead(pirPIN);

if (pirVal == HIGH) { // check if the input is HIGH
// Serial.println(« pirVal High! »);

delay(150);
if (pirState == LOW) {
  Serial.println("Motion detected!");
  client.publish(mqtt_output,"moveon");
  // We only want to print on the output change, not state
  pirState = HIGH;
}

}
else {
// Serial.println(« pirVal low! »);

if (pirState == HIGH) {
    Serial.println("Motion stopped!");
    client.publish(mqtt_output,"moveoff");
    pirState = LOW;
}

}

if(wg.available()) {
if ( wg.getWiegandType() == 8 || wg.getWiegandType() == 4 )
{
unsigned long wgCODE = wg.getCode();
if (wgCODE == 13 )
{
char wgCodeChar[16];
// sprintf(wgCodeChar, « %s », wgPINCODE);
wgPINCODE.toCharArray(wgCodeChar, 16);
client.publish(mqtt_output,wgCodeChar);
Serial.println(wgPINCODE);
Serial.println(wgCodeChar);
wgPINCODE = «  »;
}
else if ( wgCODE == 27 )
{
wgPINCODE = «  »;
}
else
{
wgPINCODE+= String(wgCODE);
if (wgPINCODE.length() > 15 )
wgPINCODE = «  »;
}
}
else
{
unsigned long wgCode = wg.getCode();
char wgCodeChar[16];
sprintf(wgCodeChar,« %lu »,wgCode);
Serial.println(wgCodeChar);
Serial.println(wg.getCode());
client.publish(mqtt_output,wgCodeChar);
}
}
client.loop();
}

que dois-je adapter encore?
merci

1 « J'aime »

Bonjour,

Perso j’utilise le plugin Digicode sur un RPi muni d’un petit écran tactile. J’ai intégré l’écran dans un cadre bois, du coup c’est assez design, mais il faut bricoler un peu…

Raj.

Si tu n’as pas de PIR, il vaut mieux virer la partie détection de mouvement.
Donc, ça :

pirVal = digitalRead(pirPIN);

if (pirVal == HIGH) { // check if the input is HIGH
// Serial.println(« pirVal High! »);

delay(150);
if (pirState == LOW) {
  Serial.println("Motion detected!");
  client.publish(mqtt_output,"moveon");
  // We only want to print on the output change, not state
  pirState = HIGH;
}
}
else {
// Serial.println(« pirVal low! »);

if (pirState == HIGH) {
    Serial.println("Motion stopped!");
    client.publish(mqtt_output,"moveoff");
    pirState = LOW;
}
}

Ensuite, il manque l’adresse IP de ton broker mqtt. Dans mon exemple, je n’ai pas d’authentification. Comme je suis en LAN j’ai considéré que ce n’est pas la peine.

Oui. Vert et Blanc sont les deux à connecter sur l’arduino. Si tu prends mon exemple c’est sur 2 et 3 de ton arduino.

Pour débugger tout ça, tu peux utiliser mqtt explorer https://mqtt-explorer.com/
Tu verras ce qui sort et rentre en MQTT.

Tu y es presque :slight_smile:

1 « J'aime »

merci pour cette réponse, je regarde demain ou après demain dès que j’ai du temps de libre.
merci beaucoup

Bonjour, j’ai essayé j’ai supprimé la partie du détecteur de présence, je suppose que je peux supprimer :

int pirState = LOW;
int pirVal = LOW;

?

J’ai télécharger MQTT explorer sur windows pour essayer.
j’ai écrit l’adresse comme ceci du mqtt mais je sais pas si c’est correct:

mqtt://mqtt.eclipse.org:1883

j’en déduit que c’est un public.

Puis-je l’installer sur mon PI pour avoir un MQTT perso?

Mes questions semble peut-etre ridicule, je débute en MQTT mais j’adore apprendre.

Merci

#include <SPI.h>
#include <Ethernet.h>
#include <Wiegand.h>

#define SERRURE 4 /* PIN sur lequel est connecté le relai /
#define LUMIERE 9 /
PIN sur lequel la lumière du clavier est connectée */
#define pirPIN 6

int pirState = LOW;
int pirVal = LOW;

String wgPINCODE =«  »;

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac = { 0x0E, 0xBE, 0xFE, 0x32, 0x12, 0x99 };

#include <PubSubClient.h>
long stayon = 500;

void callback(char* topic, byte* payload, unsigned int length);

const char* mqtt_server = « mqtt://mqtt.eclipse.org:1883 »;
const char* mqtt_input = « porte/input »;
const char* mqtt_output = « porte/output »;
IPAddress ipEth(192, 168, 1, 71);
IPAddress ipDNS(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);

void callback(char* topic, byte* payload, unsigned int length);

WIEGAND wg;
EthernetClient ethClient;
PubSubClient client(mqtt_server, 1883, callback, ethClient);
long lastMsg = 0;

char message_buff[100];

void setup() {
Serial.begin(115200);
setup_eth();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
wg.begin(2,3); /* vert et blanc sur sont 2 et 3 */
pinMode(SERRURE, OUTPUT);
pinMode(LUMIERE, OUTPUT);
pinMode(pirPIN, INPUT);
digitalWrite(SERRURE, LOW);
digitalWrite(LUMIERE, HIGH);
}

void setup_eth() {

/*
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(« Ethernet cable is not connected. »);
}
*/
Ethernet.begin(mac, ipEth, ipDNS);

Serial.println(Ethernet.localIP());

}

void callback(char* topic, byte* payload, unsigned int length) {
payload[length] = ‹ \0 ›;
Serial.print(« Message arrived [ »);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
String message((char*)payload);

if (message == « open ») {
digitalWrite(SERRURE, HIGH);
digitalWrite(LUMIERE, LOW);
delay(stayon);
digitalWrite(SERRURE, LOW);
digitalWrite(LUMIERE, HIGH);
}
if (message == « confirm ») {
digitalWrite(LUMIERE, LOW);
delay(stayon);
digitalWrite(LUMIERE, HIGH);
}
}

void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(« Attempting MQTT connection… »);
// Attempt to connect
if (client.connect(« GarageWiegand »)) {
Serial.println(« connected »);
// Once connected, publish an announcement…
client.subscribe(mqtt_input);
} else {
Serial.print(« failed, rc= »);
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}

if(wg.available()) {
if ( wg.getWiegandType() == 8 || wg.getWiegandType() == 4 )
{
unsigned long wgCODE = wg.getCode();
if (wgCODE == 13 )
{
char wgCodeChar[16];
// sprintf(wgCodeChar, « %s », wgPINCODE);
wgPINCODE.toCharArray(wgCodeChar, 16);
client.publish(mqtt_output,wgCodeChar);
Serial.println(wgPINCODE);
Serial.println(wgCodeChar);
wgPINCODE = «  »;
}
else if ( wgCODE == 27 )
{
wgPINCODE = «  »;
}
else
{
wgPINCODE+= String(wgCODE);
if (wgPINCODE.length() > 15 )
wgPINCODE = «  »;
}
}
else
{
unsigned long wgCode = wg.getCode();
char wgCodeChar[16];
sprintf(wgCodeChar,« %lu »,wgCode);
Serial.println(wgCodeChar);
Serial.println(wg.getCode());
client.publish(mqtt_output,wgCodeChar);
}
}
client.loop();
}

Bonjour,
j’ai bien avancé:

  • l’adresse du mqtt_server est celle de mon Pi ou j’ai jeedom dessus.
  • j’arrive à remonter dans mon mqtt explorer les valeurs du badge ou du code tapé. :grinning: :grinning:
  • j’ai télécharger le plugin mqtt et je retrouve bien les valeurs sur jeedom.

j’ai bricolé le programme pour avoir mes codes corrects qui active bien mes sorties^^
je voudrai simplement récuperer en MQTT la valeur de la serrure ( 1 ou 0) pour la lire sur Jeedom

j’y suis presque :grinning:

> #include <SPI.h>
> #include <Ethernet.h>
> #include <Wiegand.h> 
> 
> #define SERRURE 4 /* PIN sur lequel est connecté le relai */
> #define LUMIERE_V 9 /* PIN sur lequel la lumière verte du clavier est connectée */
> #define LUMIERE_R 8 /* PIN sur lequel la lumière rouge du clavier est connectée */
> #define BIP 7 /* PIN sur lequel le Bip est connectée */
> 
> #define pirPIN 6
> 
> int pirState = LOW;
> int pirVal = LOW;
> 
> String wgPINCODE ="";
> 
> // Enter a MAC address for your controller below.
> // Newer Ethernet shields have a MAC address printed on a sticker on the shield
> byte mac[] = { 0x0E, 0xBE, 0xFE, 0x32, 0x12, 0x99 };
> 
> #include <PubSubClient.h>
> long stayon = 500;
> 
> void callback(char* topic, byte* payload, unsigned int length);
> 
> const char* mqtt_server = "192.168.1.43";
> const char* mqtt_input = "porte/output";
> const char* mqtt_output = "porte/output";
> 
> 
> IPAddress ipEth(192, 168, 1, 71);
> IPAddress ipDNS(192, 168, 1, 254);
> IPAddress subnet(255, 255, 255, 0);
> 
> void callback(char* topic, byte* payload, unsigned int length);
> 
> WIEGAND wg;
> EthernetClient ethClient;
> PubSubClient client(mqtt_server, 1883, callback, ethClient);
> long lastMsg = 0;
> 
> char message_buff[100];
> 
> void setup() {
>   Serial.begin(115200);
>   setup_eth();
>   client.setServer(mqtt_server, 1883);
>   client.setCallback(callback);
>   wg.begin(2,3); /* vert et blanc sur sont 2 et 3 */
>   pinMode(SERRURE, OUTPUT);
>   pinMode(LUMIERE_V, OUTPUT);
>   pinMode(LUMIERE_R, OUTPUT);
>   pinMode(BIP, OUTPUT);
>   pinMode(pirPIN, INPUT);
>   digitalWrite(SERRURE, HIGH);   
>   digitalWrite(LUMIERE_V, HIGH);
>   digitalWrite(LUMIERE_R, HIGH); 
>   digitalWrite(BIP, HIGH);   
> }
> 
> void setup_eth() {
> 
> /*  
>    if (Ethernet.linkStatus() == LinkOFF) {
>       Serial.println("Ethernet cable is not connected.");
>   }
> */
>   Ethernet.begin(mac, ipEth, ipDNS);
> 
>   Serial.println(Ethernet.localIP());
>   
> }
> 
> void callback(char* topic, byte* payload, unsigned int length) {
>   payload[length] = '\0';
>   Serial.print("Message arrived [");
>   Serial.print(topic);
>   Serial.print("] ");
>   for (int i = 0; i < length; i++) {
>     Serial.print((char)payload[i]);
>   }
>   Serial.println();
>   String message((char*)payload);
> 
>   if (message == "5141807" || message == "2712" ||  message == "5164119" ){
>     digitalWrite(SERRURE,LOW);
>     digitalWrite(LUMIERE_V, LOW);
>     digitalWrite(BIP, LOW);  
>         delay(150);
>     digitalWrite(SERRURE, HIGH);
>     digitalWrite(BIP, HIGH);  
>       delay(1500);
>     digitalWrite(LUMIERE_V, HIGH); 
>   } 
>      else  {
>     digitalWrite(LUMIERE_R, LOW);    
>     digitalWrite(BIP, LOW);    
>         delay(110);
>     digitalWrite(BIP, HIGH);
>         delay(110);  
>     digitalWrite(BIP, LOW);    
>         delay(110);
>     digitalWrite(BIP, HIGH);
>         delay(110);  
>     digitalWrite(BIP, LOW);    
>         delay(110);
>     digitalWrite(BIP, HIGH);
>         delay(110);  
>     digitalWrite(BIP, LOW);    
>         delay(110);
>     digitalWrite(BIP, HIGH);
>         delay(110);  
>     digitalWrite(BIP, LOW);    
>         delay(110);
>     digitalWrite(BIP, HIGH);
>     digitalWrite(LUMIERE_R, HIGH);
>      
>     
>        
>   }
>    
> }
> 
> void reconnect() {
>   // Loop until we're reconnected
>   while (!client.connected()) {
>     Serial.print("Attempting MQTT connection...");
>     // Attempt to connect
>     if (client.connect("GarageWiegand")) {
>       Serial.println("connected");
>       // Once connected, publish an announcement...
>       client.subscribe(mqtt_input);
>     } else {
>       Serial.print("failed, rc=");
>       Serial.print(client.state());
>       Serial.println(" try again in 5 seconds");
>       // Wait 5 seconds before retrying
>       delay(5000);
>     }
>   }
> }
> void loop() {
>   if (!client.connected()) {
>     reconnect();
>   }
> 
>   if(wg.available()) {
>     if ( wg.getWiegandType() == 8 || wg.getWiegandType() == 4 )
>        {
>           unsigned long wgCODE = wg.getCode();
>           if  (wgCODE == 13 )
>             {
>               char wgCodeChar[16];
> //              sprintf(wgCodeChar, "%s", wgPINCODE);
>               wgPINCODE.toCharArray(wgCodeChar, 16);
>               client.publish(mqtt_output,wgCodeChar);
>               Serial.println(wgPINCODE);
>               Serial.println(wgCodeChar);
>               wgPINCODE = "";
>             }
>           else if ( wgCODE == 27 )
>             {
>               wgPINCODE = "";
>             }
>           else
>           {
>             wgPINCODE+= String(wgCODE);
>             if (wgPINCODE.length() > 15 )
>               wgPINCODE = "";
>           }
>        }
>        else
>        {
>           unsigned long wgCode = wg.getCode();
>           char wgCodeChar[16];
>           sprintf(wgCodeChar,"%lu",wgCode); 
>           Serial.println(wgCodeChar); 
>           Serial.println(wg.getCode());
>           client.publish(mqtt_output,wgCodeChar);
>        }
>   }
>   client.loop();
> }
> 
> `

Ce sujet a été automatiquement fermé après 24 heures suivant le dernier commentaire. Aucune réponse n’est permise dorénavant.