Not seeing child id 0 Humidity from DHT



  • Hello all,

    i made myself a sketch and uploaded it to a arduino nano.
    I'm using pimatic and can find the temperature and the relay but i don't see the humidity.

    This is the sketch.

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>

    #define NODE_ID 5 // ID of node

    //child ids
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_VLIGHT0 2

    //pin definitions
    #define RELAY_PIN0 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3

    //relay state
    #define RELAY_ON 0
    #define RELAY_OFF 1
    #define NUMBER_OF_RELAYS 1

    //sleep timer settings
    unsigned long SLEEP_TIME = 1000; // Sleep time var, first read is 0
    unsigned long SLEEP_TIME_POST = 60000; // Sleep time var changes to this value after
    unsigned long LAST_SLEEP_TIME = millis(); // Sleep time between reads (in milliseconds)

    bool state;

    //mysensors setup
    MySensor gw;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLSW0(CHILD_ID_VLIGHT0, V_LIGHT);

    //dht setup
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;

    void setup()
    {
    // Make sure relays are off when starting up
    digitalWrite(RELAY_PIN0, RELAY_OFF);
    // Then set relay pins in output mode
    pinMode(RELAY_PIN0, OUTPUT);
    dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

    // mysensor startup and Send the Sketch Version Information to the Gateway
    gw.begin(incomingMessage, NODE_ID, true);
    gw.sendSketchInfo("DHT&relay&button", "1.1");
    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID_HUM, S_HUM);
    gw.present(CHILD_ID_TEMP, S_TEMP);
    gw.present(CHILD_ID_VLIGHT0, S_LIGHT);
    delay(1000);
    metric = gw.getConfig().isMetric;
    // Set relay to last known state (using eeprom storage)
    state = gw.loadState(CHILD_ID_VLIGHT0);
    digitalWrite(RELAY_PIN0, state?RELAY_ON:RELAY_OFF);
    }

    void loop()
    {

     if (millis() - LAST_SLEEP_TIME > SLEEP_TIME) {   
    

    dhtupdate();
    LAST_SLEEP_TIME=millis();
    if (SLEEP_TIME < SLEEP_TIME_POST) {
    SLEEP_TIME=SLEEP_TIME_POST;
    }

    }

    gw.process();

    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.isAck()) {
    Serial.println("This is an ack from gateway");
    }

    if (message.type == V_LIGHT) {
    if (message.sensor == CHILD_ID_VLIGHT0){
    // Change relay state
    digitalWrite(RELAY_PIN0, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for relay1 sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    }
    }

    void dhtupdate() {
    float temperature = dht.getTemperature();
    if (isnan(temperature)) {
    Serial.println("Failed reading temperature from DHT");
    } else if (temperature != lastTemp) {
    lastTemp = temperature;
    if (!metric) {
    temperature = dht.toFahrenheit(temperature);
    }
    gw.send(msgTemp.set(temperature, 1));
    Serial.print("T: ");
    Serial.println(temperature);
    }

    float humidity = dht.getHumidity();
    if (isnan(humidity)) {
    Serial.println("Failed reading humidity from DHT");
    } else if (humidity != lastHum) {
    lastHum = humidity;
    gw.send(msgHum.set(humidity, 1));
    Serial.print("H: ");
    Serial.println(humidity);
    }

    }



  • Fixed it! i manually added the sensor in pimatic and now it works


  • Mod

    @derksuh great work. Thanks for reporting back.


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts