some problem in sensor + repeater !



  • hi i have some problem to convert a node to sensor+repeater !
    for example light sensor :

    #include <SPI.h>
    #include <MySensor.h>  
    #include <BH1750.h>
    #include <Wire.h> 
    
    #define CHILD_ID_LIGHT 0
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    BH1750 lightSensor;
    MySensor gw;
    
    // V_LIGHT_LEVEL should only be used for uncalibrated light level 0-100%.
    // If your controller supports the new V_LEVEL variable, use this instead for
    // transmitting LUX light level.
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    // MyMessage msg(CHILD_ID_LIGHT, V_LEVEL);  
    uint16_t lastlux;
    
    void setup()  
    { 
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Light Lux Sensor", "1.0");
    
      // Register all sensors to gateway (they will be created as child devices)
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      
      lightSensor.begin();
    }
    
    void loop()      
    {     
      uint16_t lux = lightSensor.readLightLevel();// Get Lux value
      Serial.println(lux);
      if (lux != lastlux) {
          gw.send(msg.set(lux));
          lastlux = lux;
      }
      
      gw.sleep(SLEEP_TIME);
    }
    

    i remove lines :
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    and
    gw.sleep(SLEEP_TIME);
    and i add #define MY_REPEATER_FEATURE
    sensor is start to report many lux... each second 1000 report . . .
    please change this code to a repeater+sensor and report every 1 min !



  • @Reza
    You can change your code yourself: replace gw.sleep(sleep_time) by gw.wait(sleep_time).

    Given the posted code I think you use the MySensors 1.5 libraries.

    BR,

    Boozz



  • @boozz
    hi thank you for help me ,
    now i use 2 library . and in some sketchs (sensor without repeater) , there are 2 line for sleep :
    unsigned long SLEEP_TIME = 30000;
    sleep(SLEEP_TIME);

    for convert this sensors to sensor+repeater , what am i do ?
    add line:
    #define MY_REPEATER_FEATURE

    and change this line to :
    sleep(SLEEP_TIME); ~~> wait(SLEEP_TIME);

    is this correct ?



  • @Reza
    Instead of asking people in the forum at every step you take, you could use the trial and error method.

    BR,

    Boozz



  • @boozz
    🙂 ok but if it is possible guidance me just This time
    this is true ?
    sleep(SLEEP_TIME); ~~> wait(SLEEP_TIME); ?
    thank you



  • @Reza
    just try it and see what happens



  • @boozz said:

    just try it and see what happens

    ok thank you 😞


  • Hardware Contributor

    @Reza
    @boozz has already answered you how to. You should try, that does not hurt, and you may be happy by the result. You don't want a sleeping repeater? better a waiting repeater!
    That said i would not use the wait, it's possible to code this quicker. But it's a little bit more advanced.
    I advice you to read some reference about Arduino etc... and try. always try or you don't learn anything!
    An howto which could be useful for you, perhaps later, is the blink led without delay from Arduino Reference for instance. And lot of other things. That's not always easy to write code for others, can take time or not same config. and others don't learn then..



  • @scalz said:

    has already answered you how to. You should try, that does not hurt, and you may be happy by the result. You don't want a sleeping repeater? better a waiting repeater!
    That said i would not use the wait, it's possible to code this quicker. But it's a little bit more advanced.
    I advice you to read some reference about Arduino etc... and try. always try or you don't learn anything!
    An howto which could be useful for you, perhaps later, is the blink led without delay from Arduino Reference for instance. And lot of other things. That's not always easy to write code for others, can take time or not same config. and others don't learn then..

    hi my friend , i know this but about this issue , i need this quickly and I don't have time for begin in arduino and full programming 😞


  • Hardware Contributor

    Have you tried ??
    well, about needing quickly, without learning... you're perhaps misunderstanding a bit things.. imho mysensors is great, open, dynamic community which try to make things easier for noobs. Sure that's very attractive, but don't forget you're in arduino/dev/mcu world...if you don't want to read&learn a minimum, you will be stuck in the examples sketch folders...



  • @scalz said:

    Have you tried ??
    well, about needing quickly, without learning... you're perhaps misunderstanding a bit things.. imho mysensors is great, open, dynamic community which try to make things easier for noobs. Sure that's very attractive, but don't forget you're in arduino/dev/mcu world...if you don't want to read&learn a minimum, you will be stuck in the examples sketch folders...
    i want try to learn but not now ! now i need this quickly 😞 so after this i try to learn step by step. . .


  • Hardware Contributor

    okay but have you tried wait instead of sleep?? we still don't know..



  • @scalz said:

    okay but have you tried wait instead of sleep?? we still don't know..

    no
    well , this topic for this !!! i told you , can i replace wait Instead sleep? i fear for The arbitrary action so before i want sure


  • Hardware Contributor

    No fear to have! A sleep or wait won't burn your node.

    I told you above:

    @scalz said:

    You don't want a sleeping repeater? better a waiting repeater!

    what do you think 😉 Does a repeater should sleep?? If so, how could he listens and repeat? So.. the repeater can't sleep! you would prefer to use wait, so it listens/wait and repeat.
    I hope this is okay. If you have a problem then why not, but imho your issue is solved.



  • @scalz
    so i test with wait 🙂 thank you my friend


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 2
  • 2
  • 10
  • 5

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts