DHT11 and a RELAY combinaison problem



  • Hi,
    I need a good kick , i try to make working a DHT 11 with a Relay.
    I have veraedge with ethernet gateway working for ''simple'' sensor,
    No problem with 1X sensor...
    but when i try to put 2 togethers no succes...
    Could somebody ''educate'' me please!
    this my code:
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySensor.h>
    #include <SPI.h>
    #include <DHT.h>

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1 // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay

    // NRFRF24L01 radio driver (set low transmit power by default)
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    MyHwATMega328 hw;
    // Construct MySensors library
    MySensor gw(radio, hw);

    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

    void setup()
    {
    gw.begin();
    dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo("Humidity", "1.0");

    // 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);
    metric = gw.getConfig().isMetric;

    // Initialize library and add callback for incoming messages
    gw.begin(incomingMessage, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    // gw.sendSketchInfo("Relay", "1.0");

    // Fetch relay status
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay
    digitalWrite(pin,HIGH);
    }
    }

    void loop()
    {
    delay(dht.getMinimumSamplingPeriod());

    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);
    }

    // gw.sleep(SLEEP_TIME); //sleep a bit
    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type==V_LIGHT) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, 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 sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    }

    HERE THE DEBUG CODE:
    send: 13-13-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 13-13-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 13-13-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-13 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    sensor started, id=13, parent=0, distance=1
    send: 13-13-0-0 s=255,c=3,t=11,pt=0,l=8,sg=0,st=ok:Humidity
    send: 13-13-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 13-13-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=ok:
    send: 13-13-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=ok:
    send: 13-13-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 13-13-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 13-13-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    repeater started, id=13, parent=0, distance=1
    send: 13-13-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 13-13-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,st=ok:23.0
    T: 23.00
    send: 13-13-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:35.0
    H: 35.00

    I have tried with: // gw.sendSketchInfo("Relay", "1.0"); (activated and not)
    Like i said everything is ok with one sensor... Thanks Mike



  • Hi, again,
    -Before posting i went threw all the forum and also the debug FAQ
    -Spent many hourssss before asking....
    -Got serialgateway+ethernetgateway+onewire+dht11+relay+motion sensor :Working!
    -i have relay + sensor problem, small lack of knowledge here ...
    -Problem is my Veraedge with 1.5 release dont find the Relay...
    -I have tried to ''restore'' my library, but like i wrote 1X sensor is working but not both...
    -Radio have an electrolytic capacitor and working good.
    -supply for the radio is ok too... not coming from the nano...
    -and sketch upload as unique sensor is working for both relay and dht11 when alone...

    I have a problem in the ''setup'' for sure,
    i need a kick in my...
    Tried a lot of different things with the same issue: Veraedge dont find one part of the sensor : Could be temperature or relay...But always find Humidity...
    Please a clue ...
    Mike





  • Thanks Nuubi ! For pointing this link! πŸ˜ƒ πŸ‘
    '''Cent fois sur le mΓ©tier remettez votre ouvrage!''' πŸ˜“
    Because you pointed it to me, i had to go back in this thread, again...
    Trying to find what was different from the 100 sketchs i tried...

    EUREKA ❗ ''development branch of MySensors Arduino package''
    ''https://github.com/mysensors/Arduino/archive/development.zip''

    I was not using the proper library...
    Now my Veraedge find everything ! ☺
    Thanks again ! And also Thanks to Hek for ''Combining MySensors examples'' πŸ‘
    Mike


Log in to reply
 

Suggested Topics

7
Online

11.4k
Users

11.1k
Topics

112.7k
Posts