Keep getting error 'child_id 0 already exists in children of node 1, cannot add child'
-
Hi all,
I'm trying to connect my first MySensors node (MQ135 gas sensor) to a serial gateway. This is connected to a raspberry pi 4 running Home Assistant on Hassio. However I keep on getting this error in the home assistant logs: I have already tried clearing the eeprom but the sensor still won't appear in home assistant any ideas on how to solve this?
Any help is greatly appreciatedHere is the log output on my sensor node I'm trying to connect:
17:08:18.717 -> 16 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=8,REL=255,VER=2.3.2 17:08:18.717 -> 28 TSM:INIT 17:08:18.717 -> 28 TSF:WUR:MS=0 17:08:18.717 -> 36 TSM:INIT:TSP OK 17:08:18.717 -> 38 TSF:SID:OK,ID=2 17:08:18.717 -> 40 TSM:FPAR 17:08:18.717 -> 45 ?TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 17:08:20.713 -> 2054 !TSM:FPAR:NO REPLY 17:08:20.748 -> 2056 TSM:FPAR
Here is the sketch on the node:
/* * 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-2019 Sensnology AB * Full contributor list: https://github.com/mysensors/MySensors/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. * ******************************* * * DESCRIPTION * * Connect the MQ2 sensor as follows : * * A H A >>> 5V * B >>> A0 * H >>> GND * B >>> 10K ohm >>> GND * * Contribution: epierre * Based on http://sandboxelectronics.com/?p=165 * License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) * Modified by HEK to work in 1.4 * */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 #include <MySensors.h> #define CHILD_ID_MQ 0 /************************Hardware Related Macros************************************/ #define MQ_SENSOR_ANALOG_PIN (0) //define which analog input channel you are going to use #define RL_VALUE (5) //define the load resistance on the board, in kilo ohms #define RO_CLEAN_AIR_FACTOR (9.83) //RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO, //which is derived from the chart in datasheet /***********************Software Related Macros************************************/ #define CALIBARAION_SAMPLE_TIMES (50) //define how many samples you are going to take in the calibration phase #define CALIBRATION_SAMPLE_INTERVAL (500) //define the time interval(in milliseconds) between each samples in the //calibration phase #define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to take in normal operation #define READ_SAMPLE_TIMES (5) //define the time interval(in milliseconds) between each samples in //normal operation /**********************Application Related Macros**********************************/ #define GAS_LPG (0) #define GAS_CO (1) #define GAS_SMOKE (2) /*****************************Globals***********************************************/ uint32_t SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) //VARIABLES float Ro = 10000.0; // this has to be tuned 10K Ohm int val = 0; // variable to store the value coming from the sensor uint16_t lastMQ = 0; float LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" //to the original curve. //data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -0.59) float COCurve[3] = {2.3,0.72,-0.34}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" //to the original curve. //data format:{ x, y, slope}; point1: (lg200, 0.72), point2: (lg10000, 0.15) float SmokeCurve[3] = {2.3,0.53,-0.44}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" //to the original curve. //data format:{ x, y, slope}; point1: (lg200, 0.53), point2:(lg10000,-0.22) MyMessage msg(CHILD_ID_MQ, V_LEVEL); void setup() { Ro = MQCalibration( MQ_SENSOR_ANALOG_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Air Quality Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_MQ, S_AIR_QUALITY); } void loop() { uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO); Serial.println(val); Serial.print("LPG:"); Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_LPG) ); Serial.print( "ppm" ); Serial.print(" "); Serial.print("CO:"); Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_CO) ); Serial.print( "ppm" ); Serial.print(" "); Serial.print("SMOKE:"); Serial.print(MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN)/Ro,GAS_SMOKE) ); Serial.print( "ppm" ); Serial.print("\n"); if (valMQ != lastMQ) { send(msg.set((int16_t)ceil(valMQ))); lastMQ = ceil(valMQ); } sleep(SLEEP_TIME); //sleep for: sleepTime } /****************** MQResistanceCalculation **************************************** Input: raw_adc - raw value read from adc, which represents the voltage Output: the calculated sensor resistance Remarks: The sensor and the load resistor forms a voltage divider. Given the voltage across the load resistor and its resistance, the resistance of the sensor could be derived. ************************************************************************************/ float MQResistanceCalculation(int raw_adc) { return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc)); } /***************************** MQCalibration **************************************** Input: mq_pin - analog channel Output: Ro of the sensor Remarks: This function assumes that the sensor is in clean air. It use MQResistanceCalculation to calculates the sensor resistance in clean air and then divides it with RO_CLEAN_AIR_FACTOR. RO_CLEAN_AIR_FACTOR is about 10, which differs slightly between different sensors. ************************************************************************************/ float MQCalibration(int mq_pin) { int i; float inVal=0; for (i=0; i<CALIBARAION_SAMPLE_TIMES; i++) { //take multiple samples inVal += MQResistanceCalculation(analogRead(mq_pin)); delay(CALIBRATION_SAMPLE_INTERVAL); } inVal = inVal/CALIBARAION_SAMPLE_TIMES; //calculate the average value inVal = inVal/RO_CLEAN_AIR_FACTOR; //divided by RO_CLEAN_AIR_FACTOR yields the Ro //according to the chart in the datasheet return inVal; } /***************************** MQRead ********************************************* Input: mq_pin - analog channel Output: Rs of the sensor Remarks: This function use MQResistanceCalculation to calculate the sensor resistance (Rs). The Rs changes as the sensor is in the different concentration of the target gas. The sample times and the time interval between samples could be configured by changing the definition of the macros. ************************************************************************************/ float MQRead(int mq_pin) { int i; float rs=0; for (i=0; i<READ_SAMPLE_TIMES; i++) { rs += MQResistanceCalculation(analogRead(mq_pin)); delay(READ_SAMPLE_INTERVAL); } rs = rs/READ_SAMPLE_TIMES; return rs; } /***************************** MQGetGasPercentage ********************************** Input: rs_ro_ratio - Rs divided by Ro gas_id - target gas type Output: ppm of the target gas Remarks: This function passes different curves to the MQGetPercentage function which calculates the ppm (parts per million) of the target gas. ************************************************************************************/ int MQGetGasPercentage(float rs_ro_ratio, int gas_id) { if ( gas_id == GAS_LPG ) { return MQGetPercentage(rs_ro_ratio,LPGCurve); } else if ( gas_id == GAS_CO ) { return MQGetPercentage(rs_ro_ratio,COCurve); } else if ( gas_id == GAS_SMOKE ) { return MQGetPercentage(rs_ro_ratio,SmokeCurve); } return 0; } /***************************** MQGetPercentage ********************************** Input: rs_ro_ratio - Rs divided by Ro pcurve - pointer to the curve of the target gas Output: ppm of the target gas Remarks: By using the slope and a point of the line. The x(logarithmic value of ppm) of the line could be derived if y(rs_ro_ratio) is provided. As it is a logarithmic coordinate, power of 10 is used to convert the result to non-logarithmic value. ************************************************************************************/ int MQGetPercentage(float rs_ro_ratio, float *pcurve) { return (pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0]))); }
Here are the home assistant logs:
2020-03-23 16:47:06 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 1, cannot add child 2020-03-23 16:54:11 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 1, cannot add child 2020-03-23 17:00:06 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 1, cannot add child 2020-03-23 17:04:54 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 1, cannot add child 2020-03-23 17:08:19 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 2, cannot add child
-
(moved to the Home Assistant category, where it hopefully will get attention from people using HA)
-
2020-03-23 17:04:54 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 1, cannot add child
This isn't an error, it's just a warning. Whenever you power up a node and present your sensors, Home Assistant will check if they are already known (and listed in your persistance file). If they are, you get this warning as an information. There's nothing to worry about unless you change an existing sensor's type but keep the same ID. In this case, Home Assistant won't update the sensor to the new type and you would have to remove the conflicting child object manually from your persistance file, reload your configuration and present your sensor again.
17:08:18.717 -> 38 TSF:SID:OK,ID=2
Your sensor node thinks its ID is 2. You wrote that you tried clearing the eeprom and your sketch doesn't assign a static node ID. If you don't assign a static ID, the node will request one from the controller. So where does it come from? Did you confirm it cleared? Did your connection work at some time after clearing the eeprom?
17:08:20.713 -> 2054 !TSM:FPAR:NO REPLY
Your node didn't get a reply from its parent. Are there any related messages in the serial output of the parent node (gateway)? This could very well be a general power / hardware or range issue especially since your Home Assistant log shows that you seem to be able to connect to your network atleast occassionally.
Please take a look at the debug / FAQ and follow the flowchart:
https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help
I guess your sensor readings don't appear in your Home Assistant dashboard during the times the radio connection works? Could you please post the configuration of your MySensors integration in
configuration.yaml
?
-
Thanks for the help. I cleared the eeprom again just to confirm that it isn't causing the problem and the connection still is not working.
Here's the serial output from the gateway:
2020-03-24 15:38:13 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:273906 TSF:MSG:READ,2-2-255,s=255,c=3,t=7,pt=0,l=0,sg=0: 2020-03-24 15:38:13 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:273912 TSF:MSG:BC 2020-03-24 15:38:13 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:273915 TSF:MSG:FPAR REQ,ID=2 2020-03-24 15:38:13 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:273918 TSF:PNG:SEND,TO=0 2020-03-24 15:38:13 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:273923 TSF:CKU:OK 2020-03-24 15:38:13 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:273925 TSF:MSG:GWL OK 2020-03-24 15:38:14 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:274456 TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0 2020-03-24 15:38:15 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275932 TSF:MSG:READ,2-2-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1 2020-03-24 15:38:15 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275938 TSF:MSG:PINGED,ID=2,HP=1 2020-03-24 15:38:15 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275946 TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275961 TSF:MSG:READ,2-2-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275970 TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275978 TSF:MSG:READ,2-2-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.3.2 2020-03-24 15:38:16 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 2 child 255 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:275990 TSF:MSG:READ,2-2-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:276008 TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=6,pt=0,l=1,sg=0,ft=0,st=OK:M 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:276016 TSF:MSG:READ,2-2-0,s=255,c=3,t=11,pt=0,l=18,sg=0:Air Quality Sensor 2020-03-24 15:38:16 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 2 child 255 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:276027 TSF:MSG:READ,2-2-0,s=255,c=3,t=12,pt=0,l=3,sg=0:1.0 2020-03-24 15:38:16 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 2 child 255 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:276037 TSF:MSG:READ,2-2-0,s=0,c=0,t=22,pt=0,l=0,sg=0: 2020-03-24 15:38:16 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 2, cannot add child 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:276047 TSF:MSG:READ,2-2-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2 2020-03-24 15:38:16 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:276056 TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1 2020-03-24 15:38:18 DEBUG (SyncWorker_11) [mysensors.persistence] Saving sensors to persistence file /config/mysensors1.pickle
I've added it all as I'm not sure what is relevant
Here is the mysensor config in the configuration.yaml file:
mysensors: gateways: - device: '/dev/ttyUSB0' baud_rate: 115200 optimistic: false persistence: true retain: true version: '2.3'
-
@henry-north According to the serial output from the gateway you do have communication between the gateway and the node.
I think there is some issue with the Homeassistant persistence file, or perhaps you changed the child type in the node scetch after it was presented first time as pointed out by @BearWithBeard? If so it will no longer match the data in the persistence file and you will get the "cannot add child" warning, and (I think) not se the sensor in HA. Try to delete the persistence file (mysensors.pickle). Then first restart HA, then restart/present gateway and then reset/present the node(s).
You can change the persistance file to a readable format by putting this in your configuration:
persistence_file: '/config/mysensors.json'
Makes it much easier to see what's going on.
-
Thanks for the log. As @olka said, the communication seems to be working. I'm wondering though, if the node is able to present its sensors and both the node and gateway can send / receive ping pong messages - which happens after the node is looking for a parent (FPAR section in the log) - how could the sensor note get stuck at FPAR as you described in your opening post? Those two serial outputs don't match up imho.
Your configuration.yaml looks fine, btw. I second @olka's suggestion to switch to a human readable JSON file though.
-
Thanks again for the advice. I added
persistence_file: '/config/mysensors.json'
to my configuration.yaml file after deleting mysensors.pickle and things seemed to work much better as I didn't get the initial error. However I did get these errors instead:
2020-03-24 19:45:34 INFO (MainThread) [homeassistant.setup] Setting up mysensors 2020-03-24 19:45:34 WARNING (SyncWorker_3) [mysensors.persistence] File does not exist or is not readable: /config/mysensors.json 2020-03-24 19:45:34 WARNING (SyncWorker_3) [mysensors.persistence] Trying backup file: /config/mysensors.json.bak 2020-03-24 19:45:34 WARNING (SyncWorker_3) [mysensors.persistence] File does not exist or is not readable: /config/mysensors.json.bak 2020-03-24 19:45:34 WARNING (SyncWorker_3) [mysensors.persistence] Failed to load sensors from file: /config/mysensors.json 2020-03-24 19:45:34 DEBUG (SyncWorker_10) [mysensors.persistence] Saving sensors to persistence file /config/mysensors.json 2020-03-24 19:45:44 DEBUG (SyncWorker_2) [mysensors.persistence] Saving sensors to persistence file /config/mysensors.json
And also I still can't get past the original point in the communications but perhaps that is now linked to the file permissions above:
2020-03-24 19:45:34 INFO (MainThread) [mysensors] Connected to Serial<id=0xb272eab0, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False) 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors] Receiving 0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=255,VER=2.3.2 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:0 MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=255,VER=2.3.2 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:5 TSM:INIT 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:7 TSF:WUR:MS=0 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:15 TSM:INIT:TSP OK 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:18 TSM:INIT:GW MODE 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:21 TSM:READY:ID=0,PAR=0,DIS=0 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:24 MCO:REG:NOT NEEDED 2020-03-24 19:45:35 INFO (MainThread) [mysensors.handler] n:0 c:255 t:3 s:14 p:Gateway startup complete. 2020-03-24 19:45:35 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 0 child 255 2020-03-24 19:45:35 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 0 child 255 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:28 MCO:BGN:INIT OK,TSP=1 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:36 TSM:READY:NWD REQ 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:41 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK: 2020-03-24 19:45:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:52 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=1,l=1,sg=0,ft=0,st=OK:0