ask the gateway not to send back acq
send(msg.setDestination(MY_PARENT_NODE_ID).setSensor(CHILD_ID).set(state?false:true), false); // Send new state and request ack back
wait(100);
send(msg.setDestination(SYSTER_ID).setSensor(CHILD_ID).set(state?false:true), true);
Posts made by FullMetal
-
RE: Node to Node Communication via Gatreway
-
RE: Node to Node Communication via Gatreway
@tekka said in Node to Node Communication via Gatreway:
@FullMetal said in Node to Node Communication via Gatreway: Please upload the debug logs for further troubleshooting.
Sorry
Debug logs node 4
Press button node 408:16:01.668 -> 13555 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
08:16:01.701 -> 13582 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:0
08:16:01.701 -> 13586 TSF:MSG:ECHO
08:16:01.701 -> This is an ack from gateway08:16:01.701 -> Incoming change for sensor:1, New status: 0
08:16:01.800 -> 13678 TSF:MSG:SEND,4-4-5-5,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
08:16:01.800 -> 13684 TSF:RTE:N2N OK
08:16:01.800 -> 13703 TSF:MSG:READ,5-5-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
08:16:01.833 -> 13708 TSF:MSG:ECHO
08:16:01.833 -> This is an ack from gateway08:16:01.833 -> Incoming change for sensor:1, New status: 1
Press button node 5
08:21:01.371 -> 313012 TSF:MSG:READ,5-5-4,s=1,c=1,t=2,pt=1,l=1,sg=0:0
08:21:01.371 -> Incoming change for sensor:1, New status: 0second press node 5
08:21:06.238 -> 317865 TSF:MSG:READ,5-5-4,s=1,c=1,t=2,pt=1,l=1,sg=0:0
08:21:06.238 -> Incoming change for sensor:1, New status: 0Debug logs node 5
Press button node 408:23:59.955 -> 51752 TSF:MSG:READ,4-4-5,s=1,c=1,t=2,pt=1,l=1,sg=0:1
08:23:59.955 -> 51757 TSF:MSG:ECHO REQ
08:23:59.988 -> 51777 TSF:MSG:SEND,5-5-4-4,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
08:23:59.988 -> 51783 TSF:RTE:N2N OK
08:23:59.988 -> Incoming change for sensor:1, New status: 1Press button node 5
08:24:36.929 -> 88704 TSF:MSG:SEND,5-5-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
08:24:36.929 -> wait 1/10sec08:24:37.062 -> 88827 TSF:MSG:SEND,5-5-4-4,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
08:24:37.062 -> 88834 TSF:RTE:N2N OKDebug logs gateway
Press button node 4 and node 508:26:19.261 -> 0;255;3;0;9;79078 TSF:MSG:READ,4-4-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
08:26:19.261 -> 0;255;3;0;9;79084 TSF:MSG:ACK REQ
08:26:19.294 -> 0;255;3;0;9;79105 TSF:MSG:SEND,0-0-4-4,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
08:26:19.294 -> 4;1;1;0;2;0
08:26:20.321 -> 0;255;3;0;9;80116 TSF:MSG:READ,5-5-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
08:26:20.321 -> 5;1;1;0;2;0 -
RE: Node to Node Communication via Gatreway
@tekka @rejoe2
Désolé de revenir si tard ..
J'ai modifié mon code sur mes nœuds, mais le résultat n'est toujours pas là!Voici mes codes:
node 4:
// MySensors #define MY_PARENT_NODE_ID 0 // define if fixed parent #define MY_PARENT_NODE_IS_STATIC #undef MY_REGISTRATION_FEATURE // sketch moves on if no registration #define MY_NODE_ID 4 // fixed node number // Enable debug prints to serial monitor #define MY_DEBUG // Enable RS485 transport layer #define MY_RS485 // Define this to enables DE-pin management on defined pin #define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use #define MY_RS485_BAUD_RATE 9600 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED #include <MySensors.h> #include <Bounce2.h> #define RELAY_PIN 4 // Arduino Digital I/O pin number for relay #define BUTTON_PIN 3 // Arduino Digital I/O pin number for button #define CHILD_ID 1 // Id of the sensor child #define SYSTER_ID 5 #define RELAY_ON 1 #define RELAY_OFF 0 Bounce debouncer = Bounce(); int oldValue=0; bool state; MyMessage msg(CHILD_ID,V_LIGHT); //MyMessage msgconf(CHILD_ID,V_VAR1); void setup() { // Setup the button pinMode(BUTTON_PIN,INPUT_PULLUP); // Activate internal pull-up //digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state = loadState(CHILD_ID); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay & Button", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_LIGHT); } /* * Example on how to asynchronously check for new messages from gw */ void loop() { debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { send(msg.setDestination(MY_PARENT_NODE_ID).setSensor(CHILD_ID).set(state?false:true), true); // Send new state and request ack back wait(100); send(msg.setDestination(SYSTER_ID).setSensor(CHILD_ID).set(state?false:true), true); } oldValue = value; } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(CHILD_ID, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
node 5:
// MySensors #define MY_PARENT_NODE_ID 0 // define if fixed parent #define MY_PARENT_NODE_IS_STATIC #undef MY_REGISTRATION_FEATURE // sketch moves on if no registration #define MY_NODE_ID 5 // fixed node number // Enable debug prints to serial monitor #define MY_DEBUG // Enable RS485 transport layer #define MY_RS485 // Define this to enables DE-pin management on defined pin #define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use #define MY_RS485_BAUD_RATE 9600 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED // Enable this if RS485 is connected to a hardware serial port //#define MY_RS485_HWSERIAL Serial1 //#include <MqttClient.h> #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #define CHILD_ID 1 #define SYSTER_ID 4 #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch Bounce debouncer = Bounce(); int oldValue=0; bool state; // Change to V_LIGHT if you use S_LIGHT in presentation below MyMessage msg(CHILD_ID,V_LIGHT); void setup() { // Setup the button pinMode(BUTTON_PIN,INPUT_PULLUP); // Activate internal pull-up //digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); } void presentation() { // Register binary input sensor to gw (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. sendSketchInfo("Button", "1.1"); present(CHILD_ID, S_LIGHT); } // Check if digital input has changed and send in new value void loop() { debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { send(msg.setDestination(MY_PARENT_NODE_ID).setSensor(CHILD_ID).set(state?false:true), false);// Send new state and request ack back Serial.println("wait 1/10sec"); wait(100); send(msg.setDestination(SYSTER_ID).setSensor(CHILD_ID).set(state?false:true), false); } oldValue = value; } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); //digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(SYSTER_ID, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
From node 4, my output is activated and deactivated immediately, due to double sending
from node 5, I can activate or deactivate if I launch the command from node 4 before otherwise.
-
RE: Node to Node Communication via Gatreway
@rejoe2
thank you for your return,
but I have the same problem, I manage to activate the relay of node 4 from node 5, but I cannot deactivate it. and when I act on node 5 the gateway does not receive frames since it calls node 4.
I think that node 4 should send the relay status to node 5 so that it knows whether it is activated or not. -
RE: Node to Node Communication via Gatreway
Hello,
Sorry to resort to an old topic ...
I am currently using mysensors RS485, and I would like to extend my installation with this protocol.
and I would like to make the nodes communicate with each other through the gateway.
But I can't do what I want ... help!
on my node 4, I have an input and 1 output, the input activates and deactivates the output. (here no worries).
On my node 5, I have an input to activate the output of node 4, so I can turn it off but not turn it on, and I don't see any frames towards the gatewayhere is the code for my node 5:
// MySensors #define MY_PARENT_NODE_ID 0 // define if fixed parent #define MY_PARENT_NODE_IS_STATIC #undef MY_REGISTRATION_FEATURE // sketch moves on if no registration #define MY_NODE_ID 5 // fixed node number // Enable debug prints to serial monitor #define MY_DEBUG // Enable RS485 transport layer #define MY_RS485 // Define this to enables DE-pin management on defined pin #define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use #define MY_RS485_BAUD_RATE 9600 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED // Enable this if RS485 is connected to a hardware serial port //#define MY_RS485_HWSERIAL Serial1 //#include <MqttClient.h> #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #define CHILD_ID 4 #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch Bounce debouncer = Bounce(); int oldValue=0; bool state; // Change to V_LIGHT if you use S_LIGHT in presentation below MyMessage msg(CHILD_ID,V_LIGHT); void setup() { // Setup the button pinMode(BUTTON_PIN,INPUT_PULLUP); // Activate internal pull-up //digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); } void presentation() { // Register binary input sensor to gw (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. sendSketchInfo("Button", "1.1"); present(CHILD_ID, S_LIGHT); } // Check if digital input has changed and send in new value void loop() { debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { msg.setDestination(4); send(msg.set(state?false:true), false);// Send new state and request ack back } oldValue = value; }
-
RE: 💬 Power Meter Pulse Sensor
In fact, my code does not work as I would like, HC information systematically go back to the HP ID.
Can you help me
-
RE: 💬 Power Meter Pulse Sensor
Here is the modified code:
#define MY_PARENT_NODE_ID 0 // define if fixed parent #define MY_PARENT_NODE_IS_STATIC #undef MY_REGISTRATION_FEATURE // sketch moves on if no registration #define MY_NODE_ID 2 // fixed node number // Enable debug prints #define MY_DEBUG // Enable RS485 transport layer #define MY_RS485 // Define this to enables DE-pin management on defined pin #define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use #define MY_RS485_BAUD_RATE 9600 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err #define MY_DEFAULT_ERR_LED_PIN 13 // Error led pin #define MY_DEFAULT_RX_LED_PIN 7 // Receive led pin #define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED // Enable and select radio type attached //#define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <MySensors.h> #include <SPI.h> #include <Bounce2.h> #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define DIGITAL_INPUT_HCHP 5 #define PULSE_FACTOR 250 // Nummber of blinks per KWH of your meeter #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false. #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers. //#define CHILD_ID 2 // Id of the sensor child unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour bool pcReceived = false; volatile unsigned long pulseHpCount = 0; volatile unsigned long pulseHcCount = 0; volatile unsigned long lastBlink = 0; unsigned long oldPulseHpCount = 0; volatile unsigned long watt = 0; unsigned long oldWatt = 0; double oldKwhHp; unsigned long oldPulseHcCount = 0; double oldKwhHc; unsigned long lastSend; Bounce debouncer = Bounce(); int oldValue=-1; MyMessage wattMsg(1,V_WATT); MyMessage kwhHpMsg(3,V_KWH); MyMessage pcHpMsg(2,V_VAR1); MyMessage kwhHcMsg(5,V_KWH); MyMessage pcHcMsg(6,V_VAR1); MyMessage hchpMsg(7,V_VAR2); const int ledPin = 13; // sortie digitale void setup() { // Fetch last known pulse count value from gw request(2, V_VAR1); request(6, V_VAR1); // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output // If no pullup is used, the reported usage will be too high because of the floating pin pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP); pinMode(DIGITAL_INPUT_HCHP,INPUT_PULLUP); pinMode(ledPin, OUTPUT); attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING); lastSend=millis(); // After setting up the button, setup debouncer debouncer.attach(DIGITAL_INPUT_HCHP); debouncer.interval(5); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Energy Meter", "2.0"); // Register this device as power sensor present(1, S_POWER); // Register this device as power sensor present(2, S_POWER); // Register this device as power sensor present(3, S_POWER); // Register this device as power sensor present(5, S_POWER); // Register this device as power sensor present(6, S_POWER); // Register this device as power sensor present(7, S_POWER); } void loop() { unsigned long now = millis(); if (digitalRead(DIGITAL_INPUT_SENSOR) == LOW ) { // LED Power On digitalWrite(ledPin, HIGH); // LED Power Off digitalWrite(ledPin, LOW); } { debouncer.update(); // Get the update value int value = debouncer.read(); Serial.println(""); if (value != oldValue) { // Send in the new value send(hchpMsg.set(value==HIGH ? 1 : 0)); oldValue = value; } } // Only send values at a maximum frequency or woken up from sleep bool sendTime = now - lastSend > SEND_FREQUENCY; if (pcReceived && (SLEEP_MODE || sendTime)) { // New watt value has been calculated if (!SLEEP_MODE && watt != oldWatt) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt<((unsigned long)MAX_WATT)) { send(wattMsg.set(watt)); // Send watt value to gw } Serial.print("Watt:"); Serial.println(watt); oldWatt = watt; } /////HP if (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH ) { // Pulse cout has changed if (pulseHpCount != oldPulseHpCount) { send(pcHpMsg.set(pulseHpCount)); // Send pulse count value to gw double kwhHp = ((double)pulseHpCount/((double)PULSE_FACTOR)); oldPulseHpCount = pulseHpCount; digitalWrite(ledPin, LOW); if (kwhHp != oldKwhHp) { send(kwhHpMsg.set(kwhHp, 4)); // Send kwh value to gw oldKwhHp = kwhHp; } digitalWrite(ledPin, HIGH); } lastSend = now; }else if (digitalRead(DIGITAL_INPUT_SENSOR) == LOW ){ if (pulseHcCount != oldPulseHcCount) { send(pcHcMsg.set(pulseHcCount)); // Send pulse count value to gw double kwhHc = ((double)pulseHcCount/((double)PULSE_FACTOR)); oldPulseHcCount = pulseHcCount; digitalWrite(ledPin, LOW); if (kwhHc != oldKwhHc) { send(kwhHcMsg.set(kwhHc, 4)); // Send kwh value to gw oldKwhHc = kwhHc; } digitalWrite(ledPin, HIGH); } lastSend = now; } }else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(2, V_VAR1); request(6, V_VAR1); lastSend=now; } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } } void receive(const MyMessage &message) { /////HP if (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH ) { if (message.type==V_VAR1) { pulseHpCount = oldPulseHpCount = message.getLong(); Serial.print("Received last pulse count from gw:"); Serial.println(pulseHpCount); pcReceived = true; } } /////HC if (digitalRead(DIGITAL_INPUT_SENSOR) == LOW ) { if (message.type==V_VAR1) { pulseHcCount = oldPulseHcCount = message.getLong(); Serial.print("Received last pulse count from gw:"); Serial.println(pulseHcCount); pcReceived = true; } } } void onPulse() { /////HP if (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH ) { if (!SLEEP_MODE) { unsigned long newBlink = micros(); unsigned long interval = newBlink-lastBlink; if (interval<10000L) { // Sometimes we get interrupt on RISING return; } watt = (3600000000.0 /interval) / ppwh; lastBlink = newBlink; } pulseHpCount++; } /////HC else if (digitalRead(DIGITAL_INPUT_SENSOR) == LOW ) { if (!SLEEP_MODE) { unsigned long newBlink = micros(); unsigned long interval = newBlink-lastBlink; if (interval<10000L) { // Sometimes we get interrupt on RISING return; } watt = (3600000000.0 /interval) / ppwh; lastBlink = newBlink; } pulseHcCount++; } }
-
RE: 💬 Power Meter Pulse Sensor
Thank you for your welcome @mfalkvidd
Our electricity provider offers several rates.
HP: Full time
HC: off-peak timeusually the HP/HC rate is programmed at night by the provider.
As the consumption is saved by the arduino, I need two different IDs to trace the information to domotics
-
RE: 💬 Power Meter Pulse Sensor
Hello
my skectch works very well, only I have a double pricing, I manage to recover the information. but I have to modify the code in order to have my exact consumption.
but my code sends me information always on the same IDs.
thank you