Jak podłączyć DHT22 do ESP32C6 Zigbee_Temp_Hum_Sensor_Sleepy.ino

Witam
Mam ESP32C6 N4 wgrałem Zigbee_Temp_Hum_Sensor_Sleepy.ino

/**
 * Ten przykład demonstruje działanie czujnika temperatury i wilgotności Zigbee w urządzeniu Sleepy.
 *
 * Przykład pokazuje, jak wykorzystać bibliotekę Zigbee do utworzenia czujnika temperatury i wilgotności w urządzeniu końcowym.
 * Czujnik jest urządzeniem końcowym Zigbee, które przesyła dane do sieci Zigbee.
 *
 * Prawidłowy tryb Zigbee musi zostać wybrany w Narzędzia->Tryb Zigbee
 * i należy wybrać właściwy schemat partycjonowania w Narzędzia->Schemat partycjonowania.
 *
 * Please check the README.md for instructions and more detailed description.
 * * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
 */

#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"

/* Zigbee temperature + humidity sensor configuration */
#define TEMP_SENSOR_ENDPOINT_NUMBER 10

#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  4         /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */
#define RGB_BRIGHTNESS 1 // Change white brightness (max 255)

uint8_t button = BOOT_PIN;

ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);

/************************ Temp sensor *****************************/
void meausureAndSleep() {
  // Measure temperature sensor value
  float temperature = temperatureRead();

  // Use temperature value as humidity value to demonstrate both temperature and humidity
  float humidity = temperature;

  // Update temperature and humidity values in Temperature sensor EP
  zbTempSensor.setTemperature(temperature);
  zbTempSensor.setHumidity(humidity);

  // Report temperature and humidity values
  zbTempSensor.report();
  Serial.printf("Reported temperature: %.2f°C, Humidity: %.2f%%\r\n", temperature, humidity);

  // Add small delay to allow the data to be sent before going to sleep
  delay(100);

  // Put device to deep sleep
  Serial.println("Going to sleep now");
  esp_deep_sleep_start();
}

/********************* Arduino functions **************************/
void setup() {
  Serial.begin(115200);
rgbLedWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0);  // Green

  // Init button switch
  pinMode(button, INPUT_PULLUP);

  // Configure the wake up source and set to wake up every 5 seconds
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

  // Optional: set Zigbee device name and model
 // zbTempSensor.setManufacturerAndModel("Espressif", "SleepyZigbeeTempSensorTest");
 zbTempSensor.setManufacturerAndModel("Adafruit_Sensor", "SleepyZigbeeTempSensorTest");

  // Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
  zbTempSensor.setMinMaxValue(10, 50);

  // Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
  zbTempSensor.setTolerance(1);

  // Set power source to battery and set battery percentage to measured value (now 100% for demonstration)
  // The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) anytime
  zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100);

  // Add humidity cluster to the temperature sensor device with min, max and tolerance values
  zbTempSensor.addHumiditySensor(0, 100, 1);

  // Add endpoint to Zigbee Core
  Zigbee.addEndpoint(&zbTempSensor);

  // Create a custom Zigbee configuration for End Device with keep alive 10s to avoid interference with reporting data
  esp_zb_cfg_t zigbeeConfig = ZIGBEE_DEFAULT_ED_CONFIG();
  zigbeeConfig.nwk_cfg.zed_cfg.keep_alive = 10000;

  // When all EPs are registered, start Zigbee in End Device mode
  if (!Zigbee.begin(&zigbeeConfig, false)) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }
  Serial.println("Connecting to network");
    rgbLedWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0);  // Red
  
  while (!Zigbee.connected()) {
    Serial.println(".");
    delay(100);
  }
  Serial.println();
  Serial.println("Successfully connected to Zigbee network");

  // Delay approx 1s (may be adjusted) to allow establishing proper connection with coordinator, needed for sleepy devices
  delay(1000);
  rgbLedWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0);  // Green
}

void loop() {
  // Checking button for factory reset
  if (digitalRead(button) == LOW) {  // Push button pressed
    // Key debounce handling
    delay(100);
    int startTime = millis();
    while (digitalRead(button) == LOW) {
      delay(50);
      if ((millis() - startTime) > 5000) {
        // If key pressed for more than 3secs, factory reset Zigbee and reboot
        Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
        delay(1000);
        Zigbee.factoryReset();
      }
    }
  }

  // Call the function to measure temperature and put the device to sleep
  meausureAndSleep();
}

Nie wiem jak wstawić do kodu obsługę DHT22 wysyła ciągle
Successfully connected to Zigbee network
Reported temperature: 28.00°C, Humidity: 28.00%
Going to sleep now
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022

Na ogólnych forach używamy angielskiego. Istnieją specjalne kategorie dla niektórych języków, ale niestety nie dla polskiego.

We use English on general forums. There are specific categories for some languages, but unfortunately not for Polish.


To make it simple for everyone, you said

➜ just add the DHT22 code in the setup to prepare it and then read the sensor inside the function meausureAndSleep() and print it as well.

you can be clearer?

Take a DHT22 example and understand how it’s being used

Take the code of the example and merge it in your code but instead of using the loop() function to access to the sensor’s data, put that code into the meausureAndSleep function

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.