Serial Gateway + NRF24 with sleep mode enabled there



  • Hi all,
    I am creating a project where I want to reduce the power consumption of the Serial Gateway too. I would like to modify the mysensor library to enable sleep function also on the Serial Gateway. Would be that possible? My idea is as following:

    I would set up network where the nodes are sleeping for 15 minutes and then will wake up and send sensor data to Serial Gateway via NRF24. Serial Gateway (arduino + NRF24) would be sleeping for 8 seconds and wake up for 1 second and wait if any data received on the NRF24. If not then the gateway will go sleep again for 8 seconds. If any communication triggered then it will do all what is needed.
    The node will wake up every 15 minutes and will send sensors data to gateway. If no ack packet received back it will know that the gateway is sleeping and will resend the data again after 990 ms. It will repeat at most 8 times to be able to catch the serial gateway at the time when it is waked up.

    Just to make it more clear. This is going to be a garden project where no power supply is available. I am going to run everything on the batteries. I already tested different approach without mysensors solution. But I am thinking to implement mysensors there too.

    Any help will be appreciated.

    Thank you in advance.


  • Mod

    I'm missing the point of having the gateway in the garden



  • @gohan - you are right. There is not much sense to have the gateway on the garden. To explain it a bit more. I wanted to create a device which would mix a LPWAN with NRF24. I already have some code for it which do not use mysensors at all. It is still work in progress but it collect data from couple of NRF24 and every 15 minutes it send the data via LPWAN Sigfox module to backend. I was thinking to implement similar solution with mysensors libaries. I understand that it does not give much sense to do so (especially in case that Sigfox LPWAN is very limited by transmited data and lets say no download link at all), but I would like to give it a try. I also need to say that I am new in mysensors and I did first testing of it just today 😊

    Another thing is that if I would be able to access some wifi network on the garden I would use ESP8266 as gateway with NRF24 if possible. Then I can imagine that it would give sense to have such device which would have power down mode enabled for most of the time which I can see like a good solution for smaller systems.

    But like I said, I am new in mysensors project so maybe I do not have enough overview about it yet, then sorry for asking stupid questions here.



  • Just one more add. Looks I succeed with some stupid modification. Definitely not a good solultion but looks it is working for now.

    In file MyTransportNRF24.cpp I added this function

    void startL()
    {
    	RF24_startListening();
    }
    

    And in file MySensorsCore.cpp following modification in _sleep function

    #if defined(MY_REPEATER_FEATURE)
      int8_t result = MY_SLEEP_NOT_POSSIBLE;	// default
      transportPowerDown();
      result = hwSleep(sleepingMS);
      startL();
      return result;
    #else
      uint32_t sleepingTimeMS = sleepingMS;
    

    It is definitely stuppid solution but for now it looks it is working as I wanted 😊


  • Mod

    @boylucky interesting use case. Thanks for explaining.

    Doing what you want with MySensors is a bit tricky. Gateways are intended to be awake all the time, and by default nodes assume they can always reach the gateway.

    With that said, I think it would be possible. You'll probably need to set the gateway as static parent for the nodes. MY_PARENT_NODE_IS_STATIC, MY_PARENT_NODE_ID, and perhaps MY_PASSIVE_NODE. You'll probably need to find a good value for MY_TRANSPORT_WAIT_READY_MS.

    bool isTransportReady (void) can be useful as well.

    And maybe it will be useful to fiddle with RF24_SET_ARD and RF24_SET_ARC https://github.com/mysensors/MySensors/blob/b132a8a81e2ba6c81bcc6e2afce7513cdddbe193/drivers/RF24/RF24registers.h#L43



  • @mfalkvidd - thanks for your reply. I will have a look to what you suggested. Currently I solved the problem of node thinking that gateway is always on with this code on the node sketch (I used the default sketch for DHT11 sensor from mysensors and added following functions (first 2 are just to have possibility to power up and power down the DHT11 sensor from a pin, the third function to catch the gateway in the wake up mode):

    void powerUpDHT()
    {
      // power up DHT11 sensor - PIN 5
      digitalWrite(DHT_POWER_PIN , HIGH);
    }
    
    void powerDownDHT()
    {
      // power down DHT11 sensor - PIN 5
      digitalWrite(DHT_POWER_PIN, LOW);
    }
    
    
    void repeatSend(MyMessage &msg, int repeats)
    {
      int repeat = 0;
      int repeatdelay = 990;
      boolean sendOK = false;
    
      while ((sendOK == false) and (repeat < repeats)) {
        if (send(msg)) {
          sendOK = true;
          Serial.print("ACK packet received: ");
        } else {
          sendOK = false;
          Serial.print("Repeat sending: ");
          Serial.println(repeat);
          //repeatdelay += 250;
        } 
        repeat++;
        wait(repeatdelay);
      }
    }```

  • Mod

    Why not using a longer range radio so that you can reach a powered gateway?



  • @gohan - I am trying to build a solution for more scenarious. For a small garden with just couple of sensors I can imagine that the LPWAN with NRF24 will be good enough. Then for bigger gardens would be better to use long range radious or some other soulutions. In my case I am about 500m from the garden. There are buildings and trees between my home and garden. I wanted to use some cheap solution. So I wanted to make it with NRF24. I tested the long range NRF24 but it was not reliable for this distance with buildings and trees between. But like I said I would like to make a project where more solutions will be available to fit more scenarious to let people re-use it.


  • Mod

    Lora or lorawan?


  • Mod

    @gohan he said Sigfox 🙂


  • Mod

    I saw that, but with LoRa he could have sensors connected directly without a gateway nearby



  • Currently LoRaWAN as Sigfox solution is used. But later on I would like to also test the LoRa for P2P communication as it would definitely suit better for such situations where garden is far from home. Till now I have no experience with P2P LoRa communication and modules.


  • Mod

    If you use Rfm95 it would be like using the normal rfm69 or the nrf24.


  • Mod

    @gohan said in Serial Gateway + NRF24 with sleep mode enabled there:

    I saw that, but with LoRa he could have sensors connected directly without a gateway nearby

    Yes. I just don't see the difference from using Sigfox.



  • @mfalkvidd - Only difference with Sigfox LoRaWAN and P2P LoRa is from my point of view the amount of data you can send. With Sigfox LPWAN node you are limited to 140 messages per day with max 12 bytes of payload in one message. You can send only 4 downlink messages.


  • Mod

    Sigfox is very limited, 12 bytes payload is not much at all, not to mention the only 4 downlink messages



  • I have set MY_PARENT_NODE_IS_STATIC, MY_PARENT_NODE_ID, and perhaps MY_PASSIVE_NODE as you adviced.
    Regarding MY_TRANSPORT_WAIT_READY_MS I do not see how it could help with the sleep mode of the gateway. Can you describe more what did you mean?

    About isTransportReady (void) - I expected that when I use it it will avoid going to sleep if data are comming from NRF24 to be processed. But it did not behave this way. I used following (but tried many other modifications)

    #if defined(MY_REPEATER_FEATURE)
     while (!isTransportReady())
      {
         _process();
      }
      int8_t result = MY_SLEEP_NOT_POSSIBLE;	// default
      transportPowerDown();
      result = hwSleep(sleepingMS);
      startL();
      return result;
    #else
      uint32_t sleepingTimeMS = sleepingMS;
    

    But it happen that the gateway is going to sleep even the messages are comming. But I guess it only from the debuging of messages (maybe there is delay between the incomming messages and printing the debug output to serial).

    Regarding your advice about RF24_SET_ARD and RF24_SET_ARC - if I understand it correctly then I am not able to set a long retry period to be able to wait for the Gateway to wake up. Do you know if there is any other option how to set it there? For now I used the mentioned repeat function which is in the post above.

    Can I ask you if there is some settings which is telling to the node that it is sending ping commands to the gateway and how to disable it or use it especially for this scenarious when the node will be waiting the gateway to wake up and send the data then.


  • Mod

    @boylucky the links in my first reply were intended to answer those questions. If they don't, I don't know. Sorry.



  • Why you don't use timer lib?

    https://playground.arduino.cc/Code/Timer



  • @wikibear - what do you mean exactely? If you mean to use it for specific time communication (gateway and sensor will know the exact time when to comunicate) then it is not suitable as the timer in the arduino is not that accurate. It would require to have real time chip included in both devices. It would not be a problem for the gateway but to have it in each sensor, it could make everything more expensive. So I prefere the way I am trying to do. Sensor will send data about every 15 minutes and the gateway will be on for 500ms after 8 seconds of sleep. During those 500ms it will check if the sensor is trying to send data, and if so then it will stay awake until the communication is done. Of course, the sleep and wake perion can be change, depend on the requirements (number of sensors and update periods of the sensors).



  • OK, i misunderstood that. Sorry.



  • @wikibear - no problem 🙂


Log in to reply
 

Suggested Topics

  • 4
  • 4
  • 2
  • 15
  • 2
  • 9

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts