breadboard
documentação

Projeto de exemplo · Casa inteligente

Sensor de porta Zigbee

Um sensor de porta/janela como produto fechado: o C6 dentro dele roda o firmware de zona IAS do esp-zigbee, e o botão inteligente (o coordenador) forma a rede em que ele entra. A chave DIP entre os terminais de contato faz o papel da porta: mude a chave, e o sensor informa pelo ar uma mudança real de status da zona (acompanhe a aba serial dele e o Wi-Fi sniffer). Clique no sensor para ver o estado de entrada na rede e do contato ao vivo.

O circuito Sensor de porta Zigbee desenhado pelo simulador

Como funciona

Um sensor de porta com fio é só um contato e um rádio, e é exatamente isso que este é. O C6 fechado dentro dele roda o firmware de contato de zona IAS do esp-zigbee: a entrada GPIO4 (com o pull-up interno) lê os dois terminais de contato, e o botão inteligente é o coordenador em cuja rede ele entra. A chave DIP entre os terminais faz o papel da porta: fechada = terminais em curto = contato fechado. Cada mudança chama setClosed()/setOpen() no firmware, que informa pelo ar uma mudança real de status da zona IAS.

O que está na bancada

  • Bateria (Battery)
  • Botão inteligente Zigbee (Zigbee Smart Button)
  • Chave DIP (DIP Switch)
  • Sensor de contato Zigbee (Zigbee Contact Sensor)

Como está ligado

  • Bateria (Battery) · pos→Botão inteligente Zigbee (Zigbee Smart Button) · vcc
  • Bateria (Battery) · neg→Botão inteligente Zigbee (Zigbee Smart Button) · gnd
  • Bateria (Battery) · pos→Sensor de contato Zigbee (Zigbee Contact Sensor) · vcc
  • Bateria (Battery) · neg→Sensor de contato Zigbee (Zigbee Contact Sensor) · gnd
  • Sensor de contato Zigbee (Zigbee Contact Sensor) · c1→Chave DIP (DIP Switch) · a0
  • Sensor de contato Zigbee (Zigbee Contact Sensor) · c2→Chave DIP (DIP Switch) · b0

O código

Os sketches Arduino C++ exatos usados para compilar o firmware incluído. No simulador, abra “Code” para editá-los e clique em “Compile & upload” para recompilar o firmware da placa.

// Zigbee contact sensor (door/window) — an IAS Zone end device.
//
// The contact input is GPIO4 with the internal pull-up: short it to GND
// (door CLOSED) or leave it open (door OPEN), exactly like the two screw
// terminals on a wired door-sensor. Every change reports a genuine IAS
// zone-status change to the coordinator over the air.

#include <Arduino.h>
#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"

#define ZIGBEE_CONTACT_ENDPOINT 10
const uint8_t contact = 4;  // GPIO4: LOW (shorted to GND) = closed

ZigbeeContactSwitch zbContact = ZigbeeContactSwitch(ZIGBEE_CONTACT_ENDPOINT);

void setup() {
  Serial.begin(115200);
  pinMode(contact, INPUT_PULLUP);

  zbContact.setManufacturerAndModel("Breadboard", "DoorSensor");
  Serial.println("Adding ZigbeeContactSwitch endpoint to Zigbee Core");
  Zigbee.addEndpoint(&zbContact);

  if (!Zigbee.begin()) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }
  Serial.println("Connecting to network");
  while (!Zigbee.connected()) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();
  Serial.println("Joined. Contact reports armed (GPIO4: low = closed).");
}

void loop() {
  static int last = -1;
  int level = digitalRead(contact);
  if (level != last) {
    last = level;
    if (level == LOW) {
      zbContact.setClosed();
      Serial.println("DOOR CLOSED (contact made) - reported");
    } else {
      zbContact.setOpen();
      Serial.println("DOOR OPEN (contact broken) - reported");
    }
  }
  delay(100);
}

Licença do firmware (em inglês)

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-zigbee-switch-c6.bin is statically linked with Arduino-ESP32 3.3.10. Parts of this library are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version. You may modify this work for your own use and reverse engineer it to debug those modifications. Download the relink package and corresponding source to rebuild it with a changed library.

It also links Espressif’s ZBOSS Zigbee stack, supplied unchanged under its own licence, which forbids reverse engineering, decompiling, modifying or disassembling the ZBOSS binary itself. Relink with the ZBOSS archives unchanged.

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-zigbee-contact-c6.bin is statically linked with Arduino-ESP32 3.3.10. Parts of this library are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version. You may modify this work for your own use and reverse engineer it to debug those modifications. Download the relink package and corresponding source to rebuild it with a changed library.

It also links Espressif’s ZBOSS Zigbee stack, supplied unchanged under its own licence, which forbids reverse engineering, decompiling, modifying or disassembling the ZBOSS binary itself. Relink with the ZBOSS archives unchanged.

Experimente

  • Espere o sensor entrar na rede (a aba serial dele imprime pontos e depois "Joined").
  • Mude a chave DIP marcada com 1, ligada entre os terminais de contato, e veja DOOR OPEN / DOOR CLOSED aparecer a cada informe transmitido.
  • Clique no sensor: o Inspector mostra o estado de entrada na rede e a posição do contato ao vivo (a barra do ímã desliza).
  • Abra o Wi-Fi sniffer para capturar os quadros de informe da zona IAS.
Informar um problema na tradução

Projetos relacionados