user45247: I made a simple temperature controller on DHT11.
I want it to work with DHT22 as well having the same code.
However, I can’t find a way how to get known what type of sensor is installed.
Is there a way?

user31105: I don't think that is possible.
What you should do is pass the type (DHT11 or DHT12) to the code, store it and change calculations (or functions) accordingly.
If you use a class, you can pass it as argument of the constructor, so the user of the library only need to set it up once (in the constructor where it belongs). Make it an enumeration, copy it into a class variable and all methods inside your class can use the type.
Something like (not checked):
MyDht.hpp:
class MyDht
{
public:
    enum EType { DHT11, DHT12 };

    public MyDht(EType type);

private:
    EType _type;
}

Dht.cpp:
MyDht::MyDht(EType type)
{
    _type = type;
}

And you create the class by:
MyDht sensor1(MyDht::DHT11);
MyDht sensor2(Mydht::DHT12);


user63409: You can use another library for DHT: https://github.com/markruys/arduino-DHT
Although, the library is quite old, it works fine and has auto-detection feature.

45247: <p>I made a simple temperature controller on DHT11.
I want it to work with DHT22 as well having the same code.</p>

<p>However, I can’t find a way how to get known what type of sensor is installed.
Is there a way?</p>
 31105: <p>I don't think that is possible.</p>

<p>What you should do is pass the type (DHT11 or DHT12) to the code, store it and change calculations (or functions) accordingly.</p>

<p>If you use a class, you can pass it as argument of the constructor, so the user of the library only need to set it up once (in the constructor where it belongs). Make it an enumeration, copy it into a class variable and all methods inside your class can use the type.</p>

<p>Something like (not checked):</p>

<p>MyDht.hpp:</p>

<pre><code>class MyDht
{
public:
    enum EType { DHT11, DHT12 };

    public MyDht(EType type);

private:
    EType _type;
}
</code></pre>

<p>Dht.cpp:</p>

<pre><code>MyDht::MyDht(EType type)
{
    _type = type;
}
</code></pre>

<p>And you create the class by:</p>

<pre><code>MyDht sensor1(MyDht::DHT11);
MyDht sensor2(Mydht::DHT12);
</code></pre>
 63409: <p>You can use another library for DHT: <a href="https://github.com/markruys/arduino-DHT" rel="nofollow noreferrer">https://github.com/markruys/arduino-DHT</a>
Although, the library is quite old, it works fine and has <em>auto-detection</em> feature.</p>
