NOT WORKING: DHT and RELAYS on Ethernet GW



  • Hi Folks!

    I've recieved my DHT11/22s and finally resolved an issue I was having with an ethernet shield (replaced the DOA unit with another new one) and I sat down to have a play and try and get one of the DHTs working on my current relay gateway/node and I ran into a loop of "Failed reading temperature from DHT!" but I can't work out what it is I'm doing wrong.

    I have the DHT working on it's own, or I have the relays working on their own, but not both at the same time.

    It doesn't seem to be a pin conflict or anything there, it may be power related though as I was trying to use the 3.3v pint o power the DHT and the 5v pin to power the relays.

    I need to invest (read: pull apart a phone charger) in a better 5v power supply for my gateway.

    If you fine people could cast an eye over my sketch and suggest any changes, maybe where I've gone wrong, or even a more elegant way of doing the same thing, I'd be greatly appreciative.

    note: for some reason i couldn't paste with code tags, so I've dumped it at pastebin:

    https://pastebin.com/HQpPKdeF

    Cheers in advance!



  • Not sure, if this is really the cause of your troubles, bit imo it's not the best way to measure the DHT values every time when loop() is gone through. Doing so, the arduino most of the time is just waiting for the DHT to finish measurement.
    I'd recommend to use a non-blocking-loop() function - you may use the https://www.mysensors.org/build/pulse_water example to build your own code or search the arduino website for non-blocking loop.


  • Mod

    @zachflem I'd put a

    wait(300000)

    at the end of loop so the sensor only sends data every 5 minutes while the rest of the GW functions keep working



  • @gohan The reason behind proposing to use a non-blocking loop() was as follows: The former gw.process()-function has been pushed in the background so it is no longer visible directly in the sketches. But nevertheless I thought, for GW's and repeaters it still is highly recommended to go through the loop() as often as possible to avoid any delays in the processing of ingoing messages.
    The proposal to just use wait() is not really compatible with this understanding of the internal machanics of MySensors. Did I get something wrong?


  • Mod

    "Wait" will keep the rest of the GW functions running, it is not like "delay" that blocks the code execution



  • @gohan would the 5 minute wait() affect the rest of the loop? as in, if I add the wait, will it delay the activation of relays etc


  • Mod

    It does affect the loop of course, but since you are only running the DHT code it shouldn't be an issue. Give it a try, it is not a complicated change 🙂



  • @gohan said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    "Wait" will keep the rest of the GW functions running, it is not like "delay" that blocks the code execution

    Thx for clarification 👍



  • OK folks, so I've got it going to some extent.

    Added the wait(), and that seems to have calmed things down a bit, but I also added an external 5v power supply to the sensor and relay board

    The relays are working, and the temp and humidity are being reported on the serial monitor, but there is no value coming back to MyController from the DHT22.

    Sketch @ https://pastebin.com/mMxh65xp

    As always, your help is appreciated.

    Cheers


  • Mod

    Is the gateway actually sending the temperature? Do you see it in the logs?



  • @gohan nope, just checked, and I can see the presentation, and my manual trigger of the relays, but no data back from the sensor.

    I'm also only getting the humidity presented to MyController


  • Mod

    DHT sensors are quite lazy so they need their time, try adding a wait(1000) before the

    float temperature = dht.getTemperature();



  • @zachflem said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    I'm also only getting the humidity presented to MyController

    This also indicates some trouble in the communication between GW and Controller. For debugging, you may also add some wait()-time in between the presentation of the individual child-ID's.



  • So I've moved inside (it was bloody hot in the shed) and I'm working on my development board (it's a mirror of the setup in the shed, minus the external power supply for the sensors)

    But with the shed sketch loaded into this MEGA, I'm getting the DHT values in the Serial Monitor, I'll hook it up proper to the network and see how we go.


  • Mod

    As a personal suggestion, I'd start looking at better sensors like the I2C ones (SHT31, SHT21, Si7021, BME280, etc)



  • @gohan said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    DHT sensors are quite lazy so they need their time, try adding a wait(1000) before the

    float temperature = dht.getTemperature();

    So far I've done this, and I have a value coming from the GW for humidity, and I'm seeing a presentation for the temp sensor in the logs, but nothing comes up when I discover the GW...


  • Mod

    What kind of gateway are you running?



  • @gohan said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    What kind of gateway are you running?

    An arduino mega clone with a w5100 based ethernet shield.

    I think I might have found the problem, the humidity sensor reports as ID 0, the 2 relays as 1 and 2, and the temp sensor is showing up as 1, but before the relay.

    So I think i need to add something to the sketch so that each type of sensor has a different prefix.

    i.e. relays are 1XX, temp are 2XX etc

    any thoughts?



  • @zachflem said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    any thoughts?

    Not sure about if that's still valid, but there had been the recommendation to use ChildID 1 for the first relay. So you may use 3+4 for temp/hum or start with 10, 20 (or whatever you like) as proposed to have room for further relays or other type of switches.



  • @rejoe2 said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    @zachflem said in NOT WORKING: DHT and RELAYS on Ethernet GW:

    any thoughts?

    Not sure about if that's still valid, but there had been the recommendation to use ChildID 1 for the first relay. So you may use 3+4 for temp/hum or start with 10, 20 (or whatever you like) as proposed to have room for further relays or other type of switches.

    Yeah, just re-read it and found the hard define for the IDs of those, and set them to 100 and 101.

    Now I have the 2 relays defined as 1 & 2 and the Humidity as 100 and Temp as 101.

    Can see all 4 sensors but only getting a value from the temp sensor.


 

327
Online

7.4k
Users

8.3k
Topics

89.6k
Posts