Wemos D1 Mini ESP8266 GW Homeassistant connection problem with sensor node



  • Hello,
    I'm trying to setup my first ESP8266 sensor. I have uploaded the ESP8266 Gateway sketch from Mysensors_master library:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex, 
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Ivo Pullens (ESP8266 support)
     * 
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the WiFi link. 
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * VERA CONFIGURATION:
     * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. 
     * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
     *
     * LED purposes:
     * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error  
     * 
     * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
     * nRF24L01+  ESP8266
     * VCC        VCC
     * CE         GPIO4          
     * CSN/CS     GPIO15
     * SCK        GPIO14
     * MISO       GPIO12
     * MOSI       GPIO13
     * GND        GND
     *            
     * Not all ESP8266 modules have all pins available on their external interface.
     * This code has been tested on an ESP-12 module.
     * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
     * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
     * - Connect GPIO15 via 10K pulldown resistor to GND
     * - Connect CH_PD via 10K resistor to VCC
     * - Connect GPIO2 via 10K resistor to VCC
     * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
     * 
      * Inclusion mode button:
     * - Connect GPIO5 via switch to GND ('inclusion switch')
     * 
     * Hardware SHA204 signing is currently not supported!
     *
     * Make sure to fill in your ssid and WiFi password below for ssid & pass.
     */
    
    #include <EEPROM.h>
    #include <SPI.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    
    #define MY_GATEWAY_ESP8266
    
    #define MY_ESP8266_SSID "Mywlan"
    #define MY_ESP8266_PASSWORD "xxxxxx"
    
    // Enable UDP communication
    //#define MY_USE_UDP
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_ESP8266_HOSTNAME "ESP8266-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,0,70
    
    // If using static ip you need to define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,0,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // The port to keep open on node server mode 
    #define MY_PORT 5003      
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    
    // Enable Inclusion mode button on gateway
    // #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
     
    // Flash leds on rx/tx/err
    // #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    // #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Led pins used if blinking feature is enabled above
    #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    
    #if defined(MY_USE_UDP)
      #include <WiFiUDP.h>
    #else
      #include <ESP8266WiFi.h>
    #endif
    
    #include <MySensors.h>
    
    void setup() { 
    }
    
    void presentation() {
      // Present locally attached sensors here    
    }
    
    
    void loop() {
      // Send locally attached sensors data here
    }
    
    
    

    and it seems to start ok:

    ÈHlìÉ`,lEØ4HÈrðú0;255;3;0;9;Starting gateway (RRNGE-, 2.0.0)
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    0;255;3;0;9;TSM:READY
    scandone
    f 0, ....scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 5
    cnt 
    
    connected with Mywlan, channel 9
    dhcp client start...
    ......ip:192.168.0.70,mask:255.255.255.0,gw:192.168.0.1
    .IP: 192.168.0.70
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    pm open,type:2 0
    

    My sensor sketch looks like this:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0: Henrik EKblad
     * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
     * 
     * DESCRIPTION
     * This sketch provides an example of how to implement a humidity/temperature
     * sensor using a DHT11/DHT-22.
     *  
     * For more information, please visit:
     * http://www.mysensors.org/build/humidity
     * 
     */
    
    // Enable debug prints
    #define MY_DEBUG
    #define MY_NODE_ID 1
    
    // Enable and select radio type attached 
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    //#define MY_RS485
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHTPIN 4
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures
    #define SENSOR_TEMP_OFFSET 0
    
    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 10000;
    
    // Force sending an update of the temperature after n sensor reads, so a controller showing the
    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
    // the value didn't change since;
    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    DHT dht(DHTPIN, DHTTYPE);
    
    void presentation()  
    { 
      // Send the sketch version information to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.1");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
    }
    
    
    void setup()
    {
      // Wait for the time of the minimum sampling period to give the sensor time to power up
      // (otherwise, timeout errors might occure for the first reading)
      wait(2000);
    }
    
    
    void loop()      
    {  
      // Get temperature from DHT library
      float temperature = dht.readTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
    
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        temperature += SENSOR_TEMP_OFFSET;
        send(msgTemp.set(temperature, 1));
    
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      } else {
        // Increase no update counter if the temperature stayed the same
        nNoUpdatesTemp++;
      }
    
      // Get humidity from DHT library
      float humidity = dht.readHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        // Reset no updates counter
        nNoUpdatesHum = 0;
        send(msgHum.set(humidity, 1));
    
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
      } else {
        // Increase no update counter if the humidity stayed the same
        nNoUpdatesHum++;
      }
    
      // Sleep for a while to save energy
      wait(UPDATE_INTERVAL); 
    }
    
    

    It seems to somehow sniff the wlan information from gateway as it registers itself to the wlan network:

    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=1)
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 6
    cnt 
    
    connected with Mywlan, channel 9
    dhcp client start...
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    ip:192.168.0.59,mask:255.255.255.0,gw:192.168.0.1
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=1)
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    

    I can see them in my router's DHCP table:

    ESP8266-sensor-gateway	Wireless 192.168.0.70	 	5C:CF:7F:2B:D5:22	 
    ESP_DE24D3	Wireless 192.168.0.59 	18:FE:34:DE:24:D3	 
    

    Gateway continues writing:

    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:SANCHK:OK
    
    

    and client:

    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    

    It seems that whatever serial.print-lines I write on the sensor sketch (in presentation, setup, loop) they never end up to the actual serial log. Don't know why. 😞

    Finally to the Homeassistant. I have defined in configuration.yaml:

    mysensors:
      gateways:
        - device: '192.168.0.70'
          persistence_file: '/home/homeassistant/.homeassistant/mysensors3.json'
          tcp_port: 5003
      debug: true
      optimistic: false
      persistence: true
      retain: true
      version: 2.0
    

    And when starting Homeassistant it says:

    16-11-17 11:48:58 INFO (MainThread) [homeassistant.core] Timer:starting
    16-11-17 11:48:58 INFO (Thread-5) [mysensors.mysensors] Trying to connect to ('192.168.0.70', 5003)
    16-11-17 11:48:58 INFO (Thread-5) [mysensors.mysensors] Connected to ('192.168.0.70', 5003)
    

    But tells nothing more nor comes any updates of my DHT22 sensor in the log.
    This is currently the whole environment. Homeautomation is running correctly on my Raspberry Pi3 and I can access the web interface with no problem. Then there are these two Wemos D1 mini ESP8266 boards currently connected via USB to my laptop. One has nothing but USB cable feeding power (=gateway), other has USB cable + DHT22 sensor connected. DHT22 sensor works as I have tested it alone without Mysensors libraries having a web server running on that Wemos showing the temperature/humidity information on a web page. Running out of ideas, hopefully someone can help. :s


  • Admin

    Hmm. does your DHT node also run on a Wemos D1?



  • Yes, they both run on similar Wemos D1 Mini board.


  • Admin

    Hmm.. we don't support that kind of setup.

    Why not just connect the DHT sensor directly to your controller over WiFi? That is, reconfigure it as a gateway. There is no need for RFM radio on ESP nodes/gateways.



  • Ok, thanks! 🙂 I thought that a gateway is also needed when using ESP8266. Is there then any idea to use Mysensors with ESP8266 and Homeassistant? Wouldn't it just be better to setup a MQTT server on Homeassistant server and connect sensors directly as MQTT clients to it? I have also some nrf24l01 boards waiting to be implemented. Those would then connect through Mysensors gateway (serial/ethernet).


  • Admin

    You can setup your ESP as a mysensors MQTT client or use the "normal" mysensors protocol over a socket. It all depend on what variants Home Assistant supports.

    The good thing with sticking with MySensors is that you can reuse mysensors example sketches and (hopefully) have a protocol Home Assistant understands (which create the desired devices).

    But you can of course roll your own thing over MQTT and create your own extensions/plugin to Home Assistant if you prefer.



  • @hek Thanks again and a very good point there. Mysensors sketch examples have been very useful so far so maybe better to stick with them. One question about the ESP8266 gateways: If I change my sensor node sketch to gateway sketch will the node still act like some kind of a hub? I mean when I'm going to build tens of sensors around the house, I don't want to have too many repeater nodes slowing down the Wifi network.


  • Admin

    @Sushukka said:

    If I change my sensor node sketch to gateway sketch will the node still act like some kind of a hub?

    No, it will act standalone, unless you enable the radio sub network.



  • Ok, I managed to add DHT part to the ESP8266GW sketch, but still have the problem with reading the DHT22 data.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex, 
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Ivo Pullens (ESP8266 support)
     * 
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the WiFi link. 
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * VERA CONFIGURATION:
     * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. 
     * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
     *
     * LED purposes:
     * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error  
     * 
     * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
     * nRF24L01+  ESP8266
     * VCC        VCC
     * CE         GPIO4          
     * CSN/CS     GPIO15
     * SCK        GPIO14
     * MISO       GPIO12
     * MOSI       GPIO13
     * GND        GND
     *            
     * Not all ESP8266 modules have all pins available on their external interface.
     * This code has been tested on an ESP-12 module.
     * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
     * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
     * - Connect GPIO15 via 10K pulldown resistor to GND
     * - Connect CH_PD via 10K resistor to VCC
     * - Connect GPIO2 via 10K resistor to VCC
     * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
     * 
      * Inclusion mode button:
     * - Connect GPIO5 via switch to GND ('inclusion switch')
     * 
     * Hardware SHA204 signing is currently not supported!
     *
     * Make sure to fill in your ssid and WiFi password below for ssid & pass.
     */
    
    #include <EEPROM.h>
    #include <SPI.h>
    #include <DHT.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    
    #define MY_GATEWAY_ESP8266
    
    #define MY_ESP8266_SSID "Mywlan"
    #define MY_ESP8266_PASSWORD "xxxxxxx"
    
    // Enable UDP communication
    //#define MY_USE_UDP
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_ESP8266_HOSTNAME "ESP8266-sensorNode1"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,0,80
    
    // If using static ip you need to define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,0,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // The port to keep open on node server mode 
    #define MY_PORT 5003      
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    
    // Enable Inclusion mode button on gateway
    // #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
     
    // Flash leds on rx/tx/err
    // #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    // #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Led pins used if blinking feature is enabled above
    #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    
    #if defined(MY_USE_UDP)
      #include <WiFiUDP.h>
    #else
      #include <ESP8266WiFi.h>
    #endif
    
    #include <MySensors.h>
    
    //-------- DHT22 related definitions ----->>>
    // Set this to the pin you connected the DHT's data pin to
    #define DHTPIN 4
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    // Set this offset if the sensor has a permanent small offset to the real temperatures
    #define SENSOR_TEMP_OFFSET 0
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    
    float lastTemp;
    float lastHum;
    bool metric = true;
    float temperature;
    
    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 10000;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    DHT dht(DHTPIN, DHTTYPE);
    //<<<----- DHT22 related definitions --------
    
    void setup() { 
       dht.begin();
    }
    
    void presentation() {
        // Send the sketch version information to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.1");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP); 
    }
    
    void loop() {
      // Get temperature from DHT library
      temperature = dht.readTemperature();
      wait(2000);
      Serial.print("Temperature:");
      Serial.println(temperature);
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
    
        // Reset no updates counter
        temperature += SENSOR_TEMP_OFFSET;
        send(msgTemp.set(temperature, 1));
      } 
      // Get humidity from DHT library
      float humidity = dht.readHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        send(msgHum.set(humidity, 1));
    
      }
      wait(UPDATE_INTERVAL); 
    }
    
    

    Serial log shows:

    ȤlÍkh$M´H>hä?ü0;255;3;0;9;Starting gateway (RRNGE-, 2.0.0)
    0;255;3;0;9;TSM:INIT
    scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 10
    cnt 
    
    connected with Mywlan, channel 9
    dhcp client start...
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    0;255;3;0;9;TSM:READY
    f r0, scandone
    .....ip:192.168.0.59,mask:255.255.255.0,gw:192.168.0.1
    .IP: 192.168.0.59
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    Temperature:nan
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    pm open,type:2 0
    Temperature:nan
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    Temperature:nan
    

    It seems that MySensors somehow screws the ESP8266 pinout layout or the normal Adafruit Arduino DHT library won't work correctly with it. If I dump the Mysensor stuff and just use the same Wemos D1 mini board with the same DHT22 sensor and DHT library it shows the temperature/humidity values no problem.


  • Admin


Log in to reply
 

Suggested Topics

  • 3
  • 24
  • 4
  • 2
  • 2
  • 2

20
Online

11.2k
Users

11.1k
Topics

112.5k
Posts