Cannot assign NODE ID
-
Have been running successfully mysensors for quite some time. Now building another sensor and have a nightmare. The manually set NODE_ID gets completly ignored and i don not why just gets itself from out of nowhere. My gateway is a version 2.0 ESP to MQTT
Code
#define SN "Vent Klapans" #define SV "2.1" //System settings #define MY_RADIO_NRF24 #define MY_DEBUG #include <Bounce2.h> #include <DHT.h> #include <math.h> #include <MySensors.h> #include <SPI.h> #include <Wire.h> #define MY_NODE_ID 56 //SETUP PINS #define BUT1_PIN 7 #define BUT2_PIN 8 #define DHT_PIN 3 #define RELAY_1 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 2 // Total number of attached relays //Define connections #define CHILD_ID_HUM 3 #define CHILD_ID_TEMP 4 #define CHILD_BUT1_ID 7 #define CHILD_BUT2_ID 8 #define RELAY_ON 0 // GPIO value to write to turn on attached relay #define RELAY_OFF 1 // GPIO value to write to turn off attached relay DHT dht; //MQ+DHT long DHT_Millis = 0; long DHT_interval = 60000; //Buttons Bounce debouncer1 = Bounce(); Bounce debouncer2 = Bounce(); int oldValue1=-1; int oldValue2=-1; MyMessage msgHumi(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgBut1(CHILD_BUT1_ID,V_STATUS); MyMessage msgBut2(CHILD_BUT2_ID,V_STATUS); void before() { Serial.println( myNodeId ); dht.setup(DHT_PIN); pinMode(BUT1_PIN,INPUT_PULLUP); pinMode(BUT2_PIN,INPUT_PULLUP); debouncer1.attach(BUT1_PIN); debouncer1.interval(5); debouncer2.attach(BUT2_PIN); debouncer2.interval(5); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) // Fetch relay status { pinMode(pin, OUTPUT); // Then set relay pins in output mode digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); // Set relay to last known state (using eeprom storage) } } void setup() { Serial.begin(115200); } void presentation() { sendSketchInfo(SN, SV); present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); present(CHILD_BUT1_ID, S_LIGHT); present(CHILD_BUT2_ID, S_LIGHT); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) // Fetch relay status { present(sensor, S_LIGHT); // Register all sensors to gw (they will be created as child devices) } } void loop() { unsigned long DHT_Current_Millis = millis(); if(DHT_Current_Millis - DHT_Millis > DHT_interval) { DHT_Millis = DHT_Current_Millis; delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); float humidity = dht.getHumidity(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else { send(msgTemp.set(temperature, 1)); send(msgHumi.set(humidity, 1)); Serial.print("T: "); Serial.println(temperature); Serial.print("H: "); Serial.println(humidity); } } debouncer1.update(); int value = debouncer1.read(); if (value != oldValue1) { // Send in the new value send(msgBut1.set(value==HIGH ? 1 : 0)); oldValue1 = value; } debouncer2.update(); int value2 = debouncer2.read(); if (value2 != oldValue2) { // Send in the new value send(msgBut2.set(value==HIGH ? 1 : 0)); oldValue2 = value2; } } void receive(const MyMessage &message) { if (message.type==V_STATUS) // We only expect one type of message from controller. But we better check anyway. { digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Change relay state saveState(message.sensor, message.getBool()); // Store state in eeprom Serial.print("Incoming change for sensor:"); // Write some debug info Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
Debug - Serial Print
15 TSF:SID:OK,ID=75 17 TSM:FPAR 53 TSF:MSG:SEND,75-75-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 1238 TSF:MSG:READ,0-0-75,s=255,c=3,t=8,pt=1,l=1,sg=0:0 1243 TSF:MSG:FPAR OK,ID=0,D=1 2060 TSM:FPAR:OK 2061 TSM:ID 2062 TSM:ID:OK 2064 TSM:UPL 2067 TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2179 TSF:MSG:READ,0-0-75,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2184 TSF:MSG:PONG RECV,HP=1 2186 TSM:UPL:OK 2188 TSM:READY:ID=75,PAR=0,DIS=1 2192 TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2329 TSF:MSG:READ,0-0-75,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2336 TSF:MSG:SEND,75-75-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 2345 TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 4354 TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=11,pt=0,l=12,sg=0,ft=0,st=OK:Vent Klapans 4363 TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.1 4371 TSF:MSG:SEND,75-75-0-0,s=3,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 4378 TSF:MSG:SEND,75-75-0-0,s=4,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK: 4420 !TSF:MSG:SEND,75-75-0-0,s=7,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=NACK: 4461 !TSF:MSG:SEND,75-75-0-0,s=8,c=0,t=3,pt=0,l=0,sg=0,ft=1,st=NACK: 4502 !TSF:MSG:SEND,75-75-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=2,st=NACK: 4510 TSF:MSG:SEND,75-75-0-0,s=2,c=0,t=3,pt=0,l=0,sg=0,ft=3,st=OK: 4516 MCO:REG:REQ 4554 !TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=NACK:2 6561 TSF:MSG:SEND,75-75-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2 6634 TSF:MSG:READ,0-0-75,s=255,c=3,t=27,pt=1,l=1,sg=0:1 6639 MCO:PIM:NODE REG=1 6641 MCO:BGN:STP 6642 MCO:BGN:INIT OK,TSP=1 6647 TSF:MSG:SEND,75-75-0-0,s=7,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1 6654 TSF:MSG:SEND,75-75-0-0,s=8,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
Debug - this is what i see on the MQTT broker (connected to
mys-out/75/255/3/0/11 Vent Klapans mys-out/75/255/3/0/12 2.1 mys-out/75/3/0/0/7 (null) mys-out/75/4/0/0/6 (null) mys-out/75/1/0/0/3 (null) mys-out/75/7/1/0/2 1 mys-out/75/8/1/0/2 1 mys-out/71/6/1/0/37 626.0
-
@moskovskiy82 upload the clearEepromConfig sketch (available in Examples->MySensors in the Arduino IDE) and run it once, then re-upload your own sketch.
I think the node is using an old node id stored in eeprom. Clearing the eeprom will get rid of that.
-
on second thought, the problem is that #define MY_NODE_ID 56 is after #include <MySensors.h> in your sketch. It needs to be defined before including MySensors.h
-
At least it was getting id 75