Cannot add node to HA



  • Hi,
    i am trying to get my first sensor node running. The GW is a 5100 based ethernet GW and works fine.
    The node is a DHT22-Sensor. This is my current sketch:

    // Enable and select radio type attached 
    #define MY_RADIO_NRF24
    
    // Enable debugging
    #define MY_DEBUG
    
    //#define MY_NODE_ID 1
    
    #include <DHT.h>
    #include <DHT_U.h>
    #include <MySensors.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 3
    
    // We're using a DHT22
    #define DHTTYPE DHT22
    
    // Set a child sensor id
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    
    
    
    DHT_Unified dht(DHT_DATA_PIN, DHTTYPE);
    
    uint32_t delayMS;
    float humidity;
    float temperature;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    bool initialValueSent = false;
    
    
    void setup()
    {
      dht.begin();
      sensor_t sensor;
      // Set delay between sensor readings based on sensor details.
      delayMS = sensor.min_delay / 1000;
    }
    
    void presentation()
    {
      sendSketchInfo("DHT22 Sensor", "0.1");
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
    }
    
    
    void loop()      
    {  
      if(!initialValueSent) {
        send(msgTemp.set(0));
        send(msgTemp.set(0));
        request(CHILD_ID_HUM, V_HUM);
        wait(1000);
      }
      // Read stuff from the DHT sensor
      sensors_event_t event;
      dht.temperature().getEvent(&event);
        if (isnan(event.temperature)) {
          Serial.println("Error reading temperature.");
          temperature = 0;
      }
      else {
        temperature = event.temperature;
    
      }
      // Get humidity event and print its value.
      dht.humidity().getEvent(&event);
      if (isnan(event.relative_humidity)) {
        Serial.println("Error reading humidity!");
        humidity = 0;
      }
      else {
        humidity = event.relative_humidity;
      }
      send(msgHum.set(temperature, 1));
      #ifdef My_DEBUG
      Serial.print("T: ")
      Serial.println(temperature);
      #endif
      send(msgTemp.set(humidity, 1));
      #ifdef My_DEBUG
      Serial.print("H: ")
      Serial.println(humidity);
      #endif
      
      // Delay between measurements.
      delay(delayMS);
    }
    
    void receive(const MyMessage &message)
    {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
      if (message.type == V_HUM) {
        if (!initialValueSent) {
          Serial.println("Receiving initial value from controller");
          initialValueSent = true;
        }
      }
    }
    

    Please note the commented MY_NODE_ID at the top of the sketch. When i uncomment it, i get lots of errors from HA that the node isn't known (yet). So, physically the communication between node, gateway and controller is working.
    However, if i run the sketch with the NODE_ID commented out, i get no feedback from HA, and this output in the serial console of the node: http://pastebin.com/2KqWDZN0

    I see at the bottom of the file that there is some kind of perhaps successful connection to HA, however, i don't see anything in the log of HA, nor a new device on the dev-state section of HA. Can anyone see where's the error?
    What unclear for me as well is the fact that there are lots of messages like

    166507 TSM:FPAR
    166544 TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    168551 !TSM:FPAR:NO REPLY
    

    This is the serial output of the gateway: http://pastebin.com/C7CyLW6K It looks like the gateway is indeed receiving the messages from the node, but HA isn't reacting.
    This is my HA config:

    gateways:
      - device: '192.168.1.233'
        persistence_file: 'mysensors.json'
    debug: true
    version: 2.0
    

    And this is the content of mysensors.json

    {"0": {"sketch_name": null, "type": 18, "battery_level": 0, "sketch_version": null, "sensor_id": 0, "children": {}, "protocol_version": "2.1.1"}, "1": {"sketch_name": null, "type": 17, "battery_level": 0, "sketch_version": "0.1", "sensor_id": 1, "children": {"0": {"description": "", "values": {"1": "23.0"}, "type": 7, "id": 0}, "1": {"description": "", "values": {"0": "30.7"}, "type": 6, "id": 1}}, "protocol_version": "2.1.1"}}
    
    

    Please note that the json has 2 sensors added. I cannot explain to myself why. Also: sensor 1 has the proper sketch_version, but no sketch_name, although defined in the sketch.

    So, has anyone an idea what's wrong here?

    And, on a unrelated side note: I see every sketch in this section around here having this initialValueSent Stuff from the HA component description. I understand that the switch(?) in the component description should have an initial value to it from HA, but just simple sensor nodes like temperature or light don't. So, could it be possible to ease the process up and just start the loop after presenting the sensor type to HA? After starting the loop, the sensor should start begin sending out values, and the first value is taken as the initialValue then. Could this be possible?


  • Mod

    Node ID should be set or the controller should be able to send one when asked, but if I where you I'd run the clear eeprom sketch and reload yours with node ID specified ; then you could use the myscontroller and connect to gateway in order to check if everything is fine. In addition if you are going to post your logs, please add more lines so we can have a better picture and don't forget to use the log parser that's on the mysensors site


  • Plugin Developer

    @simonszu

    Hi!

    You have communication (radio) problems between node and gateway. These are usually power and/or distance related. Follow the troubleshooting schema in the sticky thread top post in the troubleshooting category in the forum.

    Home assistant requires presented node, sketch name, presented sensor and initial value from the sensor, before adding the sensor to home assistant as an entity. In your case many messages were not received by the gateway, so the requirements were not fulfilled.

    Usually sensors will send initial values quite soon, so the check for initial values and request from node to controller is mostly important for devices that don't send messages without manual interaction, ie actuators like switches or lights.



  • @martinhjelmare Thanks for helping. Unfortunately, i already have added a capacitor between the VCC and GND pin of the arduinos on the gateway and the sensor node. They are ceramic capacitors with 4.7 uF which should be enough in my experience. I also don't think it is a range problem, both devices are lying on my table, they have around 110cm distance between them.
    Since @gohan said that i should post more lines of my logs - yeah, sorry, my fault. This is the serial output of the gateway at the same time the node outputs the log i have pasted above: http://pastebin.com/y916idtc

    You see: After some time, the communication between the node and the gateway succeeds, however, Home Assistant shows nothing. With full respect, but i doubt i have physical issues. The presence of the capacitor and the small range should not be the reason for any errors - and the successful message exchange at the bottom of both log files (for which i didn't change anything from the situation at the top of the file) somehow make me suspicious about any physical issues. Or maybe somehow the laws of physics change magically at my desk, who knows 😉

    Of course i have checked all the wirings and solder points on both devices with my multimeter, they are correct.

    Also, let me say that if i hardcode the node ID into the node, there is a reaction from Home Assistant after 2-3 seconds after i start the sensor node that the node ID is unknown. So the physical radio connection between both devices is capable in working from startup of the sensor node - but somehow the communication between the gateway and home assistant fails?

    So, i ask explicitly: Is the sensor node sketch basically correct, regarding the initial value transmitting and stuff? Is the home assistant component definiton correct? I was unsure regarding the initial value transfer...


  • Mod

    I'd say pls post startup logs of both gateway and node so we can see if they are talking correctly from each other: we need to start excluding possible causes of problems until we find the issue.



  • I did 😉
    The complete log from startup to switch to switching off the sensor node after an unsuccessful test is posted as a pastebin link in the initial post from Thursday, and the log from the gateway captured at the same time is added as a pastebin link in my post from a few minutes ago. 🙂


  • Plugin Developer

    @simonszu

    The majority of messages in your logs are find parent requests and responses. If you have more than a pair of those you have communication problems, it's as simple as that.

    You need to get reliable communication going to avoid losing messages and be able to present your node and sensors properly to the controller.



  • Okay, this sounds reasonable.
    But... How? The troubleshooting says, reduce range and add a capacitor. I added a capacitor (or should I add one to the vcc and gnd pin of the radio module as well?). I don't want to reduce range, since around 1 meter is quite close, and I don't want to cover my flat with repeater nodes - if I had to, MySensors would be no great use for me.


  • Plugin Developer

    The capacitor should be added as close as possible to the vcc and gnd pins of the radio. Where did you put the capacitor? Also, with mysensors 2.x, many are reporting requiring a higher value capacitor. Try with 47 uF.

    You can also try increasing the distance between node and gateway. Sometimes too short distance can generate trouble.



  • I'm sorry, it was late last night. I did post wrong facts. I did not solder the capacitor parallel to the VCC and GND pins of the arduino, but parallel to the VCC and GND pins of the radio.
    Here's a photo of the capacitor on the sensor node: https://goo.gl/photos/REYnXMsLvLeKNKpf6
    And here's a photo of the capacitor on the gateway: https://goo.gl/photos/TNVNkJN7ZawcF5qg7

    I am not really sure about the capacity. On the capacitor, there is a 47 printed on it, with a line underneath it. I remember reading an article, explaining this kind of notation, and saying that this means 4.7 uF, but i don't find it any more and am unsure about the line underneath it. Maybe this means 47uF?

    If you say i should clearly try another capacity, i'll try.


  • Mod

    That looks too little for a ceramic of that capacity. Don't you have some electrolicts to try?



  • I'm afraid, i don't. But i won't hesitate ordering some from ebay. Any recommendation which capacity i should choose? Is 47 uF okay?


  • Mod

    Don't you have a multimeter to check capacity of that ceramic cap you have?
    As for the others, usually 4.7uF is enough, but 10 or 47 could also help in some situations; if you find a bag of assorted caps I'd go for that one so you can have some spares around when you need them.



  • I checked with a multimeter. Turns out, the ceramic capacitors had 47pF 😄
    I ordered a set of assorted electrolytic capacitors. Should take some time, they're dispatched directly from China.
    However, i am unsure about the polarity of the capacitors. Should Cap+ go to VCC or GND of the radio?


  • Mod

    Usually electrolitic caps have a "-" sign on the negative and goes to gnd. If you reverse polarity they explode 😁😅



  • I knew that they are marked. But I didn't know the polarity. It could have been possible that Cap- goes to VCC on the radio, since in a full capacitor, there is a lack of electrons on Cap+, and very much electrons on Cap-, and also a lack of electrons on VCC, and very much electrons on GND, and the many electrons on the negative side should match the lack of electrons on the matching side of the other device - you see my point? So I was unsure.
    But Cap- to GND is clear and explicit, yeah.


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 2
  • 5
  • 8
  • 3

62
Online

11.4k
Users

11.1k
Topics

112.7k
Posts