Combining MySensors examples


  • Admin


  • Mod

    @hek Yay, spreading the word! 😆


  • Hardware Contributor

    @hek STICKY STICKY STICKY!

    This is actually one of the first sticking points i had when i migrated over to MySensors.org. Now thanks to this tutorial i hope that others don't get my confusion of how to combine multiple sensor array within one node. I'm sure you're going to get many thanks for spreading this!



  • Hi,
    I have also developed multi-sensor nodes based on MySensors 1.5, they works fine on the table, few more details here: http://forum.mysensors.org/topic/2747/home-automation-multi-sensor-nodes
    The 1.6 version will follow soon, I hope.



  • I have updated my project. While still under testing, now it use MySensors 2.0.0 beta , external MQTT and tested examples of sensors on the gateway.



  • Hello,

    Sorry but I've already done the job here :
    Please have a look at "RelayActuatorLrt.ino" in order to know how to use it, it's simple.

    [https://forum.mysensors.org/topic/2537/device-library](link url)

    Is it possible to integrate it in a future release of MySensors ?



  • hek,

    Would it be possible if you could make a new video that's more up to date? I know that this could be asking a lot but I tried multiple times to combine sketches/examples to no avail. I presently have nodes next to each other that I would love to be able to combine them together. Also, possibly adding in how to add two of the same examples, for example two door/window sensors?

    I really want to get a grasp on this and have been reading a lot but unfortunately I’m still missing something.

    Either way thanks you for your video. Even though I haven’t been able to get anything working I now have a better understanding of what needs to be done.



  • I too am interested in this.
    @bluezr1


  • MySensors Evangelist

    @bluezr1 I can imagine your struggle. Have had my fair share as well. The following code is running stable and has around 9 sensors it is serving. Maybe you can grab the pieces you need for your nodes. Unfortunately did not make a video.



  • @bluezr1
    Do you see "MockMySensors" example sketch which comes with MySensors library?
    There are all sensors in one sketch together.
    Presentation, sending its values, receiving ....


  • MySensors Evangelist

    @kimot said in Combining MySensors examples:

    MockMySensors

    Haha tnx glad I learned something today. Did not know about this example 😉



  • Video in OP was good for "beginner" but you very quickly run into other issues. For me it was getting confused by lots of talk about interrupts (in relation to "input" type sensors). All of Build pages for these type of sensors mention about interrupts only being available on pins 2 and 3 (assuming Arduino Pro Mini, etc.). Which only confused me further (at first). However maybe you are smarter than me. 😉 But look closely, most (all?) of MySensors code I have seen for "inputs" (door, motion, etc.) actually DO NOT use interrupts! Notice the code runs right in the main loop. Interrupts are only needed when you sleep the node!

    Everything I talk about here is for always powered nodes, where you do not need to sleep because you are not on batteries. For batteries you need to sleep to save power, and then we have to do things different. Then you will need to use the hardware interrupts, to wake the node from sleeping. But that I will call "advanced" and beyond the scope of this particular post here, which I am calling "intermediate". So, back to that...

    You can use any pin you want (almost) for inputs when you are not sleeping the node. OP video does mention about non blocking code, but he does not go into detail. I don't know why not, as it is not complicated. You simply do wait() instead of sleep(). Or, if you are combining one or more thing(s) that needs to "listen" all the time (lets say, an actuator/relay, and for fun let's add a motion sensor, too!), with something that needs to send() periodically (let's say a temperature sensor) then you just keep looping over and over checking all your inputs, and then only enter the output (temperature) part of the code every so many millis(). An example:

    void loop()     
    {
      // put code here to check motion sensor (copy from loop() part of motion sensor sketch)
    
      // now we check if enough time has passed to check temperature, if so we enter this subroutine
      if ( millis() > millisLastTemperature + TEMPERATURE_CHECK_INTERVAL )
        {
        // put code here to check temperature sensor(s)
    
        // Right before we exit temperature subroutine, note current time as last time temperature was sent.
        millisLastTemperature = millis();
        }
    
    // That's it for main loop()
    }
    
    // the relay needs code to receive incoming messages
    void receive(const MyMessage &message)
    {
      // Put code here from receive() part of relay sketch
    }
    

    Doing this way, you could even combine multiple sensors (temperature, humidity, light, etc.) to take readings even on different intervals. Just duplicate that subroutine, and give each one their own <SENSOR>_CHECK_INTERVAL variable. Just remember to define all your variables at the top of the sketch, and when dealing with millis() you want to use data type of unsigned long.

    Speaking of which, I think you also must have some very basic programming or even logical skills. But there is a lot of information in Internet nowadays, so hopefully you can study and teach yourself enough to get by.

    Good luck, and don't hesitate to post if you run into trouble. Don't suffer along in silence and then give up, without saying anything to anyone. Ask me how I know. 😉


Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 6
  • 3
  • 1
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts