victor
Published

Make a Smart Zigbee Connected Home Sensor Hub

Make a wooden smart clock with Zigbee feature to monitor the environment of your home.

IntermediateFull instructions provided4,037
Make a Smart Zigbee Connected Home Sensor Hub

Things used in this project

Hardware components

EFR32xG21 Wireless Gecko Starter Kit
Silicon Labs EFR32xG21 Wireless Gecko Starter Kit
×1
WGM160P Wi-Fi Module Starter Kit
Silicon Labs WGM160P Wi-Fi Module Starter Kit
×1
Thunderboard™ Sense 2 Sensor-to-Cloud Advanced IoT Development Kit
Silicon Labs Thunderboard™ Sense 2 Sensor-to-Cloud Advanced IoT Development Kit
×1
• Silicon Labs Si7021-A20
×1
• Audio process module XFS5152CE
×1
• Vibration detecting sensor
×1
• 7-Segment LED Digital Tube
×1
• LED drive chip SM74HC595D
×1
• 2 W speaker
×1
• Audio power amplifier PAM8403
×1
• Charger IC tp4056
×1
• Battery
×1

Hand tools and fabrication machines

• Glue
• Flatiron

Story

Read more

Schematics

displayb_page_1_j4pnrOwBAf.jpg

displayb_page_2_jBlZKmNbLu.jpg

mainb_page_1_bBIKPbfase.jpg

mainb_page_2_CTDXPIVLit.jpg

mainb_page_3_wSMuzISSBM.jpg

mainb_page_4_9WSmjodKBQ.jpg

mainb_page_5_wEgzgrUgCq.jpg

mainb_page_6_HVhqiClIl4.jpg

Code

Receive Sensor Value from Thunderboard

C/C++
boolean emberAfReportAttributesCallback(EmberAfClusterId clusterId, int8u *buffer, int16u bufLen)
{
  EmberNodeId atrSenderId;

  uint8_t i;
  uint8_t sensorIdx = 0;    // index in the sensorNode table
  bool sensorNodeExist = false;
  int8_t allocatedDisIdx = 0xFF;

  int16u temperatureValue = 0;
  emberAfCorePrintln("Received report attributes, clusterID 0x%04x", clusterId);

//  emberAfCorePrintln("index1 %x", sensor_index_t);
  if ((clusterId == 0x0402) && (bufLen == 5)) {
    atrSenderId = emberGetSender();

    temperatureValue = (buffer[4] << 8) | buffer[3];
    emberAfCorePrintln("The temperature is %d.%02d, sent from 0x%02x",
        temperatureValue / 100, temperatureValue % 100, atrSenderId);

    for (i = 0; i < SENSOR_NODE_NUMBER; i++) {
//      emberAfCorePrintln("index %d, senderIdTable[index] = 0x%02x,atrSenderId=%x", sensor_index_t, sensorNode[sensor_index_t],atrSenderId);
//      emberAfCorePrintln("index1.2 %x", sensor_index_t);
      if (sensorNode[i].sensorNodeID == atrSenderId) {
        // Find the node in the sensorNode table, break;
        sensorNodeExist = true;
        sensorIdx = i;
        sensorNode[i].sensorActive = true;  // set the active flag as true after receiving data from the sensor node.
        break;
      }
    }
//    emberAfCorePrintln("index2 %x", sensor_index_t);

    if (sensorNodeExist) {
      emberAfCorePrintln("The node already registered before, sensorIdx %d, displayIdx %d",
                          sensorIdx,
                          sensorNode[sensorIdx].sensorDisIdx);
      // report the temperature value if the sensor exist in the table.
      report_sensor_value(sensorNode[sensorIdx].sensorDisIdx, TEMPERATURE_SENSOR, temperatureValue / 10);
    }
    // Register the sensor node
    else {
      emberAfCorePrintln("A new node, register it to the display module.");
      allocatedDisIdx = register_sensor(0, TEMPERATURE_SENSOR, 1);

      if (allocatedDisIdx != FAIL) {
        emberAfCorePrintln("allocated display index %d", allocatedDisIdx);

        // register sensor node successfully, and the core allocate sensor a store index
        for (i = 0; i < SENSOR_NODE_NUMBER; i++) {
          if (sensorNode[i].sensorNodeID == 0xFFFF) {
            sensorNode[i].sensorNodeID = atrSenderId;
            sensorNode[i].sensorDisIdx = allocatedDisIdx;
            sensorNode[i].sensorActive = true;  // set the active flag as true after receiving data from the sensor node.
            sensorIdx = i;
            sensorNodeExist = true;
            break;
          }
        }

        if (i == SENSOR_NODE_NUMBER) {
          emberAfCorePrintln("Local sensor table is full");
        }
      } else {
        emberAfCorePrintln("Allocate display index failed");
      }

      if (sensorNodeExist) {
        emberAfCorePrintln("Register node to display module successfully, sensorIdx %d, displayIdx %d",
                            sensorIdx,
                            sensorNode[sensorIdx].sensorDisIdx);
        report_sensor_value(sensorNode[sensorIdx].sensorDisIdx, TEMPERATURE_SENSOR, temperatureValue / 10);
      }
    }
  }

  return false;
}

Credits

victor

victor

1 project • 0 followers

Comments