Please I need some help



  • Hello... Hi everybody, sorry how do I modify the code of water meter pulse to transfer water meter readings from one node to another node by using nrf24l01 instead of sending to the gateway? Any help please



  • @Emmanuel-Abraham

    Doing a google search I found this. I have been down that road and it is totally cool. But time consuming and arcane. My problem was connecting to databases, and making the data useful for other devices.

    So for a lot less headache, debugging and tweaking, I chose MySensors, MQTT, VirtualBox and Home Assistant. Don't get me wrong, my choice is still a lot of H,D&T, but less. And I have connectivity.

    You will learn a lot. Embrace.

    OSD


  • Mod



  • Hello here is an example i use at home: sending value 99 to node n°1

    #define TARGET_NODE 1 // Id node Relay entree et couloir au tableau electrique
    
    MyMessage MsgRelayGlobal(0,V_STATUS); // Message for the Relay actuator on node id 1, sensor 0
    
      // set the Destination of message to the node id of the relay actuator
      MsgRelayGlobal.setDestination(TARGET_NODE);
    
          MsgRelayGlobal.set( (const uint8_t ) 99 );
          Serial.println("Send Message to node 1");
          send(MsgRelayGlobal); // send message to node id 1
    
    

    and here an example of how to deal with the message at target node:

    void MyRelay::Receive(const MyMessage &message) {
      uint8_t payload= 0;
    
      payload= message.getByte();
      if  (message.type==V_STATUS) {
          if (payload==99) {
          // do something
    


  • @hlehoux
    how should be the target code for the sender code below?

    this is the sender pulse water sensor code. i can't see the receiver code.

    /*
     * 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-2018 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * Version 1.1 - GizMoCuz
     *
     * DESCRIPTION
     * Use this sensor to measure volume and flow of your house water meter.
     * You need to set the correct pulsefactor of your meter (pulses per m3).
     * The sensor starts by fetching current volume reading from gateway (VAR 1).
     * Reports both volume and flow back to gateway.
     *
     * Unfortunately millis() won't increment when the Arduino is in
     * sleepmode. So we cannot make this sensor sleep if we also want
     * to calculate/report flow.
     * http://www.mysensors.org/build/pulse_water
     */
    
    // 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 DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
    
    #define PULSE_FACTOR 1000                       // Number of blinks per m3 of your meter (One rotation/liter)
    
    #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
    
    #define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.
    
    #define CHILD_ID 1                              // Id of the sensor child
    
    uint32_t SEND_FREQUENCY =
        30000;           // Minimum time between send (in milliseconds). We don't want to spam the gateway.
    
    MyMessage flowMsg(CHILD_ID,V_FLOW);
    MyMessage volumeMsg(CHILD_ID,V_VOLUME);
    MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
    
    double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter
    
    volatile uint32_t pulseCount = 0;
    volatile uint32_t lastBlink = 0;
    volatile double flow = 0;
    bool pcReceived = false;
    uint32_t oldPulseCount = 0;
    uint32_t newBlink = 0;
    double oldflow = 0;
    double volume =0;
    double oldvolume =0;
    uint32_t lastSend =0;
    uint32_t lastPulse =0;
    
    void setup()
    {
    	// initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
    	pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    
    	pulseCount = oldPulseCount = 0;
    
    	// Fetch last known pulse count value from gw
    	request(CHILD_ID, V_VAR1);
    
    	lastSend = lastPulse = millis();
    
    	attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING);
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Water Meter", "1.1");
    
    	// Register this device as Water flow sensor
    	present(CHILD_ID, S_WATER);
    }
    
    void loop()
    {
    	uint32_t currentTime = millis();
    
    	// Only send values at a maximum frequency or woken up from sleep
    	if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY)) {
    		lastSend=currentTime;
    
    		if (!pcReceived) {
    			//Last Pulsecount not yet received from controller, request it again
    			request(CHILD_ID, V_VAR1);
    			return;
    		}
    
    		if (!SLEEP_MODE && flow != oldflow) {
    			oldflow = flow;
    
    			Serial.print("l/min:");
    			Serial.println(flow);
    
    			// Check that we don't get unreasonable large flow value.
    			// could happen when long wraps or false interrupt triggered
    			if (flow<((uint32_t)MAX_FLOW)) {
    				send(flowMsg.set(flow, 2));                   // Send flow value to gw
    			}
    		}
    
    		// No Pulse count received in 2min
    		if(currentTime - lastPulse > 120000) {
    			flow = 0;
    		}
    
    		// Pulse count has changed
    		if ((pulseCount != oldPulseCount)||(!SLEEP_MODE)) {
    			oldPulseCount = pulseCount;
    
    			Serial.print("pulsecount:");
    			Serial.println(pulseCount);
    
    			send(lastCounterMsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
    
    			double volume = ((double)pulseCount/((double)PULSE_FACTOR));
    			if ((volume != oldvolume)||(!SLEEP_MODE)) {
    				oldvolume = volume;
    
    				Serial.print("volume:");
    				Serial.println(volume, 3);
    
    				send(volumeMsg.set(volume, 3));               // Send volume value to gw
    			}
    		}
    	}
    	if (SLEEP_MODE) {
    		sleep(SEND_FREQUENCY);
    	}
    }
    
    void receive(const MyMessage &message)
    {
    	if (message.type==V_VAR1) {
    		uint32_t gwPulseCount=message.getULong();
    		pulseCount += gwPulseCount;
    		flow=oldflow=0;
    		Serial.print("Received last pulse count from gw:");
    		Serial.println(pulseCount);
    		pcReceived = true;
    	}
    }
    
    void onPulse()
    {
    	if (!SLEEP_MODE) {
    		uint32_t newBlink = micros();
    		uint32_t interval = newBlink-lastBlink;
    
    		if (interval!=0) {
    			lastPulse = millis();
    			if (interval<500000L) {
    				// Sometimes we get interrupt on RISING,  500000 = 0.5 second debounce ( max 120 l/min)
    				return;
    			}
    			flow = (60000000.0 /interval) / ppl;
    		}
    		lastBlink = newBlink;
    	}
    	pulseCount++;
    }
    


  • @mfalkvidd

    thanks sir for the feedback, below is the code for water meter pulse sensor sender but i can't see the receiver code and i don't know where i can get it sir.

    /*
     * 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-2018 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * Version 1.1 - GizMoCuz
     *
     * DESCRIPTION
     * Use this sensor to measure volume and flow of your house water meter.
     * You need to set the correct pulsefactor of your meter (pulses per m3).
     * The sensor starts by fetching current volume reading from gateway (VAR 1).
     * Reports both volume and flow back to gateway.
     *
     * Unfortunately millis() won't increment when the Arduino is in
     * sleepmode. So we cannot make this sensor sleep if we also want
     * to calculate/report flow.
     * http://www.mysensors.org/build/pulse_water
     */
    
    // 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 DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)
    
    #define PULSE_FACTOR 1000                       // Number of blinks per m3 of your meter (One rotation/liter)
    
    #define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.
    
    #define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.
    
    #define CHILD_ID 1                              // Id of the sensor child
    
    uint32_t SEND_FREQUENCY =
        30000;           // Minimum time between send (in milliseconds). We don't want to spam the gateway.
    
    MyMessage flowMsg(CHILD_ID,V_FLOW);
    MyMessage volumeMsg(CHILD_ID,V_VOLUME);
    MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
    
    double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter
    
    volatile uint32_t pulseCount = 0;
    volatile uint32_t lastBlink = 0;
    volatile double flow = 0;
    bool pcReceived = false;
    uint32_t oldPulseCount = 0;
    uint32_t newBlink = 0;
    double oldflow = 0;
    double volume =0;
    double oldvolume =0;
    uint32_t lastSend =0;
    uint32_t lastPulse =0;
    
    void setup()
    {
    	// initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
    	pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    
    	pulseCount = oldPulseCount = 0;
    
    	// Fetch last known pulse count value from gw
    	request(CHILD_ID, V_VAR1);
    
    	lastSend = lastPulse = millis();
    
    	attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING);
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Water Meter", "1.1");
    
    	// Register this device as Water flow sensor
    	present(CHILD_ID, S_WATER);
    }
    
    void loop()
    {
    	uint32_t currentTime = millis();
    
    	// Only send values at a maximum frequency or woken up from sleep
    	if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY)) {
    		lastSend=currentTime;
    
    		if (!pcReceived) {
    			//Last Pulsecount not yet received from controller, request it again
    			request(CHILD_ID, V_VAR1);
    			return;
    		}
    
    		if (!SLEEP_MODE && flow != oldflow) {
    			oldflow = flow;
    
    			Serial.print("l/min:");
    			Serial.println(flow);
    
    			// Check that we don't get unreasonable large flow value.
    			// could happen when long wraps or false interrupt triggered
    			if (flow<((uint32_t)MAX_FLOW)) {
    				send(flowMsg.set(flow, 2));                   // Send flow value to gw
    			}
    		}
    
    		// No Pulse count received in 2min
    		if(currentTime - lastPulse > 120000) {
    			flow = 0;
    		}
    
    		// Pulse count has changed
    		if ((pulseCount != oldPulseCount)||(!SLEEP_MODE)) {
    			oldPulseCount = pulseCount;
    
    			Serial.print("pulsecount:");
    			Serial.println(pulseCount);
    
    			send(lastCounterMsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1
    
    			double volume = ((double)pulseCount/((double)PULSE_FACTOR));
    			if ((volume != oldvolume)||(!SLEEP_MODE)) {
    				oldvolume = volume;
    
    				Serial.print("volume:");
    				Serial.println(volume, 3);
    
    				send(volumeMsg.set(volume, 3));               // Send volume value to gw
    			}
    		}
    	}
    	if (SLEEP_MODE) {
    		sleep(SEND_FREQUENCY);
    	}
    }
    
    void receive(const MyMessage &message)
    {
    	if (message.type==V_VAR1) {
    		uint32_t gwPulseCount=message.getULong();
    		pulseCount += gwPulseCount;
    		flow=oldflow=0;
    		Serial.print("Received last pulse count from gw:");
    		Serial.println(pulseCount);
    		pcReceived = true;
    	}
    }
    
    void onPulse()
    {
    	if (!SLEEP_MODE) {
    		uint32_t newBlink = micros();
    		uint32_t interval = newBlink-lastBlink;
    
    		if (interval!=0) {
    			lastPulse = millis();
    			if (interval<500000L) {
    				// Sometimes we get interrupt on RISING,  500000 = 0.5 second debounce ( max 120 l/min)
    				return;
    			}
    			flow = (60000000.0 /interval) / ppl;
    		}
    		lastBlink = newBlink;
    	}
    	pulseCount++;
    }
    


  • Hello @Emmanuel-Abraham , i've never used this pulse meter sensor.

    as far as i can see, it's sending 3 different values to the gateaway:

    flow value : send(flowMsg.set(flow, 2));
    pulse count : send(lastCounterMsg.set(pulseCount));
    volume : send(volumeMsg.set(volume, 3));

    so if you want to send say the flow value to another node, let's say node 34
    you should
    flowMsg.setDestination(34);

    and you have to add the
    void receive(const MyMessage &message)
    {
    }
    function in the code of your node n°34



  • @hlehoux

    Thanks sir for the reply, sorry can you help me to write water meter pulse sensor receiver code for the transmitter code above?



  • @Emmanuel-Abraham sorry but i’m not sure i understand what you want to achieve.
    i think you already have a working water pulse sensor but can you explain what you want to do ? why another node ? what do you want this node to do ? what data do you want to send to the node ?

    what is your programming knowledge ?



  • @hlehoux ok for now i need one transmitter and one receiver, on transmitter side will be attached to water meter that will be attached with water pulse sensor to monitor water flow rate, water consumption in Liters or in cubic meters and battery level status and this three data should be sent to a receiver that will include display to display that data from the transmitter sir, the transmitter should operates at least 1 year without replacing the battery. that's what i wanted sir.



  • OK, for the receiver you could use this example: https://www.mysensors.org/build/display

    you will have to adapt the example code which is displaying the current time.

    and add the receive function
    void receive(const MyMessage &message)
    {
    }

    and inside the receive function extract the the values you want and display it through lcd.print()

    hope this helps



  • you will for sure also find many other "display" node example in the forum.



  • @hlehoux sorry sir can you help me to modify my two codes above one for transmitter and another for receiver by using your example above? I I told you I have not enough knowledge about mysensors library sir please help me.



  • @Emmanuel-Abraham said in Please I need some help:

    how do I modify the code of water meter pulse to transfer water meter readings from one node to another node by using nrf24l01

    Hello this is Gulshan Negi
    I am a newbie here.
    To modify the code of a water meter pulse to transmit readings from one node to another using the nRF24L01, you will need to do the following:

    a. Install the necessary libraries for the nRF24L01 module. You will need to download the Arduino libraries for the nRF24L01 and install them on your computer.
    b. Connect the nRF24L01 module to your microcontroller. The nRF24L01 module has six pins that need to be connected to your microcontroller. These are VCC, GND, MOSI, MISO, SCK, and CE.
    c. Initialize the nRF24L01 module in your code. You will need to include the libraries for the nRF24L01 module in your sketch and initialize the module by setting up the appropriate communication speeds and addresses.
    d. Set up the transmitter and receiver nodes. You will need to set up two nodes, one for transmitting and one for receiving. The transmitter node will send the water meter readings to the receiver node via the nRF24L01 module.
    e. Write the code to transmit and receive the water meter readings. You will need to write code to transfer the water meter readings from the transmitter node to the receiver node using the nRF24L01 module. You will also need to write code to receive the water meter readings at the receiver node and process them as required.

    I hope this helps!
    Thanks



  • @gulshan212 how can i do this by using mysensors library coz i need also to save battery power.


Log in to reply
 

Suggested Topics

11
Online

11.4k
Users

11.1k
Topics

112.7k
Posts