Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. SuperKris
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by SuperKris

    • RE: Old school phone as doorbell and domoitcs interface!

      Thanks guys!

      @yveaux Dont know that site very well, but i might do that... If enough people like the idea and build it i might develop it further. There are some other ideas like a mute function and i have been wondering if it would be possible to develop a module that just connects to any old pone as a external box.

      posted in My Project
      SuperKris
      SuperKris
    • Old school phone as doorbell and domoitcs interface!

      So i made a really cool project with a old phone.

      The current version features the following functions:

      • Doorbell function with simple button
      • MySensors integration with NRF24 radio
      • Wirelessly activate 5 different ringtones
      • Alarm signal
      • Working dial with 10 virtual switches

      The full description of the project can be found here:
      https://superkris.tweakblogs.net/blog/16935/old-school-phone-as-doorbell-and-domoitcs-interface!

      Hope you guys like it!

      Old school phone as doorbell and domotics interface – 03:28
      β€” Kristiaan N.

      0_1542365227093_646237.png

      Unfortunately i cant paste the code here because its to long, but it can be found on the link provided above.

      posted in My Project
      SuperKris
      SuperKris
    • RE: Virtual switches that never go off and controllers

      @mfalkvidd said in Virtual switches that never go off and controllers:

      wait() will not mess with ability to receive radio - in fact, handling the radio is exactly what is done inside wait(). However, if a radio message needs to be handled, wait() can take more time than the specified number of milliseconds. Therefore, wait() won't be suitable for generating a precise 5ms square wave.

      As you probably already guessed, button presses will be ignored during wait(), unless you use interrupts.

      For a more flexible solution, you'll need to modify all code to work without wait. See https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay for a simple starting point, but be aware that it gets more and more complex with multiple different things happening at the same time.

      Thanks for the info! i was afraid that was what wait was doing. The question is how bad i want to fix this... I know about millis. I dont have to rewrite that much code for it. Maybe there is some library i can use.

      Also it doesnt really matter how good the square wave is, as long as the 2 "bell" pins are never high at the same time.

      I guess millis can be the solution for sending a off signal to, or are there better ways to handle this?

      posted in Development
      SuperKris
      SuperKris
    • RE: Virtual switches that never go off and controllers

      The code so far....

      Another problem i have is in the "ringtone" in the last part of the code. It stops the whole code of the arduino while running. Is wait not a suitable function for this? or does this happen because its in a while loop?
      Are there better ways to solve this?

      /**
       * 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-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/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.
       *
       *******************************
       *
       * DESCRIPTION
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (button below) and GND.
       * http://www.mysensors.org/build/binary
       */
      
      /// ##### mysensors setup ######
      #define ProjectName "OldPhone" // Name that is vissible in controller
      #define ProjectVersion "0,1"          // Version that is vissible in controller
      #define MY_DEBUG       // Enable debug prints to serial monitor
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      #define childIdDoor 1         // child ID number used by mysensors foor doorbell button
      #define chuildIdDail_1 101    // child ID number used by mysensors when the number 1 is dailed
      #define chuildIdDail_2 102    // child ID number used by mysensors when the number 2 is dailed
      #define chuildIdDail_3 103    // child ID number used by mysensors when the number 3 is dailed
      #define chuildIdDail_4 104    // child ID number used by mysensors when the number 4 is dailed
      #define chuildIdDail_5 105    // child ID number used by mysensors when the number 5 is dailed
      #define chuildIdDail_6 106    // child ID number used by mysensors when the number 6 is dailed
      #define chuildIdDail_7 107    // child ID number used by mysensors when the number 7 is dailed
      #define chuildIdDail_8 108    // child ID number used by mysensors when the number 8 is dailed
      #define chuildIdDail_9 109    // child ID number used by mysensors when the number 9 is dailed
      #define chuildIdDail_10 110   // child ID number used by mysensors when the number 0 is dailed
      
      // ###### Include libraries #####
      #include <SPI.h>              // needed for NRF24
      #include <MySensors.h>        // mysensors library
      #include <Bounce2.h>          // for debouncing buttons and dail
      
      // ###### I/O pin number setup ######
      #define button 3              // input pin activated when doorbell button is pressed
      #define edail 8               // input pin activated when dail is used (Enable Dail)
      #define pdail 7               // input pin activated with each tick of the dail (Pulse Dial)
      #define lbell 4               // output pin to swing bellh hamer left
      #define rbell 5               // output Pin to swing bellh hamer right
      
      // ##### Debouncer variables #####
      Bounce debouncerButton = Bounce(); // Create button debouncer for doorbell button 
      Bounce debouncerEdail = Bounce();  // Create button debouncer for Enable Dail
      Bounce debouncerPdail = Bounce();  // Create button debouncer for Pulse Dial 
      int valueButton = 0;               // Value 
      int oldValueButton = 0;
      int valueEdail = 0;
      int oldValueEdail = 0;
      int valuePdail = 0;
      int oldValuePdail = 0;
      int dailCount = 0;
      int newDailCount = 0;  
      
      
      int ring = 0;
      int ringX = 15;
      int onPulse = 20;
      int offPulse = 10;
      int repeat = 0;
      int repeatX = 4;
      int ringPause = 2000;
      
      // ##### setup MySensors message containers #####
      MyMessage msgDoor(childIdDoor,V_STATUS);         // message container used for doorbell button
      MyMessage msgDail_1(chuildIdDail_1,V_STATUS);    // message container used when the number 1 is dailed
      MyMessage msgDail_2(chuildIdDail_2,V_STATUS);    // message container used when the number 2 is dailed
      MyMessage msgDail_3(chuildIdDail_3,V_STATUS);    // message container used when the number 3 is dailed
      MyMessage msgDail_4(chuildIdDail_4,V_STATUS);    // message container used when the number 4 is dailed
      MyMessage msgDail_5(chuildIdDail_5,V_STATUS);    // message container used when the number 5 is dailed
      MyMessage msgDail_6(chuildIdDail_6,V_STATUS);    // message container used when the number 6 is dailed
      MyMessage msgDail_7(chuildIdDail_7,V_STATUS);    // message container used when the number 7 is dailed
      MyMessage msgDail_8(chuildIdDail_8,V_STATUS);    // message container used when the number 8 is dailed
      MyMessage msgDail_9(chuildIdDail_9,V_STATUS);    // message container used when the number 9 is dailed
      MyMessage msgDail_10(chuildIdDail_10,V_STATUS);  // message container used when the number 0 is dailed
      
      void setup()  
      {  
      //##### I/O pin function setup #####
        pinMode(button,INPUT);    //set the already defined I/O pin as input
        pinMode(edail, INPUT);    //set the already defined I/O pin as input
        pinMode(pdail, INPUT);    //set the already defined I/O pin as input
        pinMode(lbell, OUTPUT);   //set the already defined I/O pin as output
        pinMode(rbell, OUTPUT);   //set the already defined I/O pin as output
       
      // ##### Debouncer setup #####
        debouncerButton.attach(button);
        debouncerButton.interval(5);
        debouncerEdail.attach(edail);
        debouncerEdail.interval(5);
        debouncerPdail.attach(pdail);
        debouncerPdail.interval(5);
      }
      
      // ##### Function of MySensors that presents all attached sensors to the controller #####
      void presentation() { 
        sendSketchInfo(ProjectName, ProjectVersion);   // Send the sketch version information to the gateway and Controller
        present(childIdDoor, S_BINARY);                // Present doorbell button as binary switch
        present(chuildIdDail_1, S_BINARY);             // Present the dailing of number 1 as binary switch
        present(chuildIdDail_2, S_BINARY);             // Present the dailing of number 2 as binary switch
        present(chuildIdDail_3, S_BINARY);             // Present the dailing of number 3 as binary switch
        present(chuildIdDail_4, S_BINARY);             // Present the dailing of number 4 as binary switch
        present(chuildIdDail_5, S_BINARY);             // Present the dailing of number 5 as binary switch
        present(chuildIdDail_6, S_BINARY);             // Present the dailing of number 6 as binary switch
        present(chuildIdDail_7, S_BINARY);             // Present the dailing of number 7 as binary switch
        present(chuildIdDail_8, S_BINARY);             // Present the dailing of number 8 as binary switch
        present(chuildIdDail_9, S_BINARY);             // Present the dailing of number 9 as binary switch
        present(chuildIdDail_10, S_BINARY);            // Present the dailing of number 0 as binary switch
      }
      
      void loop() {
      // ##### debouncer updater ##### 
        debouncerButton.update();                      // Update debouncer for doorbell button
        valueButton = debouncerButton.read();          // Set current value of doorbell button 
        debouncerEdail.update();                       // Update debouncer for enable dail
        valueEdail = debouncerEdail.read();            // Set current value of enable dail
        debouncerPdail.update();                       // Update debouncer for pulse dail 
        valuePdail = debouncerPdail.read();            // Set current value of pulse dail
      
      // ##### Mysensors code to check doorbell button and sent message ##### 
        if (valueButton != oldValueButton) {                       // Check if the value of the button has changed 
           send(msgDoor.set(valueButton==HIGH ? 1 : 0));           // Transmit the new value
           oldValueButton = valueButton;                           // Change old value so this doenst loop
        }
      
      // ##### Mysensors code to read dail counter and sent message as one individual sensor #####
        switch (newDailCount) {         // Check the current vallue of the completed counter
           case 1:                      // if value is equal to 1 
             send(msgDail_1.set(1));    // Transmit ON message for dail switch 1 
             send(msgDail_1.set(0));    // Transmit OFF message for dail switch 1. Some home automation software prefers this.
             break;                     // end of case
           case 2:                      // if value is equal to 2 
             send(msgDail_2.set(1));    // Transmit ON message for dail switch 2
             send(msgDail_2.set(0));    // Transmit OFF message for dail switch 2. Some home automation software prefers this.
             break;                     // end of case
           case 3:                      // if value is equal to 3 
             send(msgDail_3.set(1));    // Transmit ON message for dail switch 3
             send(msgDail_3.set(0));    // Transmit OFF message for dail switch 3. Some home automation software prefers this.
             break;                     // end of case
           case 4:                      // if value is equal to 4 
             send(msgDail_4.set(1));    // Transmit ON message for dail switch 4 
             send(msgDail_4.set(0));    // Transmit OFF message for dail switch 4. Some home automation software prefers this.
             break;                     // end of case
           case 5:                      // if value is equal to 5 
             send(msgDail_5.set(1));    // Transmit ON message for dail switch 5 
             send(msgDail_5.set(0));    // Transmit OFF message for dail switch 5. Some home automation software prefers this.
             break;                     // end of case
           case 6:                      // if value is equal to 6 
             send(msgDail_6.set(1));    // Transmit ON message for dail switch 6 
             send(msgDail_6.set(0));    // Transmit OFF message for dail switch 6. Some home automation software prefers this.
             break;                     // end of case       
           case 7:                      // if value is equal to 7 
             send(msgDail_7.set(1));    // Transmit ON message for dail switch 7 
             send(msgDail_7.set(0));    // Transmit OFF message for dail switch 7. Some home automation software prefers this.
             break;                     // end of case       
           case 8:                      // if value is equal to 8 
             send(msgDail_8.set(1));    // Transmit ON message for dail switch 8 
             send(msgDail_8.set(0));    // Transmit OFF message for dail switch 8. Some home automation software prefers this.
             break;                     // end of case       
           case 9:                      // if value is equal to 9 
             send(msgDail_9.set(1));    // Transmit ON message for dail switch 9 
             send(msgDail_9.set(0));    // Transmit OFF message for dail switch 9. Some home automation software prefers this.
             break;                     // end of case       
           case 10:                     // if value is equal to 10 
             send(msgDail_10.set(1));    // Transmit ON message for dail switch 10 
             send(msgDail_10.set(0));    // Transmit OFF message for dail switch 10. Some home automation software prefers this.
             break;                     // end of case       
        }
        newDailCount = 0;                // Reset the completed counter so this doesnt loop
      
        
      // ###### Code for checking enable dail and sending state trough serial  ######  
        if (valueEdail != oldValueEdail && valueEdail == HIGH) {          // Check if enable dail has changed AND if its currently its currently activated
           Serial.println("dail is activated...");                        // If so sent message 
           oldValueEdail = valueEdail;}                                   // And change old value so this doenst loop
           else if (valueEdail != oldValueEdail && valueEdail == LOW) {   // Check if enable dail has changed AND if its currently its currently deactivated
           Serial.println("dail is deactivated...");                      // If so sent message
           newDailCount = dailCount;                                       // Write the counted pulses to the New Dail Count
           dailCount = 0;                                                 // Reset the dail count for next dail 
           oldValueEdail = valueEdail;                                    // And change old value so this doenst loop
        }
      
      // ###### Code for checking pusle dail and sending state trough serial ######
        if (valuePdail != oldValuePdail && valueEdail == HIGH) {          // Check if dail pulse has changed AND if currently its currently activated
           if (valuePdail == LOW) {                                       // Only take action when the signal goes from high to low to prevent double count
             dailCount++;                                                 // If the conditions are met increase counter by 1
             Serial.print("Tick! Total ammout of pulses: ");              // Serial print a messagge saying a pulse was detected
             Serial.println (dailCount);                                  // Serial print a the current value of the counter
           }
             oldValuePdail = valuePdail;                                  // Change old value so this doenst loop  
        }
       
        if (valueButton == HIGH) {                // If the boorbell button was pressed (read from debouncer)
           while (repeat < repeatX){              // start a loop if the number of repeats isnt reached yet (a repeat is the time a bell is ringed pauesed)
              repeat++;                           // add 1 count to the "repeat" counter
              while (ring < ringX){               // start a loop if the number of rings isnt reached yet (a ring is the hammer hitting each bell once)
                 ring++;                          // add 1 count to the "ring" counter
                 digitalWrite(lbell, HIGH);       // power the bell coil so that the hammer hits the left bell  !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 wait(onPulse);                   // hold for the amount of ms set for "onPulse"                !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 digitalWrite(lbell, LOW);        // power down the bell coil                                   !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 wait(offPulse);                  // wait for the amount of ms set for "offpulse"               !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 digitalWrite(rbell, HIGH);       // power the bell coil so that the hammer hits the right bell !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 wait(onPulse);                   // hold for the amount of ms set for "onPulse"                !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 digitalWrite(rbell, LOW);        // power down the bell coil                                   !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
                 wait(offPulse);                  // wait for the amount of ms set for "offpulse"               !!! VERY IMPORTANT: "LBELL" AND "RBELL" CAN NEVER BE HIGH AT THE SAME TIME !!!
              }                                   // go back to start if loop till "ring" has the same value as "ringX"
              wait (ringPause);                   // wait for the amount of ms set for "ringPause"
                 if (ring == ringX){              // if the amount of "ring" is the same as the amount set in "ringX"....
                    ring = 0;                     // reset the "ring" counter
                    }
               }
           }  
                    
        if (repeat == repeatX){                   // if the amount of "repeat" is the same as the amount set in "repeatX"....
           repeat = 0;                            // reset the "repeat" counter
           } 
      }
      
      posted in Development
      SuperKris
      SuperKris
    • Virtual switches that never go off and controllers

      For a project i'm working on i have converted a old 1950's phone into a doorbell/multiple switches.

      If i dail 3, for example it does a "send(msgDail_1.set(1));" This message is set up as S_BINARY and V_STATUS.

      In my experience some home automation software like Domotics doesnt like this very much as the switch never switches off. A simple solution can be to send a off command directly after the on command. This seems to be working most of the time, but sometime it seems a bit random. Maybe because the status is only high for a very low time.

      A normal switch would always have 2 states, or be pressed for several 100ms.

      A solution can be to add a "wait" for maybe 500ms. However i found that the "wait" function actually stops the Arduino from receiving input. Most of the time that wont be a problem, but i would like to get it working the right way. Both the send and wait function are in a "switch case" if it makes ant difference.

      Do you guys recognize this problem? How have you solved this?

      posted in Development
      SuperKris
      SuperKris
    • RE: What are the best settings for MY_RF24_PA_LEVEL?

      I have a node that is not working perfectly. I'm not sure about the reception problem, but it doesnt help its in a thick aluminium housing. I'll try some foil on the radio of the gateway!

      posted in Troubleshooting
      SuperKris
      SuperKris
    • RE: What are the best settings for MY_RF24_PA_LEVEL?

      @rejoe2 said in What are the best settings for MY_RF24_PA_LEVEL?:

      Hi SuperKris,

      most likely, there is not a definite answer to your questions.

      First a very good point for a lot of info around the nrf's: https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

      Thanks for the link, there was some useful information there

      I personally got best results using the PA+LNA-Versions and additional base modules, power sourced through 5V with PA-Level set to max.

      This is the standard-level which is used as long as there is no explicitely defined other level. This is the standard mechanism using the myconfig.h settings. Keep eyes open, as this is defined to LOW e.g. in the GW-Sketch...

      One of the reasons i started asking about this that it was defined to LOW in the default gateway sketch. I started to google on these settings and found a couple of topics where they advise to lower MY_RF24_PA_LEVEL. This made me even more unsure about selecting the right voltage level.

      MAX will also work with the non PA+LNA-Boards, but keep in mind using this setting also means higher power consumption, so soucing the NRF through Arduino's 3.3V-PIN might not work.

      I always use a e-cap on every PSU. For this the radio i often use 47u, and a 470-1000u on the arduino 5V. Also always a 50n in parallel as close to the chip as possible. I dont use a extra regulator board, but i use arduino's with a strong 3V3 PSU. I love the one's by Robotdyn. They have a AMS117 (SOT223 size i think?). They specify the 3V3 at 350mA. I have not tested this, but the AMS117 should be good for 1A if it can cool enough, so i expect it to be able to deliver plenty of power.

      @rejoe2 said in What are the best settings for MY_RF24_PA_LEVEL?:

      @LastSamurai
      According to my personal experience I would answer with a clear yes! The +PA+LNA-Version gets better receiving results and generates a stronger signal when sending. So -apart form adding a capacitor- changing the module on the GW imo is also an action to recommend to improve the overall results. You may in addition think about shielding both decoder chips (not the antennas).

      Does shielding actually improve results? This is interesting to me. how should one proceed with this? First warping it in plastic, and next in aluminium foil? Should the shield be connected to the ground pin, or maybe even to the shell of the USB?

      posted in Troubleshooting
      SuperKris
      SuperKris
    • RE: What are the best settings for MY_RF24_PA_LEVEL?

      Anyone? Or am i asking stupid questions again? πŸ˜•

      posted in Troubleshooting
      SuperKris
      SuperKris
    • What are the best settings for MY_RF24_PA_LEVEL?

      I spent some time googeling the best value's for MY_RF24_PA_LEVEL, but i could not find a definitive answer. I hope my questions are not very stupid, but i would like to understand the type of radio and its settings better.

      First i would like to know which NRF24L01 are the best. From what i have read, the NRF24L01 + PA + LNA has a build in amplifier and is therefore more powerful. Usually these have a external antenna mounted by a SMA connector. The normal NRF24L01+ have a PCB antenna.

      For a gateway i would guess the NRF24L01 + PA + LNA would always be the best choice right? Same for a repeating node i would guess... Off course this is amusing power consumption, costs of the more expensive NRF24L01 + PA + LNA radio, and the lager size are no problem. Or am i missing something here?

      Considering range. The best combination is always NRF24L01 + PA + LNA for both nodes if i understand right. For some node's i prefer the smaller, cheaper, and less power hungry NRF24L01+. Does using a NRF24L01+PA+LNA as a gateway to communicate with the NRF24L01+ offer any improved performance over using a NRF24L01+ for both the gateways and the node?

      Will MY_RF24_PA_LEVEL work on both the NRF24L01+ and NRF24L01+PA+LNA, or will it only work on the NRF24L01+PA+LNA?

      From reading the library API i understand the default value is RF24_PA_MAX. I'm a bit of a noob with Arduino, so i'm not sure how this works. If i make a sketch without manually adding MY_RF24_PA_LEVEL, will the library set it to RF24_PA_MAX automatically?

      So what is the generally the best value for the MY_RF24_PA_LEVEL when used with a NRF24L01+PA+LNA on a gateway? A lower power will obviously mean less range. But i can imagine a very high power can sometime also cause problems. So is there a sweet sport for a average configuration when the gateway is inside of a regular house where all sensors are in a max 20m range (with walls) and the furthest sensor is maybe 30-40m away?

      posted in Troubleshooting
      SuperKris
      SuperKris
    • RE: NRF24L01 radio problems. (Bermuda triangle shit)

      I for sure learned to double check any print terminal i take out of sample boxes. Damn...

      The 230V part of the board has a 5.08mm pitch for all lanes. I cut out the PCB pads and via's of the experimental board on both sided for insulation. The decoupling for 5V was done with 470u and 100n as close as possible to the Arduino. Same for the radio with 47u and 100n.

      There is only 1 real way to do this. Same goes for all the other connections. There are no other components in there. Except for the psu output and the radio voltage i cant think of anything that causes the issue with the radios.

      posted in Hardware
      SuperKris
      SuperKris
    • NRF24L01 radio problems. (Bermuda triangle shit)

      I was had a horrible project with a design that i build for "smart lamp" The idea was simple. Build a standard PCB that can be build into a standard light housing that can control the light, can read the output of a PIR, and sent temp/hum data. This is what i made:

      0_1482849340625_upload-7061811c-3893-4c2c-8303-33d6718a64dc

      • Robotdyn Arduino nano clone (i love these)
      • HiLink PSU
      • NRF24L01+
      • Omron solid state

      It was working great until i tried 230V. The lamp would not turn on. After a few seconds a big flash killed the solid stat and the fuse in front of it. I had NO idea on what could be wrong here. Checked everything 10 times, placed a new solid state and fuse, and tried again. The same thing happened and i had no clue what was wrong. The lesson i learned eventually is that you should never take print terminals from a sample box without checking. the terminals for the output where internally fused together by design πŸ˜•. Meanwhile i was out of solid states but i had learned that the solid stat was not compatible with my LED bulb anyway because it needed a 100mA current to be able to switch of. My 3W led light did not supply such current. What a nightmare... The simple solution was to add a relay module so that problem was fixed. The module preformed without any problems now.

      On to the real issue...

      Next i installed the light outside. All the electronics where build in the base of the lamp which was plastic only. I used hot glue to fuse the electronics to the housing. (the glue is non conductive). Before screwing on the rest of the lamp (aluminium) i tested it again, but the module would not respond to Domoticz.

      The LED's on the arduino would behave strangely. The on LED would turn solid. Another LED started blinking, slowly. After a couple of seconds it stopt blinking, and stated again. Next the cycle repeated and repeated. I'm not used to this. Usually 1 led is always on, and the other blinks so fast it looks like a dimmed led. I do not understand a lot of the communication between the arduino and the radio, but i'm guessing the "dimmed" light must be the radio doing its job.

      The arduino is powered by the Hi-Link module. Its powering the 5V pin of the Arduino and is decoupled with 470uF and 100nF. The radio is connected the the 3.3V output of the arduino. Its also decoupled with 47uF and 100nF. I measured the DC voltage on both 5V and 3.3V, and its nominal. I also measured AC, and my cheap ass DMM gives a very small AC ripple on the 5VDC. I have no idea of the actual ripple as my cheap ass DMM is probably not fast enough. I do not expect there to be a actual noticeable AC ripple tho.

      That said, I could not get my creation to work. I switched the arduino, i switched to a different brand of arduino, i switched radio's, etc. In the end i got it working with this radio module. The kind of arduino didn't matter.

      I also experimented by putting the radio's in another in another Mysensors board, with the same arduino's. The same thing happened with almost all radio's. A serial print showed that the radio failed almost every time. I tried about 4 different boards without external antenna, and 3 with antenna. This one (from now on called straight antenna) and this one (from now on called angled antenna). I even took some radios out of older mysensors projects that i know where working fine.

      It seems like my build destroyed every radio except for the one with the straight external antenna. I have NO IDEA what could have caused this, but it looks like i now have a bunch of dead radio's. I'm not sure how to test this.

      Do you guys have any idea's on how this could have happened and how i should proceed in the future?

      posted in Hardware
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @Boots33 said:

      @SuperKris Yes sleep will power down your node so should not be used for nodes that are expecting to receive messages or are set up as a repeater. Have a look at this thread for the basic non blocking delay code.

      Thanks. That is just what i was looking for, but i want not able to find it trough the search funtion!

      There is just 1 thing i still dont understand about the sleep function. In the latest version of my sketch i use a sleep time of 5 seconds. If the arduino fully stops processing code while in sleep, i would not think it would be able to receive messages from the controller.

      But i have no problem receiving messages from the controller. If i press a lightswitch in Domoticz the relay on the arduino switches without any noticeable delay. This should not be possible right? How is this possible?

      @tboha said:

      • sleep() stops all code. You should not use it in this environment.
      • the receive() is declared outside loop() but runs inside loop(). This is done automatically by MySensors framework.

      Thanks! I guess i still dont fully understand the whole structure of a arduino sketch. I see why sleep() would stop the keypad from working properly, but i dont really understand why receive() seems to be not affected by this.

      • you are right to disable sleep(), but .... the DHT Sensor is not as fast as your Arduino.

      I think i understand why i'm getting the errors from the DHT code. I'm just wondering if it would slow down other functions of the arduino, or the controller.

      So as you expected, it boils down to enclose the DHT code into an millis() controlled if-Statement.

      Basically it looks like this

      static const uint64_t UPDATE_INTERVAL = 60000;
      static const uint64_t MEASURING_INTERVAL = 30000;
      
      // before setup() aka global variables
      unsigned long last_time = 0, actual_time = 0;
      ----------
      
      // within loop()
        if ( (millis() - last_time) >= MEASURING_INTERVAL) {   
          last_time = millis();
          // Force reading sensor, so it works also after sleep()
          dht.readSensor(true);
      // rest of your DHT Code here
      
      }   // donΒ΄t forget closing parenthesis (after Humidity is done)
      

      you will recognize the fragments, they originate form the DHT Example Sketch.

      Thank, i'll try to work this within my sketch. It just seems a little hard because the DHT code is relatively complex compared to the other code i used in this sketch. I'm to much of a noob to understand if i can just copy the whole loop part into the if function with the millis.

      I'll try adding the millis code tonight!

      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      Ok, next problem. I saw this one coming, but i cant figure it out by myself...

      I added the DHT code for the temperature and humidity. I took the sketch that under the build section as example. It does compile and work, but the sleep in the sketch is a issue. I was surprised to find the sketch was still responding to messages from the gateway. Maybe i'm understanding sleep wrong, so that is my first question.

      1. Does sleep stop all code from running, or just the function that its in? In other words; My keypad code is in the loop function. The mysensor code for receiving messages is in another funtion outside the loop function (void receive). Does a sleep in the loop function also blocks void receive, or does it only block the loop part?

      So both my keypad code and the DHT code are in the loop part of the sketch. This makes the keypad unresponsive. If i understand right this is caused because the code is sleeping most of the time. If i keep pressing the button until it wakes up for a a fraction of a second the key is registered.

      So the easy way would be to disable sleep right.... I do not need to save any batteries, and i want the whole node to be as responsive as possible. Disabling the sleep function (with just a // ) seems to work, but its flooding (debug still enabled off course) the serial monitor "with Failed reading temperature from DHT! Failed reading humidity from DHT"

      1. So i guess this is just because of the way the DHT works, but i fear this may be slowing down the whole sketch and making the node less responsive. Is it a bad idea to just skip the sleep and keep the rest the same?

      From what i learned from earlier experiments where i needed to time things but still needed it to be responsive to other input, i think the only solution is the millis function. I think such a function could be applied to only run the DHT code every 5 seconds. Unfortunately i'm way to much of a noob, and the DHT code is way to advanced to replace the sleep function with a millis function.

      1. Can anyone help me on my wat to replace the sleep funtion with the millies code?

      My current code (its getting pretty big now) can be found below:

      
      
      
      // ##### SET PROJECT NAME AND VERSION #####
      #define ProjectName "Shed Controller" // Name that is vissible in controller
      #define ProjectVersion "0,3"          // Version that is vissible in controller
      //#define MY_NODE_ID 10               // Manual Node ID.
      
      // ##### SET MYSENSOR SETTINGS BEFORE INCLUDIGN LIBRARY #####
      #define MY_DEBUG            // Enable debug prints to serial monitor
      // #define MY_DISABLED_SERIAL  // Disable serial monitor so pins 0 and 1 can be used for the keypad. Disable this line with comment to use serial monitor so debug code works
      #define MY_RADIO_NRF24      // Enable and select radio type attached
      #define MY_REPEATER_FEATURE // Enabled repeater feature for this node
      
      // ##### INCLUDE LIBRARYS #####
      #include <SPI.h>
      #include <MySensors.h>
      #include <Keypad.h>
      #include <DHT.h>
      
      
      
      // ##### DEFINE I/O PINS #####
      //#define IoPin1 4  // Arduino Digital I/O pin number for I/O 1 
      #define IoPin2 3  // Arduino Digital I/O pin number for I/O 2 
      #define IoPin3 6  // Arduino Digital I/O pin number for I/O 3 
      #define IoPin4 5  // Arduino Digital I/O pin number for I/O 4 
      #define IoPin5 8  // Arduino Digital I/O pin number for I/O 5
      #define IoPin6 7  // Arduino Digital I/O pin number for I/O 6
      #define IoPin7 19 // Arduino Digital I/O pin number for I/O 7
      
      // ##### DEFINE CHILD ID'S #####
      #define CHILD_ID1 1     // ID for child 1 (I/O)
      #define CHILD_ID2 2     // ID for child 2 (I/O) used for relay
      //#define CHILD_ID4 4   // ID for child 4 (I/O)
      #define CHILD_ID5 5     // ID for child 5 (I/O) used for relay
      #define CHILD_ID6 6     // ID for child 6 (I/O) used for relay
      #define CHILD_ID7 7     // ID for child 7 (I/O) used for relay
      
      #define CHILD_ID_V1 10    // ID for child virtual switch 1. Used for Outside lighting button
      #define CHILD_ID_V2 11    // ID for child virtual switch 2. Used for Heater button
      #define CHILD_ID_V3 12    // ID for child virtual switch 3. Used for Anti Frost button
      #define CHILD_ID_V4 13    // ID for child virtual switch 4. Used for Party Lights button
      #define CHILD_ID_V5 14    // ID for child virtual switch 5. Used for Wifi AP button
      #define CHILD_ID_V6 15    // ID for child virtual switch 6. Used for Aux 1 button
      #define CHILD_ID_V7 16    // ID for child virtual switch 7. Used for Aux 2 button
      #define CHILD_ID_V8 17    // ID for child virtual switch 8. Used for 5 min button
      #define CHILD_ID_TEMP1 30 // ID for child 8 (I/O) used for humidity
      #define CHILD_ID_HUM1 31  // ID for child 3 (I/O) used for temperature
      
      // ##### TEMPERATURE SENSOR SETTINGS #####
      #define SENSOR_TEMP_OFFSET 0 // Offset for temperatur sensor can be set here
      static const uint64_t UPDATE_INTERVAL = 10000;
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      DHT dht;
      
      // ##### RELAY SETTING #####
      #define RELAY_ON 0          // Invert for some relay modules (currently inverted)
      #define RELAY_OFF 1         // Invert for some relay modules (currently inverted)
      
      // ##### OTHER VARIABLES #####
      bool state; // Not realy sure what this exatly does. I guess temporary storage of received messages and loading from EEPROM
      
      // ##### BOOLEANS FOR VIRTUAL SWITCHES #####
      bool VirtalSwitch1;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch2;  // Boolean (status) for virtual switch 2 (controlled by keypad)
      bool VirtalSwitch3;  // Boolean (status) for virtual switch 3 (controlled by keypad)
      bool VirtalSwitch4;  // Boolean (status) for virtual switch 4 (controlled by keypad)
      bool VirtalSwitch5;  // Boolean (status) for virtual switch 5 (controlled by keypad)
      bool VirtalSwitch6;  // Boolean (status) for virtual switch 6 (controlled by keypad)
      bool VirtalSwitch7;  // Boolean (status) for virtual switch 7 (controlled by keypad)
      
      // ##### DEFINE MYSENSORS MESSAGE CONTAINERS TO COMMUNICATE WITH GATEWAY #####
      MyMessage msgTemp(CHILD_ID_TEMP1, V_TEMP); // msgTemp sends child ID CHILD_ID_TEMP1 as V_TEMP
      MyMessage msgHum(CHILD_ID_HUM1, V_HUM);    // msgHum sends child ID CHILD_ID_HUM1 as V_HUM
      MyMessage msgV1(CHILD_ID_V1,S_LIGHT);      // msgV1 sends child ID CHILD_ID_V1 as S_LIGHT
      MyMessage msgV2(CHILD_ID_V2,S_LIGHT);      // msgV2 sends child ID CHILD_ID_V2 as S_LIGHT
      MyMessage msgV3(CHILD_ID_V3,S_LIGHT);      // msgV3 sends child ID CHILD_ID_V3 as S_LIGHT
      MyMessage msgV4(CHILD_ID_V4,S_LIGHT);      // msgV4 sends child ID CHILD_ID_V4 as S_LIGHT
      MyMessage msgV5(CHILD_ID_V5,S_LIGHT);      // msgV5 sends child ID CHILD_ID_V5 as S_LIGHT
      MyMessage msgV6(CHILD_ID_V6,S_LIGHT);      // msgV6 sends child ID CHILD_ID_V6 as S_LIGHT
      MyMessage msgV7(CHILD_ID_V7,S_LIGHT);      // msgV7 sends child ID CHILD_ID_V7 as S_LIGHT
      MyMessage msgV8(CHILD_ID_V8,S_LIGHT);      // msgV8 sends child ID CHILD_ID_V8 as S_LIGHT
      
      // ##### KEYPAD SETUP #####
      const byte ROWS = 4; // Just settings for keypad library. Enter number of rows here
      const byte COLS = 3; // Just settings for keypad library. Enter number of columns here
      // Nameing of very key on the keypad. The output of keypad code will be the charaters used here.
      char keys[ROWS][COLS] = {
        {'1', '2', '3'},
        {'4', '5', '6'},
        {'7', '8', '9'},
        {'A', 'B', 'C'}
      };
      byte rowPins[ROWS] = { A0, A1, A2, A3 }; // The pins the row wires are connected to (from left to right)
      byte colPins[COLS] = { A4, 1, 0 };       // The pins the column wires are connected to (from top to bottom)
      Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // This creates the actual keypad based on specs above.
      
      
      void setup()  
      {  
        // ##### I/O SETUP FOR PHYSICAL I/O ON ARDUINO #####
        // Setup I/O 2
        pinMode(IoPin2, OUTPUT);                        // use I/O 2 as output for relay module
        digitalWrite(IoPin2, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID2);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF); // write last know state
      
      
      
      
        // Setup I/O 3
        dht.setup(IoPin3); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
      
      
      
      
        // Setup I/O 4                                     Not in use  
        // pinMode(IoPin4, OUTPUT);                        // use I/O 4 as output for relay module
        // digitalWrite(IoPin4, RELAY_OFF);                // and set switch relay output off
        // state = loadState(CHILD_ID4);                   // Load last known state (using eeprom storage) 
        // digitalWrite(IoPin4, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 5
        pinMode(IoPin5, OUTPUT);                        // use I/O 5 as output for relay module
        digitalWrite(IoPin5, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID5);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 6
        pinMode(IoPin6, OUTPUT);                        // use I/O 6 as output for relay module
        digitalWrite(IoPin6, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID6);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 7
        pinMode(IoPin7, OUTPUT);                        // use I/O 7 as output for relay module
        digitalWrite(IoPin7, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID7);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF); // write last know state
      
      
      
      
      
       // ----- PIN SETUP (FOR TESTING ONLY -----
       // pinMode(IoPin4, OUTPUT);   //use I/O 4 as output for relay module
       // digitalWrite(IoPin4, HIGH);//   and set is HIGH so relay stays off
        
      }
      
      // ###### PRESENT ALL ATTACHED SENSORS TO CONTROLLER ######
      void presentation(){
        
        // ----- Sent sketch info -----
        sendSketchInfo(ProjectName, ProjectVersion); // Send the sketch version information to the gateway and Controller
        
        // ----- Physical I/O child IDs -----
        //present(CHILD_ID1, XXXXXXX); //Register child ID 1 as NONE
        present(CHILD_ID2, S_LIGHT, "Outside lighting relay"); //Register CHILD_ID2 as S_LIGHT, and sent name to controller.
        //present(CHILD_ID4, XXXXXXX); //Register child ID 4 as NONE
        present(CHILD_ID5, S_LIGHT, "Switched outlet heater"); //Register CHILD_ID5 as S_LIGHT, and sent name to controller.
        present(CHILD_ID6, S_LIGHT, "Sw outlet party lights"); //Register CHILD_ID6 as S_LIGHT, and sent name to controller.
        present(CHILD_ID7, S_LIGHT, "Gate light relay");       //Register CHILD_ID7 as S_LIGHT, and sent name to controller.
        // ----- virtual switch child ID (keypad)
        
        present(CHILD_ID_V1, S_LIGHT, "Outside light switch"); //Register CHILD_ID_V1 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V2, S_LIGHT, "Shed heater");          //Register CHILD_ID_V2 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V3, S_LIGHT, "Anti frost mode");      //Register CHILD_ID_V3 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V4, S_LIGHT, "Party lights");         //Register CHILD_ID_V4 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V5, S_LIGHT, "Wifi AP");              //Register CHILD_ID_V5 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V6, S_LIGHT, "Aux 1");                //Register CHILD_ID_V6 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V7, S_LIGHT, "Aux 2");                //Register CHILD_ID_V7 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V8, S_LIGHT, "5 min. button");        //Register CHILD_ID_V8 as S_LIGHT, and sent name to controller
       
        // ----- Sensor child ID's -----
        present(CHILD_ID_TEMP1, S_TEMP, "Temp shed Inside");   //Register CHILD_ID_TEMP1 as S_TEMP, and sent name to controller
        present(CHILD_ID_HUM1, S_HUM, "Hum. shed Indide");     //Register CHILD_ID_HUM1 as S_HUM, and sent name to controller
      
        // ----- Aditional presentation setting -----
        metric = getConfig().isMetric;  //Not sure what this does, Its needed for DHT sensor
      } 
      
      void loop()
      { // ##### KEYPAD CODE TO SET A ACTION FOR A PRESSED KEY #####
        char key = kpd.getKey();       // Get key from keypad (if pressed)
        if (key)  {                    // compare key (defined in keypad setup)
          switch (key) {               // with multiple multiple options below
      
                                  // On button for outside light
            case '1':                  // If the pressed key compares with "1"
              VirtalSwitch1 = true;    // Change te state of boolean VirtalSwitch1 to true (on)
              send(msgV1.set(1));      // Sent "on" command to gateway for CHILD_ID_V1 
              Serial.println("KEY 1"); // Debug code. Print "KEY 1" to show that button 1 was pressed
              break;                   // End of code for button 1
      
                                  // Off button for outside light
            case '2':                  // If the pressed key compares with "2"
              VirtalSwitch1 = false;   // Change te state of boolean VirtalSwitch1 to false (off)
              send(msgV1.set(0));      // Sent "off" command to gateway for CHILD_ID_V1 
              Serial.println("KEY 2"); // Debug code. Print "KEY 2" to show that button 2 was pressed
              break;                   // End of code for button 2
      
                                  // 5 minute button
            case '3':                  // If the pressed key compares with "3"
              send(msgV8.set(1));      // Sent "on" command to gateway for CHILD_ID_V8
              Serial.println("KEY 4"); // Debug code. Print "KEY 4" to show that button 4 was pressed
              break;                   // End of code for button 4
      
                                  // On button for heating
            case '4':                  // If the pressed key compares with "4"
              VirtalSwitch2 = true;    // Change te state of boolean VirtalSwitch2 to true (on). This is the heater
              VirtalSwitch3 = false;   // Change te state of boolean VirtalSwitch3 to false (off). This is the anti frost funtion
              send(msgV2.set(1));      // Sent "on" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(0));      // Sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 4"); // Debug code. Print "KEY 4" to show that button 4 was pressed
              break;                   // End of code for button 4
      
                                  // Off button for heating
            case '5':                  // If the pressed key compares with "5"
              VirtalSwitch2 = false;   // Change te state of boolean VirtalSwitch2 to false (off). This is the heater
              VirtalSwitch3 = false;   // Change te state of boolean VirtalSwitch3 to false (off). This is the anti frost funtion
              send(msgV2.set(0));      // Sent "off" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(0));      // Sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 5"); // Debug code. Print "KEY 5" to show that button 5 was pressed
              break;                   // End of code for button 5
      
                                  // On button for anti frost
            case '6':                  // If the pressed key compares with "6"
              VirtalSwitch2 = false;   // Change te state of boolean VirtalSwitch2 to false (off). This is the heater
              VirtalSwitch3 = true;    // Change te state of boolean VirtalSwitch3 to true (on). This is the anti frost funtion
              send(msgV2.set(0));      // Sent "off" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(1));      // Sent "on" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 6"); // Debug code. Print "KEY 6" to show that button 6 was pressed
              break;                   // End of code for button 6
              
                                  // On button for party lights
            case '7':                  // If the pressed key compares with "7"
              VirtalSwitch4 = true;    // Change te state of boolean VirtalSwitch1 to true (on)
              send(msgV4.set(1));      // Sent "on" command to gateway for CHILD_ID_V4 
              Serial.println("KEY 7"); // Debug code. Print "KEY 7" to show that button 7 was pressed
              break;                   // End of code for button 7
      
                                  // Off button for party lights
            case '8':                  // If the pressed key compares with "8"
              VirtalSwitch4 = false;   // Change te state of boolean VirtalSwitch1 to false (off)
              send(msgV4.set(0));      // Sent "off" command to gateway for CHILD_ID_V4 
              Serial.println("KEY 8"); // Debug code. Print "KEY 8" to show that button 8 was pressed
              break;                   // End of code for button 8
      
                                      // Aux ON/OFF buton 1
            case '9':{                     // If the pressed key compares with "9"
              if (VirtalSwitch6 == false){ // check if the virtual switch (VirtalSwitch6) is OFF. If so, do the following
                VirtalSwitch6 = true;      // set the new status of the virtual swich to ON
                send(msgV6.set(1));        // Sent "on" command to gateway for CHILD_ID_V6 
              }
              else {                       // If the virtual switch was not OFF, it must have been ON, so do the following 
                VirtalSwitch6 = false;     // set the new status of the virtual swich to OFF
                send(msgV6.set(0));        // Sent "off" command to gateway for CHILD_ID_V6 
                }
              }
              Serial.println("KEY 9");    // Debug code. Print "KEY 9" to show that button 9 was pressed
              break;                      // End of code for button 9
      
                                   // On button for Wifi AP
            case 'A':                  // If the pressed key compares with "A"
              VirtalSwitch5 = true;    // Change te state of boolean VirtalSwitch5 to true (on)
              send(msgV5.set(1));      // Sent "on" command to gateway for CHILD_ID_V5 
              Serial.println("KEY A"); // Debug code. Print "KEY A" to show that button A was pressed
              break;                   // End of code for button A
      
                                   // Off button for Wifi AP
            case 'B':                  // If the pressed key compares with "B"
              VirtalSwitch5 = false;   // Change te state of boolean VirtalSwitch5 to false (off)
              send(msgV5.set(0));      // Sent "off" command to gateway for CHILD_ID_V5 
              Serial.println("KEY B"); // Debug code. Print "KEY B" to show that button B was pressed
              break;                   // End of code for button B    
      
                                    // Aux ON/OFF buton 2
            case 'C':{                     // If the pressed key compares with "C"
              if (VirtalSwitch7 == false){ // check if the virtual switch (VirtalSwitch7) is OFF. If so, do the following
                VirtalSwitch7 = true;      // set the new status of the virtual swich to ON
                send(msgV7.set(1));        // Sent "on" command to gateway for CHILD_ID_V7 
              }
              else {                       // If the virtual switch was not OFF, it must have been ON, so do the following 
                VirtalSwitch7 = false;     // set the new status of the virtual swich to OFF
                send(msgV7.set(0));        // Sent "off" command to gateway for CHILD_ID_V7 
                }
              }
              Serial.println("KEY C");    // Debug code. Print "KEY C" to show that button C was pressed
              break;                      // End of code for button C
              
            default:                  // If the pressed key does not match the cases above
              Serial.print(key);      // Print the key that was pressed
              Serial.println(" was pressed but not recognized by the keypadcode. Something is wrong!"); // print warning
              break;                  // End of function
          }
        }  
      
      
      
      // Force reading sensor, so it works also after sleep()
        dht.readSensor(true);
      
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
          #ifdef MY_DEBUG
          Serial.print("T: ");
          Serial.println(temperature);
          #endif
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
      
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
        } else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
        // Sleep for a while to save energy
        //sleep(UPDATE_INTERVAL); 
      
      
      
      
      }
      
      // ##### CODE FOR RECEIVING MYSENSORS MESSAGES FROM CONTROLLER #####
      void receive(const MyMessage &message) {                         //start mysensor receiving code
        if (message.isAck()) {                                         //Check for gateway acknowledgment
           Serial.println("This is an ack from gateway");              //Print debug code (serial print) to confirm received ack
        }
        // ----- Relay actors -----
        // ----- Action taken for child ID 1: Currently set as V_LIGHT to switch relay on IoPin1 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID2) {  //if message is V_LIGHT and the child ID is 2 
           state = message.getBool();                                  //guess this write the incomming boolean to state?
           digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF);             //change the the arduino pin from "on" to "off" or other way around
           saveState(CHILD_ID2, state);                                //guess this saves the state if child ID 2 to EEPPROM
           Serial.print("Incoming change for sensor:");                //debug info text
           Serial.print(message.sensor);                               //write received child ID
           Serial.print(", New status: ");                             //debug info text
           Serial.println(message.getBool());                          //write received boolean
         } 
        // ----- Action taken for child ID 5: Currently set as V_LIGHT to switch relay on IoPin5 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID5) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID5, state);
         } 
        // ----- Action taken for child ID 6: Currently set as V_LIGHT to switch relay on IoPin6 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID6) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID6, state);
         } 
        // ----- Action taken for child ID 7: Currently set as V_LIGHT to switch relay on IoPin7 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID7) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID7, state);
         } 
        // ----- Virtual switches -----   
        // ----- Action taken for CHILD_ID_V1: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch1) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V1) {  //if message is V_LIGHT, the child ID is CHILD_ID_V1 do the following 
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch1 = state;                                        //copy the received boolean to VirtalSwitch1 
           saveState(CHILD_ID_V1, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         } 
        // ----- Action taken for CHILD_ID_V2: Currently set as V_LIGHT.  ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V2 && state == 1) {  //if message is V_LIGHT, the CHILD_ID_V2 and the message is 1 (on)
           VirtalSwitch2 = true;                                         //set VirtalSwitch2 (heating) to 1 (on)
           VirtalSwitch3 = false;                                        //set VirtalSwitch3 (anti frost) to 0. This prevents the anti frost and heating funtion being on at the same time.
           send(msgV3.set(0));                                           //sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion.
           saveState(CHILD_ID_V2, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }  
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V2 && state == 0) {  //if message is V_LIGHT, the CHILD_ID_V2 and the message is 0 (off)
           VirtalSwitch2 = false;                                        //set VirtalSwitch2 (heating) to 0 (off)
           VirtalSwitch3 = false;                                        //set VirtalSwitch3 (anti frost) to 0 ((off)
           send(msgV3.set(0));                                           //sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion.
           saveState(CHILD_ID_V2, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }
        // ----- Action taken for CHILD_ID_V3: Currently set as V_LIGHT.  ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V3 && state == 1) {  //if message is V_LIGHT, the CHILD_ID_V3 and the message is 1 (on)
           VirtalSwitch3 = true;                                         //set VirtalSwitch3 (anti frost) to 1 (on)
           VirtalSwitch2 = false;                                        //set VirtalSwitch2 (heating) to 0. This prevents the heating and anti frost funtion being on at the same time.
           send(msgV2.set(0));                                           //sent "off" command to gateway for CHILD_ID_V2. This is the heating funtion.
           saveState(CHILD_ID_V3, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }  
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V3 && state == 0) {  //if message is V_LIGHT, the CHILD_ID_V3 and the message is 0 (off)
           VirtalSwitch3 = false;                                        //set VirtalSwitch3 (anti frost) to 0 ((off)
           VirtalSwitch2 = false;                                        //set VirtalSwitch2 (heating) to 0 (off)
           send(msgV2.set(0));                                           //sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion.
           saveState(CHILD_ID_V3, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }
        // ----- Action taken for CHILD_ID_V4: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch4) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V4) {  //if message is V_LIGHT, the child ID is CHILD_ID_V4 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch4 = state;                                        //copy the received boolean to VirtalSwitch4 
           saveState(CHILD_ID_V4, state);                                //guess this saves the state if CHILD_ID_V4 to EEPPROM
         } 
        // ----- Action taken for CHILD_ID_V5: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch5) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V5) {  //if message is V_LIGHT, the child ID is CHILD_ID_V5 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch5 = state;                                        //copy the received boolean to VirtalSwitch5 
           saveState(CHILD_ID_V5, state);                                //guess this saves the state if CHILD_ID_V5 to EEPPROM
         } 
        // ----- Action taken for CHILD_ID_V6: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch6) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V6) {  //if message is V_LIGHT, the child ID is CHILD_ID_V6 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch6 = state;                                        //copy the received boolean to VirtalSwitch6 
           saveState(CHILD_ID_V6, state);                                //guess this saves the state if CHILD_ID_V6 to EEPPROM
         }    
        // ----- Action taken for CHILD_ID_V7: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch7) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V7) {  //if message is V_LIGHT, the child ID is CHILD_ID_V7 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch7 = state;                                        //copy the received boolean to VirtalSwitch7 
           saveState(CHILD_ID_V7, state);                                //guess this saves the state if CHILD_ID_V6 to EEPPROM
         }   
      }
      
      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      Found it!!! I figured there must be a serial begin somewhere in the library. It was not in MySensors.h, but MySensors.h had MySensorsCore.h included which included serval other library's. One of them was MyConfig.h I looked in al library's for a serial begin by searching "serial". In MyConfig.h i found this.

      /**********************************
      *  Serial and debug options
      ***********************************/
      
      // Enable MY_DEBUG in sketch to show debug prints. This option will add a lot to the size of the
      // final sketch but is helpful to see what is actually is happening during development
      //#define MY_DEBUG
      
      // Enable MY_SPECIAL_DEBUG in sketch to activate I_DEBUG messages if MY_DEBUG is disabled.
      // I_DEBUG requests are:
      // R: routing info (only repeaters): received msg XXYY (as stream), where XX is the node and YY the routing node
      // V: CPU voltage
      // F: CPU frequency
      // M: free memory
      // E: clear MySensors EEPROM area and reboot (i.e. "factory" reset)
      //#define MY_SPECIAL_DEBUG
      
      // Enable MY_DEBUG_VERBOSE_SIGNING flag for verbose debug prints related to signing.
      // Requires DEBUG to be enabled.
      // This will add even more to the size of the final sketch!
      //#define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable this in sketch if you want to use TX(1), RX(0) as normal I/O pin
      //#define MY_DISABLED_SERIAL
      
      // Enable MY_CORE_ONLY flag if you want to use core functions without loading the framework
      //#define MY_CORE_ONLY
      
      // Turn off debug if serial pins is used for other stuff
      

      Adding "#define MY_DISABLED_SERIAL" to my sketch did the trick, and i can now use the full keypad.

      // ##### SET PROJECT NAME AND VERSION #####
      #define ProjectName "Shed controller"
      #define ProjectVersion "0,3"
      
      // ##### SET MYSENSOR SETTINGS BEFORE INCLUDIGN LIBRARY #####
      //#define MY_DEBUG // Enable debug prints to serial monitor
      #define MY_DISABLED_SERIAL
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      #define MY_REPEATER_FEATURE // Enabled repeater feature for this node
      
      // ##### INCLUDE LIBRARYS #####
      #include <SPI.h>
      #include <MySensors.h>
      #include <Keypad.h>
      
      etc.....
      
      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      So right now i think i have all the code for the keypad en de relays complete. It does exactly what i want. I just have one problem...

      The damn thing keeps giving serial prints. In the sketch below not from the mysensors library, but from the keypad code. The problem with this is that i really need all the digital ports, including 1 and 0. At this point there is no real way around that.

      In the keypad code i posted in my 2nd post, this issue only happened when there was a serial print active. Its currently not in the sketch at all, or is working from the library?

      Does anyone has any clue how i can give the digital pin 0 and 1 back to the keypad again?

      My current code

      
      // ##### SET PROJECT NAME AND VERSION #####
      #define ProjectName "Shed controller"
      #define ProjectVersion "0,3"
      
      // ##### SET MYSENSOR SETTINGS BEFORE INCLUDIGN LIBRARY #####
      //#define MY_DEBUG // Enable debug prints to serial monitor
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      #define MY_REPEATER_FEATURE // Enabled repeater feature for this node
      
      // ##### INCLUDE LIBRARYS #####
      #include <SPI.h>
      #include <MySensors.h>
      #include <Keypad.h>
      
      // ##### DEFINE I/O PINS #####
      //#define IoPin1 4  // Arduino Digital I/O pin number for I/O 1 
      #define IoPin2 3  // Arduino Digital I/O pin number for I/O 2 
      //#define IoPin3 6  // Arduino Digital I/O pin number for I/O 3 
      #define IoPin4 5  // Arduino Digital I/O pin number for I/O 4 
      #define IoPin5 8  // Arduino Digital I/O pin number for I/O 5
      #define IoPin6 7  // Arduino Digital I/O pin number for I/O 6
      #define IoPin7 19 // Arduino Digital I/O pin number for I/O 7
      
      // ##### DEFINE CHILD ID'S #####
      #define CHILD_ID1 1    // ID for child 1 (I/O)
      #define CHILD_ID2 2    // ID for child 2 (I/O) used for relay
      //#define CHILD_ID3 3  // ID for child 3 (I/O)
      //#define CHILD_ID4 4  // ID for child 4 (I/O)
      #define CHILD_ID5 5    // ID for child 5 (I/O) used for relay
      #define CHILD_ID6 6    // ID for child 6 (I/O) used for relay
      #define CHILD_ID7 7    // ID for child 7 (I/O) used for relay
      #define CHILD_ID_V1 10  // ID for child virtual switch 1. Used for Outside lighting button
      #define CHILD_ID_V2 11  // ID for child virtual switch 2. Used for Heater button
      #define CHILD_ID_V3 12  // ID for child virtual switch 3. Used for Anti Frost button
      #define CHILD_ID_V4 13  // ID for child virtual switch 4. Used for Party Lights button
      #define CHILD_ID_V5 14  // ID for child virtual switch 5. Used for Wifi AP button
      #define CHILD_ID_V6 15  // ID for child virtual switch 6. Used for Aux 1 button
      #define CHILD_ID_V7 16  // ID for child virtual switch 7. Used for Aux 2 button
      #define CHILD_ID_V8 17  // ID for child virtual switch 8. Used for 5 min button
      
      
      // ##### RELAY SETTING #####
      #define RELAY_ON 0          // Invert for some relay modules (currently inverted)
      #define RELAY_OFF 1         // Invert for some relay modules (currently inverted)
      
      // ##### OTHER VARIABLES #####
      bool state; // Not realy sure what this exatly does. I guess temporary storage of received messages and loading from EEPROM
      
      // ##### BOOLEANS FOR VIRTUAL SWITCHES #####
      bool VirtalSwitch1;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch2;  // Boolean (status) for virtual switch 2 (controlled by keypad)
      bool VirtalSwitch3;  // Boolean (status) for virtual switch 3 (controlled by keypad)
      bool VirtalSwitch4;  // Boolean (status) for virtual switch 4 (controlled by keypad)
      bool VirtalSwitch5;  // Boolean (status) for virtual switch 5 (controlled by keypad)
      bool VirtalSwitch6;  // Boolean (status) for virtual switch 6 (controlled by keypad)
      bool VirtalSwitch7;  // Boolean (status) for virtual switch 7 (controlled by keypad)
      
      // ##### DEFINE MYSENSORS MESSAGE CONTAINERS TO COMMUNICATE WITH GATEWAY #####
      MyMessage msgV1(CHILD_ID_V1,S_LIGHT); // msgV1 sends child ID CHILD_ID_V1 as S_LIGHT
      MyMessage msgV2(CHILD_ID_V2,S_LIGHT); // msgV2 sends child ID CHILD_ID_V2 as S_LIGHT
      MyMessage msgV3(CHILD_ID_V3,S_LIGHT); // msgV3 sends child ID CHILD_ID_V3 as S_LIGHT
      MyMessage msgV4(CHILD_ID_V4,S_LIGHT); // msgV4 sends child ID CHILD_ID_V4 as S_LIGHT
      MyMessage msgV5(CHILD_ID_V5,S_LIGHT); // msgV5 sends child ID CHILD_ID_V5 as S_LIGHT
      MyMessage msgV6(CHILD_ID_V6,S_LIGHT); // msgV6 sends child ID CHILD_ID_V6 as S_LIGHT
      MyMessage msgV7(CHILD_ID_V7,S_LIGHT); // msgV7 sends child ID CHILD_ID_V7 as S_LIGHT
      MyMessage msgV8(CHILD_ID_V8,S_LIGHT); // msgV8 sends child ID CHILD_ID_V8 as S_LIGHT
      
      // ##### KEYPAD SETUP #####
      const byte ROWS = 4; // Just settings for keypad library. Enter number of rows here
      const byte COLS = 3; // Just settings for keypad library. Enter number of columns here
      // Nameing of very key on the keypad. The output of keypad code will be the charaters used here.
      char keys[ROWS][COLS] = {
        {'1', '2', '3'},
        {'4', '5', '6'},
        {'7', '8', '9'},
        {'A', 'B', 'C'}
      };
      byte rowPins[ROWS] = { A0, A1, A2, A3 }; // The pins the row wires are connected to (from left to right)
      byte colPins[COLS] = { A4, 1, 0 };       // The pins the column wires are connected to (from top to bottom)
      Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // This creates the actual keypad based on specs above.
      
      
      void setup()  
      {  
        // ##### I/O SETUP FOR PHYSICAL I/O ON ARDUINO #####
        // Setup I/O 2
        pinMode(IoPin2, OUTPUT);                        // use I/O 2 as output for relay module
        digitalWrite(IoPin2, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID2);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 4                                     Not in use  
        // pinMode(IoPin4, OUTPUT);                        // use I/O 4 as output for relay module
        // digitalWrite(IoPin4, RELAY_OFF);                // and set switch relay output off
        // state = loadState(CHILD_ID4);                   // Load last known state (using eeprom storage) 
        // digitalWrite(IoPin4, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 5
        pinMode(IoPin5, OUTPUT);                        // use I/O 5 as output for relay module
        digitalWrite(IoPin5, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID5);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 6
        pinMode(IoPin6, OUTPUT);                        // use I/O 6 as output for relay module
        digitalWrite(IoPin6, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID6);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 7
        pinMode(IoPin7, OUTPUT);                        // use I/O 7 as output for relay module
        digitalWrite(IoPin7, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID7);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF); // write last know state
      
      
       // ----- PIN SETUP (FOR TESTING ONLY -----
       // pinMode(IoPin4, OUTPUT);   //use I/O 4 as output for relay module
       // digitalWrite(IoPin4, HIGH);//   and set is HIGH so relay stays off
        
      }
      
      // ###### PRESENT ALL ATTACHED SENSORS TO CONTROLLER ######
      void presentation(){
        sendSketchInfo(ProjectName, ProjectVersion); // Send the sketch version information to the gateway and Controller
        // ----- Physical I/O child IDs -----
        //present(CHILD_ID1, XXXXXXX); //Register child ID 1 as NONE
        present(CHILD_ID2, S_LIGHT, "Outside lighting relay"); //Register child ID 2 as S_LIGHT, and sent name to controller.
        //present(CHILD_ID3, XXXXXXX); //Register child ID 3 as NONE
        //present(CHILD_ID4, XXXXXXX); //Register child ID 4 as NONE
        present(CHILD_ID5, S_LIGHT, "Switched outlet heater"); //Register child ID 5 as S_LIGHT, and sent name to controller.
        present(CHILD_ID6, S_LIGHT, "Sw outlet party lights"); //Register child ID 6 as S_LIGHT, and sent name to controller.
        present(CHILD_ID7, S_LIGHT, "Gate light relay");       //Register child ID 7 as S_LIGHT, and sent name to controller.
        // ----- virtual switch child ID (keypad)
        present(CHILD_ID_V1, S_LIGHT, "Outside light switch"); //Register CHILD_ID_V1 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V2, S_LIGHT, "Shed heater");          //Register CHILD_ID_V2 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V3, S_LIGHT, "Anti frost mode");      //Register CHILD_ID_V3 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V4, S_LIGHT, "Party lights");         //Register CHILD_ID_V4 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V5, S_LIGHT, "Wifi AP");              //Register CHILD_ID_V5 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V6, S_LIGHT, "Aux 1");                //Register CHILD_ID_V6 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V7, S_LIGHT, "Aux 2");                //Register CHILD_ID_V7 as S_LIGHT, and sent name to controller
        present(CHILD_ID_V8, S_LIGHT, "5 min. button");        //Register CHILD_ID_V8 as S_LIGHT, and sent name to controller
      } 
      
      void loop()
      { // ##### KEYPAD CODE TO SET A ACTION FOR A PRESSED KEY #####
        char key = kpd.getKey();       // Get key from keypad (if pressed)
        if (key)  {                    // compare key (defined in keypad setup)
          switch (key) {               // with multiple multiple options below
      
                                  // On button for outside light
            case '1':                  // If the pressed key compares with "1"
              VirtalSwitch1 = true;    // Change te state of boolean VirtalSwitch1 to true (on)
              send(msgV1.set(1));      // Sent "on" command to gateway for CHILD_ID_V1 
              Serial.println("KEY 1"); // Debug code. Print "KEY 1" to show that button 1 was pressed
              break;                   // End of code for button 1
      
                                  // Off button for outside light
            case '2':                  // If the pressed key compares with "2"
              VirtalSwitch1 = false;   // Change te state of boolean VirtalSwitch1 to false (off)
              send(msgV1.set(0));      // Sent "off" command to gateway for CHILD_ID_V1 
              Serial.println("KEY 2"); // Debug code. Print "KEY 2" to show that button 2 was pressed
              break;                   // End of code for button 2
      
                                  // 5 minute button
            case '3':                  // If the pressed key compares with "3"
              send(msgV8.set(1));      // Sent "on" command to gateway for CHILD_ID_V8
              Serial.println("KEY 4"); // Debug code. Print "KEY 4" to show that button 4 was pressed
              break;                   // End of code for button 4
      
                                  // On button for heating
            case '4':                  // If the pressed key compares with "4"
              VirtalSwitch2 = true;    // Change te state of boolean VirtalSwitch2 to true (on). This is the heater
              VirtalSwitch3 = false;   // Change te state of boolean VirtalSwitch3 to false (off). This is the anti frost funtion
              send(msgV2.set(1));      // Sent "on" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(0));      // Sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 4"); // Debug code. Print "KEY 4" to show that button 4 was pressed
              break;                   // End of code for button 4
      
                                  // Off button for heating
            case '5':                  // If the pressed key compares with "5"
              VirtalSwitch2 = false;   // Change te state of boolean VirtalSwitch2 to false (off). This is the heater
              VirtalSwitch3 = false;   // Change te state of boolean VirtalSwitch3 to false (off). This is the anti frost funtion
              send(msgV2.set(0));      // Sent "off" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(0));      // Sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 5"); // Debug code. Print "KEY 5" to show that button 5 was pressed
              break;                   // End of code for button 5
      
                                  // On button for anti frost
            case '6':                  // If the pressed key compares with "6"
              VirtalSwitch2 = false;   // Change te state of boolean VirtalSwitch2 to false (off). This is the heater
              VirtalSwitch3 = true;    // Change te state of boolean VirtalSwitch3 to true (on). This is the anti frost funtion
              send(msgV2.set(0));      // Sent "off" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(1));      // Sent "on" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 6"); // Debug code. Print "KEY 6" to show that button 6 was pressed
              break;                   // End of code for button 6
              
                                  // On button for party lights
            case '7':                  // If the pressed key compares with "7"
              VirtalSwitch4 = true;    // Change te state of boolean VirtalSwitch1 to true (on)
              send(msgV4.set(1));      // Sent "on" command to gateway for CHILD_ID_V4 
              Serial.println("KEY 7"); // Debug code. Print "KEY 7" to show that button 7 was pressed
              break;                   // End of code for button 7
      
                                  // Off button for party lights
            case '8':                  // If the pressed key compares with "8"
              VirtalSwitch4 = false;   // Change te state of boolean VirtalSwitch1 to false (off)
              send(msgV4.set(0));      // Sent "off" command to gateway for CHILD_ID_V4 
              Serial.println("KEY 8"); // Debug code. Print "KEY 8" to show that button 8 was pressed
              break;                   // End of code for button 8
      
                                      // Aux ON/OFF buton 1
            case '9':{                     // If the pressed key compares with "9"
              if (VirtalSwitch6 == false){ // check if the virtual switch (VirtalSwitch6) is OFF. If so, do the following
                VirtalSwitch6 = true;      // set the new status of the virtual swich to ON
                send(msgV6.set(1));        // Sent "on" command to gateway for CHILD_ID_V6 
              }
              else {                       // If the virtual switch was not OFF, it must have been ON, so do the following 
                VirtalSwitch6 = false;     // set the new status of the virtual swich to OFF
                send(msgV6.set(0));        // Sent "off" command to gateway for CHILD_ID_V6 
                }
              }
              Serial.println("KEY 9");    // Debug code. Print "KEY 9" to show that button 9 was pressed
              break;                      // End of code for button 9
      
                                   // On button for Wifi AP
            case 'A':                  // If the pressed key compares with "A"
              VirtalSwitch5 = true;    // Change te state of boolean VirtalSwitch5 to true (on)
              send(msgV5.set(1));      // Sent "on" command to gateway for CHILD_ID_V5 
              Serial.println("KEY A"); // Debug code. Print "KEY A" to show that button A was pressed
              break;                   // End of code for button A
      
                                   // Off button for Wifi AP
            case 'B':                  // If the pressed key compares with "B"
              VirtalSwitch5 = false;   // Change te state of boolean VirtalSwitch5 to false (off)
              send(msgV5.set(0));      // Sent "off" command to gateway for CHILD_ID_V5 
              Serial.println("KEY B"); // Debug code. Print "KEY B" to show that button B was pressed
              break;                   // End of code for button B    
      
                                    // Aux ON/OFF buton 2
            case 'C':{                     // If the pressed key compares with "C"
              if (VirtalSwitch7 == false){ // check if the virtual switch (VirtalSwitch7) is OFF. If so, do the following
                VirtalSwitch7 = true;      // set the new status of the virtual swich to ON
                send(msgV7.set(1));        // Sent "on" command to gateway for CHILD_ID_V7 
              }
              else {                       // If the virtual switch was not OFF, it must have been ON, so do the following 
                VirtalSwitch7 = false;     // set the new status of the virtual swich to OFF
                send(msgV7.set(0));        // Sent "off" command to gateway for CHILD_ID_V7 
                }
              }
              Serial.println("KEY C");    // Debug code. Print "KEY C" to show that button C was pressed
              break;                      // End of code for button C
              
            default:                  // If the pressed key does not match the cases above
              Serial.print(key);      // Print the key that was pressed
              Serial.println(" was pressed but not recognized by the keypadcode. Something is wrong!"); // print warning
              break;                  // End of function
          }
        }  
        // ----- WRITE BOOLEAN TO PIN (FOR TESTING PURPOSES ONLY) -----
        //digitalWrite(IoPin4, VirtalSwitch6);
      }
      
      // ##### CODE FOR RECEIVING MYSENSORS MESSAGES FROM CONTROLLER #####
      void receive(const MyMessage &message) {                         //start mysensor receiving code
        if (message.isAck()) {                                         //Check for gateway acknowledgment
           Serial.println("This is an ack from gateway");              //Print debug code (serial print) to confirm received ack
        }
        // ----- Relay actors -----
        // ----- Action taken for child ID 1: Currently set as V_LIGHT to switch relay on IoPin1 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID2) {  //if message is V_LIGHT and the child ID is 2 
           state = message.getBool();                                  //guess this write the incomming boolean to state?
           digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF);             //change the the arduino pin from "on" to "off" or other way around
           saveState(CHILD_ID2, state);                                //guess this saves the state if child ID 2 to EEPPROM
           Serial.print("Incoming change for sensor:");                //debug info text
           Serial.print(message.sensor);                               //write received child ID
           Serial.print(", New status: ");                             //debug info text
           Serial.println(message.getBool());                          //write received boolean
         } 
        // ----- Action taken for child ID 5: Currently set as V_LIGHT to switch relay on IoPin5 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID5) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID5, state);
         } 
        // ----- Action taken for child ID 6: Currently set as V_LIGHT to switch relay on IoPin6 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID6) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID6, state);
         } 
        // ----- Action taken for child ID 7: Currently set as V_LIGHT to switch relay on IoPin7 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID7) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID7, state);
         } 
        // ----- Virtual switches -----   
        // ----- Action taken for CHILD_ID_V1: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch1) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V1) {  //if message is V_LIGHT, the child ID is CHILD_ID_V1 do the following 
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch1 = state;                                        //copy the received boolean to VirtalSwitch1 
           saveState(CHILD_ID_V1, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         } 
        // ----- Action taken for CHILD_ID_V2: Currently set as V_LIGHT.  ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V2 && state == 1) {  //if message is V_LIGHT, the CHILD_ID_V2 and the message is 1 (on)
           VirtalSwitch2 = true;                                         //set VirtalSwitch2 (heating) to 1 (on)
           VirtalSwitch3 = false;                                        //set VirtalSwitch3 (anti frost) to 0. This prevents the anti frost and heating funtion being on at the same time.
           send(msgV3.set(0));                                           //sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion.
           saveState(CHILD_ID_V2, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }  
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V2 && state == 0) {  //if message is V_LIGHT, the CHILD_ID_V2 and the message is 0 (off)
           VirtalSwitch2 = false;                                        //set VirtalSwitch2 (heating) to 0 (off)
           VirtalSwitch3 = false;                                        //set VirtalSwitch3 (anti frost) to 0 ((off)
           send(msgV3.set(0));                                           //sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion.
           saveState(CHILD_ID_V2, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }
        // ----- Action taken for CHILD_ID_V3: Currently set as V_LIGHT.  ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V3 && state == 1) {  //if message is V_LIGHT, the CHILD_ID_V3 and the message is 1 (on)
           VirtalSwitch3 = true;                                         //set VirtalSwitch3 (anti frost) to 1 (on)
           VirtalSwitch2 = false;                                        //set VirtalSwitch2 (heating) to 0. This prevents the heating and anti frost funtion being on at the same time.
           send(msgV2.set(0));                                           //sent "off" command to gateway for CHILD_ID_V2. This is the heating funtion.
           saveState(CHILD_ID_V3, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }  
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V3 && state == 0) {  //if message is V_LIGHT, the CHILD_ID_V3 and the message is 0 (off)
           VirtalSwitch3 = false;                                        //set VirtalSwitch3 (anti frost) to 0 ((off)
           VirtalSwitch2 = false;                                        //set VirtalSwitch2 (heating) to 0 (off)
           send(msgV2.set(0));                                           //sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion.
           saveState(CHILD_ID_V3, state);                                //guess this saves the state if CHILD_ID_V1 to EEPPROM
         }
        // ----- Action taken for CHILD_ID_V4: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch4) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V4) {  //if message is V_LIGHT, the child ID is CHILD_ID_V4 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch4 = state;                                        //copy the received boolean to VirtalSwitch4 
           saveState(CHILD_ID_V4, state);                                //guess this saves the state if CHILD_ID_V4 to EEPPROM
         } 
        // ----- Action taken for CHILD_ID_V5: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch5) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V5) {  //if message is V_LIGHT, the child ID is CHILD_ID_V5 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch5 = state;                                        //copy the received boolean to VirtalSwitch5 
           saveState(CHILD_ID_V5, state);                                //guess this saves the state if CHILD_ID_V5 to EEPPROM
         } 
        // ----- Action taken for CHILD_ID_V6: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch6) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V6) {  //if message is V_LIGHT, the child ID is CHILD_ID_V6 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch6 = state;                                        //copy the received boolean to VirtalSwitch6 
           saveState(CHILD_ID_V6, state);                                //guess this saves the state if CHILD_ID_V6 to EEPPROM
         }    
        // ----- Action taken for CHILD_ID_V7: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch7) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V7) {  //if message is V_LIGHT, the child ID is CHILD_ID_V7 do the following
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch7 = state;                                        //copy the received boolean to VirtalSwitch7 
           saveState(CHILD_ID_V7, state);                                //guess this saves the state if CHILD_ID_V6 to EEPPROM
         }   
      }```
      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @tboha said:

      Yes, it is supposed to give a human readable name to your Sensor, which could be displayed by your controller.
      strange - within my "testenvironment" it compiled (5 minutes ago) without complaints.
      Would you please give the CompilerMessage?
      It is not a vital point but itΒ΄s anoying.

      I tried ir multiple times earlier tonight, but was unable to compile. (i dont know the error anymore). For some reason it works fine now. Very strange!

      Switching to a mega is no option at this point. I got all the hardware already soldered together on a PCB, and thats a lot of inputs and outputs to do. I also do not like the size of the mega. The ram i dont need. I'm currently at around 50% and besides the DTH sensor, i'm almost done.

      Also i like the challenge of creating what i want with minimal components. I'm pretty sure its going to work in the end!

      Same goes for multiple arduino's. I think i have a couple of I/O expander PCBs laying around, but rather not use them either as its complicates the sketch even further.

      I have read a lot about the API but i'm still very much struggling to understand anything of it. I will definitely continue to read!

      Below my current code. The keypad part is done. Next is the receiving part for the virtual switches.

      Thank you very much for your great help! I fear i will have new questions very soon!

      
      // ##### SET PROJECT NAME AND VERSION #####
      #define ProjectName "Schuur controller"
      #define ProjectVersion "0,2"
      
      // ##### SET MYSENSOR SETTINGS BEFORE INCLUDIGN LIBRARY #####
      #define MY_DEBUG // Enable debug prints to serial monitor
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      #define MY_REPEATER_FEATURE // Enabled repeater feature for this node
      
      // ##### INCLUDE LIBRARYS #####
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      #include <Keypad.h>
      
      // ##### DEFINE I/O PINS #####
      //#define IoPin1 4  // Arduino Digital I/O pin number for I/O 1 
      #define IoPin2 3  // Arduino Digital I/O pin number for I/O 2 
      //#define IoPin3 6  // Arduino Digital I/O pin number for I/O 3 
      #define IoPin4 5  // Arduino Digital I/O pin number for I/O 4 
      #define IoPin5 8  // Arduino Digital I/O pin number for I/O 5
      #define IoPin6 7  // Arduino Digital I/O pin number for I/O 6
      #define IoPin7 19 // Arduino Digital I/O pin number for I/O 7
      
      // ##### DEFINE CHILD ID'S #####
      #define CHILD_ID1 1    // ID for child 1 (I/O)
      #define CHILD_ID2 2    // ID for child 2 (I/O) used for relay
      //#define CHILD_ID3 3  // ID for child 3 (I/O)
      //#define CHILD_ID4 4  // ID for child 4 (I/O)
      #define CHILD_ID5 5    // ID for child 5 (I/O) used for relay
      #define CHILD_ID6 6    // ID for child 6 (I/O) used for relay
      #define CHILD_ID7 7    // ID for child 7 (I/O) used for relay
      #define CHILD_ID_V1 10  // ID for child virtual switch 1. Used for Outside lighting button
      #define CHILD_ID_V2 11  // ID for child virtual switch 2. Used for Heater button
      #define CHILD_ID_V3 12  // ID for child virtual switch 3. Used for Anit Frost button
      #define CHILD_ID_V4 13  // ID for child virtual switch 4. Used for Party Lights button
      #define CHILD_ID_V5 14  // ID for child virtual switch 5. Used for Wifi AP button
      #define CHILD_ID_V6 15  // ID for child virtual switch 6. Used for Aux 1 button
      #define CHILD_ID_V7 16  // ID for child virtual switch 7. Used for Aux 2 button
      #define CHILD_ID_V8 17  // ID for child virtual switch 8. Used for 5 min button
      
      
      // ##### RELAY SETTING #####
      #define RELAY_ON 0          // Invert for some relay modules (currently inverted)
      #define RELAY_OFF 1         // Invert for some relay modules (currently inverted)
      
      // ##### OTHER VARIABLES #####
      bool state; // not sure what this does
      
      // ##### BOOLEANS FOR VIRTUAL SWITCHES #####
      bool VirtalSwitch1;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch2;  // Boolean (status) for virtual switch 2 (controlled by keypad)
      bool VirtalSwitch3;  // Boolean (status) for virtual switch 3 (controlled by keypad)
      bool VirtalSwitch4;  // Boolean (status) for virtual switch 4 (controlled by keypad)
      bool VirtalSwitch5;  // Boolean (status) for virtual switch 5 (controlled by keypad)
      bool VirtalSwitch6;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch7;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      
      // ##### DEFINE MYSENSORS MESSAGE CONTAINERS TO COMMUNICATE WITH GATEWAY #####
      MyMessage msgV1(CHILD_ID_V1,S_LIGHT); // msgV1 sends child ID CHILD_ID_V1 as S_LIGHT
      MyMessage msgV2(CHILD_ID_V2,S_LIGHT); // msgV2 sends child ID CHILD_ID_V2 as S_LIGHT
      MyMessage msgV3(CHILD_ID_V3,S_LIGHT); // msgV3 sends child ID CHILD_ID_V3 as S_LIGHT
      MyMessage msgV4(CHILD_ID_V4,S_LIGHT); // msgV4 sends child ID CHILD_ID_V4 as S_LIGHT
      MyMessage msgV5(CHILD_ID_V5,S_LIGHT); // msgV5 sends child ID CHILD_ID_V5 as S_LIGHT
      MyMessage msgV6(CHILD_ID_V6,S_LIGHT); // msgV6 sends child ID CHILD_ID_V6 as S_LIGHT
      MyMessage msgV7(CHILD_ID_V7,S_LIGHT); // msgV7 sends child ID CHILD_ID_V7 as S_LIGHT
      MyMessage msgV8(CHILD_ID_V8,S_LIGHT); // msgV8 sends child ID CHILD_ID_V8 as S_LIGHT
      
      // ##### KEYPAD SETUP #####
      const byte ROWS = 4; // Four rows
      const byte COLS = 3; // Three columns
      // Define the Keymap
      char keys[ROWS][COLS] = {
        {'1', '2', '3'},
        {'4', '5', '6'},
        {'7', '8', '9'},
        {'A', 'B', 'C'}
      };
      // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
      byte rowPins[ROWS] = { A0, A1, A2, A3 };
      // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
      byte colPins[COLS] = { A4, 1, 0 };                                        //if you got any spare pins - change 0 and 1 accordingly  e.g. { A4, 8, 9 }
                                                                                // or see below
      // Create the Keypad
      Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
      
      void setup()  
      {  
        // ##### I/O SETUP FOR PHYSICAL I/O ON ARDUINO #####
        // Setup I/O 2
        pinMode(IoPin2, OUTPUT);                        // use I/O 2 as output for relay module
        digitalWrite(IoPin2, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID2);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 4                                     Not in use  
        // pinMode(IoPin4, OUTPUT);                        // use I/O 4 as output for relay module
        // digitalWrite(IoPin4, RELAY_OFF);                // and set switch relay output off
        // state = loadState(CHILD_ID4);                   // Load last known state (using eeprom storage) 
        // digitalWrite(IoPin4, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 5
        pinMode(IoPin5, OUTPUT);                        // use I/O 5 as output for relay module
        digitalWrite(IoPin5, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID5);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 6
        pinMode(IoPin6, OUTPUT);                        // use I/O 6 as output for relay module
        digitalWrite(IoPin6, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID6);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 7
        pinMode(IoPin7, OUTPUT);                        // use I/O 7 as output for relay module
        digitalWrite(IoPin7, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID7);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF); // write last know state
         
      
       // ----- PIN SETUP (FOR TESTING ONLY -----
        pinMode(IoPin4, OUTPUT);   //use I/O 4 as output for relay module
        digitalWrite(IoPin4, HIGH);//   and set is HIGH so relay stays off
        
      }
      
      // ###### PRESENT ALL ATTACHED SENSORS TO CONTROLLER ######
      void presentation(){
        sendSketchInfo(ProjectName, ProjectVersion); // Send the sketch version information to the gateway and Controller
      
        // ----- Actual I/O child IDs -----
        //present(CHILD_ID1, XXXXXXX); //Register child ID 1 as NONE
        present(CHILD_ID2, S_LIGHT);   //Register child ID 2 as S_LIGHT
        //present(CHILD_ID3, XXXXXXX); //Register child ID 3 as NONE
        //present(CHILD_ID4, XXXXXXX); //Register child ID 4 as NONE
        present(CHILD_ID5, S_LIGHT);   //Register child ID 5 as S_LIGHT
        present(CHILD_ID6, S_LIGHT);   //Register child ID 6 as S_LIGHT
        present(CHILD_ID7, S_LIGHT);   //Register child ID 7 as S_LIGHT
      
        // ----- virtual switch child ID (keypad)
        present(CHILD_ID_V1, S_LIGHT, "Outside light switch");    //Register child ID 10 as S_LIGHT
        present(CHILD_ID_V2, S_LIGHT);  //Register child ID 11 as S_LIGHT
        present(CHILD_ID_V3, S_LIGHT);  //Register child ID 12 as S_LIGHT
        present(CHILD_ID_V4, S_LIGHT);  //Register child ID 13 as S_LIGHT
        present(CHILD_ID_V5, S_LIGHT);  //Register child ID 14 as S_LIGHT
        present(CHILD_ID_V6, S_LIGHT);  //Register child ID 15 as S_LIGHT
        present(CHILD_ID_V7, S_LIGHT);  //Register child ID 16 as S_LIGHT
        present(CHILD_ID_V8, S_LIGHT);  //Register child ID 17 as S_LIGHT
      } 
      
      void loop()
      { // ##### KEYPAD CODE TO SET A ACTION FOR A PRESSED KEY #####
        char key = kpd.getKey();       // Get key from keypad (if pressed)
        if (key)  {                    // compare key (defined in keypad setup)
          switch (key) {               // with multiple multiple options below
      
                                  // On button for outside light
            case '1':                  // If the pressed key compares with "1"
              VirtalSwitch1 = true;    // Change te state of boolean VirtalSwitch1 to true (on)
              send(msgV1.set(1));      // Sent "on" command to gateway for CHILD_ID_V1 
              Serial.println("KEY 1"); // Debug code. Print "KEY 1" to show that button 1 was pressed
              break;                   // End of code for button 1
      
                                  // Off button for outside light
            case '2':                  // If the pressed key compares with "2"
              VirtalSwitch1 = false;   // Change te state of boolean VirtalSwitch1 to false (off)
              send(msgV1.set(0));      // Sent "off" command to gateway for CHILD_ID_V1 
              Serial.println("KEY 2"); // Debug code. Print "KEY 2" to show that button 2 was pressed
              break;                   // End of code for button 2
      
                                  // 5 minute button
            case '3':                  // If the pressed key compares with "3"
              send(msgV8.set(1));      // Sent "on" command to gateway for CHILD_ID_V8
              Serial.println("KEY 4"); // Debug code. Print "KEY 4" to show that button 4 was pressed
              break;                   // End of code for button 4
      
                                  // On button for heating
            case '4':                  // If the pressed key compares with "4"
              VirtalSwitch2 = true;    // Change te state of boolean VirtalSwitch2 to true (on). This is the heater
              VirtalSwitch3 = false;   // Change te state of boolean VirtalSwitch3 to false (off). This is the anti frost funtion
              send(msgV2.set(1));      // Sent "on" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(0));      // Sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 4"); // Debug code. Print "KEY 4" to show that button 4 was pressed
              break;                   // End of code for button 4
      
                                  // Off button for heating
            case '5':                  // If the pressed key compares with "5"
              VirtalSwitch2 = false;   // Change te state of boolean VirtalSwitch2 to false (off). This is the heater
              VirtalSwitch3 = false;   // Change te state of boolean VirtalSwitch3 to false (off). This is the anti frost funtion
              send(msgV2.set(0));      // Sent "off" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(0));      // Sent "off" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 5"); // Debug code. Print "KEY 5" to show that button 5 was pressed
              break;                   // End of code for button 5
      
                                  // On button for anti frost
            case '6':                  // If the pressed key compares with "6"
              VirtalSwitch2 = false;   // Change te state of boolean VirtalSwitch2 to false (off). This is the heater
              VirtalSwitch3 = true;    // Change te state of boolean VirtalSwitch3 to true (on). This is the anti frost funtion
              send(msgV2.set(0));      // Sent "off" command to gateway for CHILD_ID_V2. This is the heater
              send(msgV3.set(1));      // Sent "on" command to gateway for CHILD_ID_V3. This is the anti frost funtion
              Serial.println("KEY 6"); // Debug code. Print "KEY 6" to show that button 6 was pressed
              break;                   // End of code for button 6
              
                                  // On button for party lights
            case '7':                  // If the pressed key compares with "7"
              VirtalSwitch4 = true;    // Change te state of boolean VirtalSwitch1 to true (on)
              send(msgV4.set(1));      // Sent "on" command to gateway for CHILD_ID_V4 
              Serial.println("KEY 7"); // Debug code. Print "KEY 7" to show that button 7 was pressed
              break;                   // End of code for button 7
      
                                  // Off button for party lights
            case '8':                  // If the pressed key compares with "8"
              VirtalSwitch4 = false;   // Change te state of boolean VirtalSwitch1 to false (off)
              send(msgV4.set(0));      // Sent "off" command to gateway for CHILD_ID_V4 
              Serial.println("KEY 8"); // Debug code. Print "KEY 8" to show that button 8 was pressed
              break;                   // End of code for button 8
      
                                      // Aux ON/OFF buton 1
            case '9':{                     // If the pressed key compares with "9"
              if (VirtalSwitch6 == false){ // check if the virtual switch (VirtalSwitch6) is OFF. If so, do the following
                VirtalSwitch6 = true;      // set the new status of the virtual swich to ON
                send(msgV6.set(1));        // Sent "on" command to gateway for CHILD_ID_V6 
              }
              else {                       // If the virtual switch was not OFF, it must have been ON, so do the following 
                VirtalSwitch6 = false;     // set the new status of the virtual swich to OFF
                send(msgV6.set(0));        // Sent "off" command to gateway for CHILD_ID_V6 
                }
              }
              Serial.println("KEY 9");    // Debug code. Print "KEY 9" to show that button 9 was pressed
              break;                      // End of code for button 9
      
                                   // On button for Wifi AP
            case 'A':                  // If the pressed key compares with "A"
              VirtalSwitch5 = true;    // Change te state of boolean VirtalSwitch5 to true (on)
              send(msgV5.set(1));      // Sent "on" command to gateway for CHILD_ID_V5 
              Serial.println("KEY A"); // Debug code. Print "KEY A" to show that button A was pressed
              break;                   // End of code for button A
      
                                   // Off button for Wifi AP
            case 'B':                  // If the pressed key compares with "B"
              VirtalSwitch5 = false;   // Change te state of boolean VirtalSwitch5 to false (off)
              send(msgV5.set(0));      // Sent "off" command to gateway for CHILD_ID_V5 
              Serial.println("KEY B"); // Debug code. Print "KEY B" to show that button B was pressed
              break;                   // End of code for button B    
      
                                    // Aux ON/OFF buton 2
            case 'C':{                     // If the pressed key compares with "C"
              if (VirtalSwitch7 == false){ // check if the virtual switch (VirtalSwitch7) is OFF. If so, do the following
                VirtalSwitch7 = true;      // set the new status of the virtual swich to ON
                send(msgV7.set(1));        // Sent "on" command to gateway for CHILD_ID_V7 
              }
              else {                       // If the virtual switch was not OFF, it must have been ON, so do the following 
                VirtalSwitch7 = false;     // set the new status of the virtual swich to OFF
                send(msgV7.set(0));        // Sent "off" command to gateway for CHILD_ID_V7 
                }
              }
              Serial.println("KEY C");    // Debug code. Print "KEY C" to show that button C was pressed
              break;                      // End of code for button C
              
            default:                  // If the pressed key does not match the cases above
              Serial.print(key);      // Print the key that was pressed
              Serial.println(" was pressed but not recognized by the keypadcode. Something is wrong!"); // print warning
              break;                  // End of function
          }
        }  
        // ----- WRITE BOOLEAN TO PIN (FOR TESTING PURPOSES ONLY) -----
        //digitalWrite(IoPin4, VirtalSwitch6);
      }
      
      // ##### CODE FOR RECEIVING MYSENSORS MESSAGES FROM CONTROLLER #####
      void receive(const MyMessage &message) {                         //start mysensor receiving code
        if (message.isAck()) {                                         //Check for gateway acknowledgment
           Serial.println("This is an ack from gateway");              //Print debug code (serial print) to confirm received ack
        }
        // ----- Action taken for child ID 1: Currently set as V_LIGHT to switch relay on IoPin1 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID2) {  //if message is V_LIGHT and the child ID is 2 
           state = message.getBool();                                  //guess this write the incomming boolean to state?
           digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF);             //change the the arduino pin from "on" to "off" or other way around
           saveState(CHILD_ID2, state);                                //guess this saves the state if child ID 2 to EEPPROM
           Serial.print("Incoming change for sensor:");                //debug info text
           Serial.print(message.sensor);                               //write received child ID
           Serial.print(", New status: ");                             //debug info text
           Serial.println(message.getBool());                          //write received boolean
         } 
        // ----- Action taken for child ID 5: Currently set as V_LIGHT to switch relay on IoPin5 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID5) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID5, state);
         } 
        // ----- Action taken for child ID 6: Currently set as V_LIGHT to switch relay on IoPin6 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID6) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID6, state);
         } 
        // ----- Action taken for child ID 7: Currently set as V_LIGHT to switch relay on IoPin7 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID7) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID7, state);
         } 
         
         // ----- Action taken for CHILD_ID_V1: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch1) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V1) {  //if message is V_LIGHT and the CHILD_ID_V1
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch1 = state;                                        //copy the received boolean to VirtalSwitch1 
           saveState(CHILD_ID_V1, state);                               //guess this saves the state if CHILD_ID_V1 to EEPPROM
         } 
         
      }```
      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @tboha said:

      @SuperKris
      From the first look: it could be a simple typo:

      saveState(CHILD_ID_V1), state);
      should be
      saveState(CHILD_ID_V1, state);
      it may be simply one parenthesis too much.

      Wow.. I cant believe i missed that... damn.

      Ok, so everything seems to work now. I can just copy paste code and add some "virtual" buttons. Thats great! Thank you so much.

      Next i will need to add the PIR setup, but i think i have enough understanding to do this now. After that the DHT22 code. Should be a bit more trick, but i will get there.

      Just one more question about the code you written:

        present(CHILD_ID_V1, S_LIGHT, "Partylichtjes");  
      

      What does "partytlichtjes" do? I guess its supposed to send the name of the switch to the controller, but it wont compile if i add it in my sketch.

      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      Thank you very much thoba! With that info is was able to build a fully working proof of concept!

      I attached a test relay to IoPin4 which is linked to VirtalSwitch1. I can see VirtalSwitch1 in the controller, and add it as switch. When i use the keypad it changes the boolean, and the status of the switch is updated in the controller.

      I can not change the same boolean trough the controller, as there is no receiving code. This however was easy to write because i figured it would not be much different than the relay pins. I added some code, and it seems to work fine. I can change the boolean in the node with the controller now.

      There is still 1 issue with this code. I can not store the state of the boolean to the EEPROM. If i uncomment the last line, the sketch will not compile and i get the following error:

      Arduino: 1.6.13 (Windows Store 1.6.13.0) (Windows 10), Board:"Arduino Nano, ATmega328"
      
      C:\Users\krist\Desktop\arduino testing\IO_test_0.2\IO_test_0.2.ino: In function 'void receive(const MyMessage&)':
      
      IO_test_0.2:207: error: too few arguments to function 'void saveState(uint8_t, uint8_t)'
      
            saveState(CHILD_ID_V1), state);                               //guess this saves the state if child ID 2 to EEPPROM
      
                                 ^
      
      In file included from C:\Users\krist\Documents\Arduino\libraries\MySensors/MySensors.h:293:0,
      
                       from C:\Users\krist\Desktop\arduino testing\IO_test_0.2\IO_test_0.2.ino:13:
      
      C:\Users\krist\Documents\Arduino\libraries\MySensors/core/MySensorsCore.cpp:408:6: note: declared here
      
       void saveState(uint8_t pos, uint8_t value) {
      
            ^
      
      exit status 1
      too few arguments to function 'void saveState(uint8_t, uint8_t)'
      
      This report would have more information with
      "Show verbose output during compilation"
      option enabled in File -> Preferences.
      

      The working code:

      
      // ##### SET PROJECT NAME AND VERSION #####
      #define ProjectName "Schuur controller"
      #define ProjectVersion "0,2"
      
      // ##### SET MYSENSOR SETTINGS BEFORE INCLUDIGN LIBRARY #####
      #define MY_DEBUG // Enable debug prints to serial monitor
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      #define MY_REPEATER_FEATURE // Enabled repeater feature for this node
      
      // ##### INCLUDE LIBRARYS #####
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      #include <Keypad.h>
      
      // ##### DEFINE I/O PINS #####
      //#define IoPin1 4  // Arduino Digital I/O pin number for I/O 1 
      #define IoPin2 3  // Arduino Digital I/O pin number for I/O 2 
      //#define IoPin3 6  // Arduino Digital I/O pin number for I/O 3 
      #define IoPin4 5  // Arduino Digital I/O pin number for I/O 4 
      #define IoPin5 8  // Arduino Digital I/O pin number for I/O 5
      #define IoPin6 7  // Arduino Digital I/O pin number for I/O 6
      #define IoPin7 19 // Arduino Digital I/O pin number for I/O 7
      
      // ##### DEFINE CHILD ID'S #####
      #define CHILD_ID1 1    // ID for child 1 (I/O)
      #define CHILD_ID2 2    // ID for child 2 (I/O)
      //#define CHILD_ID3 3  // ID for child 3 (I/O)
      //#define CHILD_ID4 4  // ID for child 4 (I/O)
      #define CHILD_ID5 5    // ID for child 5 (I/O)
      #define CHILD_ID6 6    // ID for child 6 (I/O)
      #define CHILD_ID7 7    // ID for child 7 (I/O)
      #define CHILD_ID_V1 10  // ID for child virtual switch 1
      #define CHILD_ID_V2 11  // ID for child virtual switch 2
      #define CHILD_ID_V3 12  // ID for child virtual switch 3
      #define CHILD_ID_V4 13  // ID for child virtual switch 4
      #define CHILD_ID_V5 14  // ID for child virtual switch 5
      
      // ##### RELAY SETTING #####
      #define RELAY_ON 0          // Invert for some relay modules (currently inverted)
      #define RELAY_OFF 1         // Invert for some relay modules (currently inverted)
      
      // ##### OTHER VARIABLES #####
      bool state; // not sure what this does
      
      // ##### BOOLEANS FOR VIRTUAL SWITCHES #####
      bool VirtalSwitch1;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch2;  // Boolean (status) for virtual switch 2 (controlled by keypad)
      bool VirtalSwitch3;  // Boolean (status) for virtual switch 3 (controlled by keypad)
      bool VirtalSwitch4;  // Boolean (status) for virtual switch 4 (controlled by keypad)
      bool VirtalSwitch5;  // Boolean (status) for virtual switch 5 (controlled by keypad)
      
      // ##### DEFINE MYSENSORS MESSAGE CONTAINERS TO COMMUNICATE WITH GATEWAY #####
      MyMessage msgV1(CHILD_ID_V1,S_LIGHT); // msgV1 sends child ID CHILD_ID_V1 as S_LIGHT
      MyMessage msgV2(CHILD_ID_V2,S_LIGHT); // msgV2 sends child ID CHILD_ID_V2 as S_LIGHT
      MyMessage msgV3(CHILD_ID_V3,S_LIGHT); // msgV3 sends child ID CHILD_ID_V3 as S_LIGHT
      MyMessage msgV4(CHILD_ID_V4,S_LIGHT); // msgV4 sends child ID CHILD_ID_V4 as S_LIGHT
      MyMessage msgV5(CHILD_ID_V5,S_LIGHT); // msgV5 sends child ID CHILD_ID_V5 as S_LIGHT
      
      // ##### KEYPAD SETUP #####
      const byte ROWS = 4; // Four rows
      const byte COLS = 3; // Three columns
      // Define the Keymap
      char keys[ROWS][COLS] = {
        {'1', '2', '3'},
        {'4', '5', '6'},
        {'7', '8', '9'},
        {'A', 'B', 'C'}
      };
      // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
      byte rowPins[ROWS] = { A0, A1, A2, A3 };
      // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
      byte colPins[COLS] = { A4, 1, 0 };                                        //if you got any spare pins - change 0 and 1 accordingly  e.g. { A4, 8, 9 }
                                                                                // or see below
      // Create the Keypad
      Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
      
      void setup()  
      {  
        // ##### I/O SETUP FOR PHYSICAL I/O ON ARDUINO #####
        // Setup I/O 2
        pinMode(IoPin2, OUTPUT);                        // use I/O 2 as output for relay module
        digitalWrite(IoPin2, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID2);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 4                                     Not in use  
        // pinMode(IoPin4, OUTPUT);                        // use I/O 4 as output for relay module
        // digitalWrite(IoPin4, RELAY_OFF);                // and set switch relay output off
        // state = loadState(CHILD_ID4);                   // Load last known state (using eeprom storage) 
        // digitalWrite(IoPin4, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 5
        pinMode(IoPin5, OUTPUT);                        // use I/O 5 as output for relay module
        digitalWrite(IoPin5, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID5);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 6
        pinMode(IoPin6, OUTPUT);                        // use I/O 6 as output for relay module
        digitalWrite(IoPin6, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID6);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 7
        pinMode(IoPin7, OUTPUT);                        // use I/O 7 as output for relay module
        digitalWrite(IoPin7, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID7);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF); // write last know state
         
      
       // ----- PIN SETUP (FOR TESTING ONLY -----
        pinMode(IoPin4, OUTPUT);   //use I/O 4 as output for relay module
        digitalWrite(IoPin4, HIGH);//   and set is HIGH so relay stays off
        
      }
      
      // ###### PRESENT ALL ATTACHED SENSORS TO CONTROLLER ######
      void presentation(){
        sendSketchInfo(ProjectName, ProjectVersion); // Send the sketch version information to the gateway and Controller
      
        // ----- Actual I/O child IDs -----
        //present(CHILD_ID1, XXXXXXX); //Register child ID 1 as NONE
        present(CHILD_ID2, S_LIGHT);   //Register child ID 2 as S_LIGHT
        //present(CHILD_ID3, XXXXXXX); //Register child ID 3 as NONE
        //present(CHILD_ID4, XXXXXXX); //Register child ID 4 as NONE
        present(CHILD_ID5, S_LIGHT);   //Register child ID 5 as S_LIGHT
        present(CHILD_ID6, S_LIGHT);   //Register child ID 6 as S_LIGHT
        present(CHILD_ID7, S_LIGHT);   //Register child ID 7 as S_LIGHT
      
        // ----- virtual switch child ID (keypad)
        present(CHILD_ID_V1, S_LIGHT);  //Register child ID 10 as S_LIGHT
        present(CHILD_ID_V2, S_LIGHT);  //Register child ID 11 as S_LIGHT
        present(CHILD_ID_V3, S_LIGHT);  //Register child ID 12 as S_LIGHT
        present(CHILD_ID_V4, S_LIGHT);  //Register child ID 13 as S_LIGHT
        present(CHILD_ID_V5, S_LIGHT);  //Register child ID 14 as S_LIGHT
      } 
      
      void loop()
      { // ##### KEYPAD CODE TO SET A ACTION FOR A PRESSED KEY #####
        char key = kpd.getKey();     // Get key from keypad (if pressed)
        if (key)  {                  // compare key (defined in keypad setup)
          switch (key) {             // with multiple multiple options below
      
            case '1':                // If the pressed key compares with "1"
              VirtalSwitch1 = true;  // Change te state of boolean VirtalSwitch1 to true
              send(msgV1.set(1));    // sending virtual switch state to Gateway
              Serial.println("1");   // Debug code. Print "1" to show that button 1 was pressed
              break;                 // End of code for button 1
      
            case '4':                // If the pressed key compares with "4"
              VirtalSwitch1 = false; // Change te state of boolean VirtalSwitch1 to false
              send(msgV1.set(0));    // sending virtual switch state to Gateway
              Serial.println("4");   // Debug code. Print "4" to show that button 4 was pressed
              break;                 // End of code for button 4
      
                                     // Other keys to be added here according to the same template
              
            default:                 // If the pressed key does not match the cases above
              Serial.println(key);   // Print the key that was pressed
              break;                 // End of function
          }
        }  
        // ----- WRITE BOOLEAN TO PIN (FOR TESTING PURPOSES ONLY) -----
        digitalWrite(IoPin4, VirtalSwitch1);
      }
      
      // ##### CODE FOR RECEIVING MYSENSORS MESSAGES FROM CONTROLLER #####
      void receive(const MyMessage &message) {                         //start mysensor receiving code
        if (message.isAck()) {                                         //Check for gateway acknowledgment
           Serial.println("This is an ack from gateway");              //Print debug code (serial print) to confirm received ack
        }
        // ----- Action taken for child ID 1: Currently set as V_LIGHT to switch relay on IoPin1 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID2) {  //if message is V_LIGHT and the child ID is 2 
           state = message.getBool();                                  //guess this write the incomming boolean to state?
           digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF);             //change the the arduino pin from "on" to "off" or other way around
           saveState(CHILD_ID2, state);                                //guess this saves the state if child ID 2 to EEPPROM
           Serial.print("Incoming change for sensor:");                //debug info text
           Serial.print(message.sensor);                               //write received child ID
           Serial.print(", New status: ");                             //debug info text
           Serial.println(message.getBool());                          //write received boolean
         } 
        // ----- Action taken for child ID 5: Currently set as V_LIGHT to switch relay on IoPin5 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID5) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID5, state);
         } 
        // ----- Action taken for child ID 6: Currently set as V_LIGHT to switch relay on IoPin6 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID6) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID6, state);
         } 
        // ----- Action taken for child ID 7: Currently set as V_LIGHT to switch relay on IoPin7 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID7) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID7, state);
         } 
         
         // ----- Action taken for CHILD_ID_V1: Currently set as V_LIGHT. Changes the boolean of virtual switch (VirtalSwitch1) ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID_V1) {  //if message is V_LIGHT and the CHILD_ID_V1
           state = message.getBool();                                    //guess this write the incomming boolean to state?
           VirtalSwitch1 = state;                                        //copy the received boolean to VirtalSwitch1 
           //saveState(CHILD_ID_V1), state);                               //guess this saves the state if child ID 2 to EEPPROM
         } 
         
      }```
      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @Qu3Uk said:

      @SuperKris said:

      The keypad will not be used to enter numbers. I will place a sticker over it converting the text on the switches to functions as "turn party lights on", "switch heater on", and "turn on garden lights for 5 min". These buttons will be coupled to certain actions by the controller. I'm using Domoticz on a Rpi.

      Nice idea. When you do it could you provide a photo? Like to know how clean it looks.

      Once the project is finished i'll make a new topic with the pictures, electrical connections, and the code so anyone can recreate it.

      The trick with the foil keyboards is one i did not do for some time now. I picked it up at a company i worked for a while. We took register scales for store. They have big foil keyboards with a lot PLU's (products) printed on each button. We would redraw the keyboard, put net tekst on the buttons, and print it on paper of plastic sheets and cut it to size. Next we would laminate it with double sticky plastic sheets with sticky back in a hot laminating machine. Next simply paste the sheets over the original keyboard, and it would look great. Pretty durable too. The effect might be less on a smaller keypad, bu i think it will probably look pretty decent.

      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @korttoma said:

      Hi @SuperKris

      Have you checked if Domoticz support the scene controller type?

      Here is an example project by @petewill

      Hi Korttoma,

      I have no idea if, and how, the scene controller sketch is supported in Domotics. Looking at the sketch the function is a bit different from what i'm looking to do. The sketch seems to sent a number to the controller instead of the the on or off status of a "virtual" switch.

      I guess i could write code in Domotics that can convert this input to certain events, but i'm trying to keep it simple at the controllers side. Otherwise i would have to ceate virtual switches in domotics, and lots of scripts.

      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @Boots33 said:

      @SuperKris So the keypad will just control the state of a "virtual" switch on the controller ? and then you will have that virtual switch control other nodes to do the actual hardware switching?

      That is exactly what i want!

      @tboha said:

      @SuperKris : you should consider adding the "sending" routines for MySensors. Maybe dissecting the Binary Switch Example would be a better startingpoint than the RelaySketch.

      I tried to integrate these routines into your template. Unfortunately I canΒ΄t test this sketch due to the lack of the Keypad. At least the sketch compiles without error.

      Thanks! this should really help! I will test this tonight but its already giving me some understanding of how the sending of the messages work. I already have a couple of questions from just looking at you code.

      1. I see you did not really use the manual created booleans ("VirtalSwitch1" for example). Do i need these manual created booleans for the function i want, of are these booleans automatically created by the mysensors library?

      2. The code you added to sent the "virtual" switches to the controller seems to be the following:

      • "MyMessage msgV1(CHILD_ID_V1,S_LIGHT)" presents the existence of the switch to the gateway
      • and "send(msgV1.set(1))" sends the status change to the gateway.
        Where is the status (boolean?) actually stored? Is this a boolean provided by the mysensors code?
      1. Again, if i understand right, the state of a (virtual) switch is always stored on the node. Not on the controller. Can you confirm?
        If so, how do i change the state of the (virtual) switch from the controller? For example. 1 keypad button will control the the outside lighting. Inside of the house i will place a 433mhz wallswitch that does the same thing. For this i need the 433mhz wallswitch to be able to change the state of the (virtual) button. The controller (Domoticz) will turn on the lights depending on the state of the virtual switch.
        In other words, it seems to me the vitual switches should be controlled by the controller, but i dont see any receiving code.

      2. I see you wrote some comments about not using pin 0 and 1. I would rather not used them too, but i do not have any pins left. I need:
        6 digital pins for the NRF24L01 radio
        5 digital pins for the keypad
        4 digital pins for relays
        1 digital pin for PIR
        1 digital pin for TEMP/HUM
        1 digital pin for future expansion
        This leaves me with no available pins. A5 and A6 are analog only so i have no use for these. Unfortunatly i really need 0 and 1. I can still use then for debugging, but when serial debug is activated i loose 2 collumns of the keypad. For debugging this is not a huge problem.

      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      @Boots33 said:

      @SuperKris If I understand what you are trying to do is use the keypad instead of individual push buttons to change the relay state. Is that correct?

      Yes and no... or mostly.... no. Instead of changing the relay state, i want the push button to be a separate switch which is technically not related to any relays or other outputs. Its supposed to behave like a walls witch that is available in the controller.

      In the end i may couple a push button to one of the relay outputs, but this will be done in the controller. For instance, the controller wil only allow to switch on the light with the pushbutton if its dark outside.

      In the keypad code i do use 2 keys to control the boolean. This has 2 reasons. 1) that part is just proof of concept. 2) for some of the buttons i want it to work like this. I'm aware that i can use 1 button to change the boolean and change it back. I will add this later for some buttons.

      I hope this clarifies my intentions. This makes it different from the relay+button example sketch. Otherwise i would probably find it easier. I'm currently hoping to learn how i can make these "virtual wall switches" that are controlled from the keypad.

      I just dont know how to sent the booleans to the controller. I'm also not sure how to receive them, though i'm thinking it must be similar to the actual relays.

      posted in My Project
      SuperKris
      SuperKris
    • RE: How do i sent "virtual switches" from node to Controller?

      Here is most of my code;

      Relay code (fully working):

      // ##### SET PROJECT NAME AND VERSION #####
      #define ProjectName "Schuur controller"
      #define ProjectVersion "0,1"
      
      // ##### SET MYSENSOR SETTINGS BEFORE INCLUDIGN LIBRARY #####
      #define MY_DEBUG // Enable debug prints to serial monitor
      #define MY_RADIO_NRF24 // Enable and select radio type attached
      #define MY_REPEATER_FEATURE // Enabled repeater feature for this node
      
      // ##### INCLUDE LIBRARYS #####
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      #include <Keypad.h>
      
      // ##### DEFINE I/O PINS #####
      //#define IoPin1 4  // Arduino Digital I/O pin number for I/O 1 
      #define IoPin2 3  // Arduino Digital I/O pin number for I/O 2 
      //#define IoPin3 6  // Arduino Digital I/O pin number for I/O 3 
      //#define IoPin4 5  // Arduino Digital I/O pin number for I/O 4 
      #define IoPin5 8  // Arduino Digital I/O pin number for I/O 5
      #define IoPin6 7  // Arduino Digital I/O pin number for I/O 6
      #define IoPin7 19 // Arduino Digital I/O pin number for I/O 7
      
      // ##### DEFINE CHILD ID'S #####
      #define CHILD_ID1 1    // ID for child 1 (I/O)
      #define CHILD_ID2 2    // ID for child 2 (I/O)
      //#define CHILD_ID3 3  // ID for child 3 (I/O)
      //#define CHILD_ID4 4  // ID for child 4 (I/O)
      #define CHILD_ID5 5    // ID for child 5 (I/O)
      #define CHILD_ID6 6    // ID for child 6 (I/O)
      #define CHILD_ID7 7    // ID for child 7 (I/O)
      #define CHILD_ID10 10  // ID for child 10 (virtual switch)
      #define CHILD_ID11 11  // ID for child 11 (virtual switch)
      #define CHILD_ID12 12  // ID for child 12 (virtual switch)
      #define CHILD_ID13 13  // ID for child 13 (virtual switch)
      #define CHILD_ID14 14  // ID for child 14 (virtual switch)
      
      // ##### RELAY SETTING #####
      #define RELAY_ON 0          // Invert for some relay modules (currently inverted)
      #define RELAY_OFF 1         // Invert for some relay modules (currently inverted)
      
      // ##### OTHER VARIABLES #####
      bool state; // not sure what this does
      
      // ##### BOOLEANS FOR VIRTUAL SWITCHES #####
      bool VirtalSwitch1;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch2;  // Boolean (status) for virtual switch 2 (controlled by keypad)
      bool VirtalSwitch3;  // Boolean (status) for virtual switch 3 (controlled by keypad)
      bool VirtalSwitch4;  // Boolean (status) for virtual switch 4 (controlled by keypad)
      bool VirtalSwitch5;  // Boolean (status) for virtual switch 5 (controlled by keypad)
      
      void setup()  
      {  
        // ##### I/O SETUP FOR PHYSICAL I/O ON ARDUINO #####
        // Setup I/O 2
        pinMode(IoPin2, OUTPUT);                        // use I/O 2 as output for relay module
        digitalWrite(IoPin2, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID2);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 4                                     Not in use  
        // pinMode(IoPin4, OUTPUT);                        // use I/O 4 as output for relay module
        // digitalWrite(IoPin4, RELAY_OFF);                // and set switch relay output off
        // state = loadState(CHILD_ID4);                   // Load last known state (using eeprom storage) 
        // digitalWrite(IoPin4, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 5
        pinMode(IoPin5, OUTPUT);                        // use I/O 5 as output for relay module
        digitalWrite(IoPin5, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID5);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 6
        pinMode(IoPin6, OUTPUT);                        // use I/O 6 as output for relay module
        digitalWrite(IoPin6, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID6);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF); // write last know state
      
        // Setup I/O 7
        pinMode(IoPin7, OUTPUT);                        // use I/O 7 as output for relay module
        digitalWrite(IoPin7, RELAY_OFF);                // and set switch relay output off
        state = loadState(CHILD_ID7);                   // Load last known state (using eeprom storage) 
        digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF); // write last know state
        // 
      }
      
      // ###### PRESENT ALL ATTACHED SENSORS TO CONTROLLER ######
      void presentation(){
        sendSketchInfo(ProjectName, ProjectVersion); // Send the sketch version information to the gateway and Controller
      
        // ----- Actual I/O child IDs -----
        //present(CHILD_ID1, XXXXXXX); //Register child ID 1 as NONE
        present(CHILD_ID2, S_LIGHT);   //Register child ID 2 as S_LIGHT
        //present(CHILD_ID3, XXXXXXX); //Register child ID 3 as NONE
        //present(CHILD_ID4, XXXXXXX); //Register child ID 4 as NONE
        present(CHILD_ID5, S_LIGHT);   //Register child ID 5 as S_LIGHT
        present(CHILD_ID6, S_LIGHT);   //Register child ID 6 as S_LIGHT
        present(CHILD_ID7, S_LIGHT);   //Register child ID 7 as S_LIGHT
      
        // ----- virtual switch child ID (keypad)
        present(CHILD_ID10, S_LIGHT);  //Register child ID 10 as S_LIGHT
        present(CHILD_ID11, S_LIGHT);  //Register child ID 11 as S_LIGHT
        present(CHILD_ID12, S_LIGHT);  //Register child ID 12 as S_LIGHT
        present(CHILD_ID13, S_LIGHT);  //Register child ID 13 as S_LIGHT
        present(CHILD_ID14, S_LIGHT);  //Register child ID 14 as S_LIGHT
      } 
      
      void loop() 
      {
      }
      
      // ##### CODE FOR RECEIVING MYSENSORS MESSAGES FROM CONTROLLER #####
      void receive(const MyMessage &message) {                         //start mysensor receiving code
        if (message.isAck()) {                                         //Check for gateway acknowledgment
           Serial.println("This is an ack from gateway");              //Print debug code (serial print) to confirm received ack
        }
        // ----- Action taken for child ID 1: Currently set as V_LIGHT to switch relay on IoPin1 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID2) {  //if message is V_LIGHT and the child ID is 2 
           state = message.getBool();                                  //guess this write the incomming boolean to state?
           digitalWrite(IoPin2, state?RELAY_ON:RELAY_OFF);             //change the the arduino pin from "on" to "off" or other way around
           saveState(CHILD_ID2, state);                                //guess this saves the state if child ID 2 to EEPPROM
           Serial.print("Incoming change for sensor:");                //debug info text
           Serial.print(message.sensor);                               //write received child ID
           Serial.print(", New status: ");                             //debug info text
           Serial.println(message.getBool());                          //write received boolean
         } 
        // ----- Action taken for child ID 5: Currently set as V_LIGHT to switch relay on IoPin5 -----
        if (message.type == V_LIGHT && message.sensor == CHILD_ID5) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin5, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID5, state);
         } 
        // ----- Action taken for child ID 6: Currently set as V_LIGHT to switch relay on IoPin6 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID6) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin6, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID6, state);
         } 
        // ----- Action taken for child ID 7: Currently set as V_LIGHT to switch relay on IoPin7 ----- 
        if (message.type == V_LIGHT && message.sensor == CHILD_ID7) {  //no further comments. See actions for child 2. Its the same
           state = message.getBool();                                  //also no debug code (serial print) written to save space
           digitalWrite(IoPin7, state?RELAY_ON:RELAY_OFF);
           saveState(CHILD_ID7, state);
         } 
         
      }
      

      **Keypad code (concept works): **

      
      // -------- USED LIBARIES -----------
      #include <Keypad.h>
      
      // ##### KEYPAD SETUP #####
      const byte ROWS = 4; // Four rows
      const byte COLS = 3; // Three columns
      // Define the Keymap
      char keys[ROWS][COLS] = {
        {'1','2','3'},
        {'4','5','6'},
        {'7','8','9'},
        {'A','B','C'}
      };
      // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
      byte rowPins[ROWS] = { A0, A1, A2, A3 };
      // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
      byte colPins[COLS] = { A4, 1, 0 }; 
      // Create the Keypad
      Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
      
      // ##### DEFINE I/O PINS #####
      //#define IoPin1 4  // Arduino Digital I/O pin number for I/O 1 
      #define IoPin2 3  // Arduino Digital I/O pin number for I/O 2 
      //#define IoPin3 6  // Arduino Digital I/O pin number for I/O 3 
      #define IoPin4 5  // Arduino Digital I/O pin number for I/O 4 
      #define IoPin5 8  // Arduino Digital I/O pin number for I/O 5
      #define IoPin6 7  // Arduino Digital I/O pin number for I/O 6
      #define IoPin7 19 // Arduino Digital I/O pin number for I/O 7
      
      
      // ##### BOOLEANS FOR VIRTUAL SWITCHES #####
      bool VirtalSwitch1;  // Boolean (status) for virtual switch 1 (controlled by keypad)
      bool VirtalSwitch2;  // Boolean (status) for virtual switch 2 (controlled by keypad)
      bool VirtalSwitch3;  // Boolean (status) for virtual switch 3 (controlled by keypad)
      bool VirtalSwitch4;  // Boolean (status) for virtual switch 4 (controlled by keypad)
      bool VirtalSwitch5;  // Boolean (status) for virtual switch 5 (controlled by keypad)
      
      void setup()
      
      
      { // ##### PIN SETUP (FOR TESTING ONLY #####
      
        pinMode(IoPin4, OUTPUT);   //use I/O 4 as output for relay module
        digitalWrite(IoPin4, HIGH);//   and set is HIGH so relay stays off
      
        
        // ###### VARIOUS SETTINGS ######
        Serial.begin(115200); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SERIAL PRINT MUST BE DEACTIVATED TO MAKE THE WHOLE KEYPAD WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      
      
      } 
      
      void loop()
      {
        char key = kpd.getKey();     // Get key from keypad (if pressed)
        if(key)  {                   // compare key (defined in keypad setup)
          switch (key) {             // with multiple multiple options below 
            
            case '1':                // If the pressed key compares with "1"
              VirtalSwitch1 = true;  // Change te state of boolean VirtalSwitch1 to true
              Serial.println("1");   // Debug code. Print "1" to show that button 1 was pressed
              break;                 // End of code for button 1
            
            case '4':                // If the pressed key compares with "4"          
              VirtalSwitch1 = false; // Change te state of boolean VirtalSwitch1 to false
              Serial.println("2");   // Debug code. Print "4" to show that button 4 was pressed
              break;                 // End of code for button 4
      
              
            default:                 // If the pressed key does not match the cases above
              Serial.println(key);   // Print the key that was pressed 
              break;                 // End of function 
          }
        }
      
      // ##### WRITE BOOLEAN TO PIN (FOR TESTING PURPOSES ONLY) #####
        digitalWrite(IoPin4, VirtalSwitch1);
      
        
      }
      
      

      I need to join this code and get the boolean to communicate toe the controller as described in my first post.

      posted in My Project
      SuperKris
      SuperKris
    • How do i sent "virtual switches" from node to Controller?

      I need some help with a project that i'm building. I'm calling it the Shed Controller. This is a Mysensors 2.0 node that controls all the electronics around my shed. I features relays, PIR, i plan to add temperature sensor, and it has a keypad.

      The keypad will not be used to enter numbers. I will place a sticker over it converting the text on the switches to functions as "turn party lights on", "switch heater on", and "turn on garden lights for 5 min". These buttons will be coupled to certain actions by the controller. I'm using Domoticz on a Rpi.

      I want to use a keypad (3 row, 4 column) because i have very limited I/O pins available. Also its a very clean and cheap way to place buttons on the housing, as it just sticks on there.

      I'm a bit of a noob when it comes to Arduino and Mysensors. Its not my first build, but i had a lot of trouble realizing all the relay code. That works fine now, but as you may understand i want other functionality than the relay + button example.

      I'm using a modified version of a standard keypad library example. When a button is pressed its decoded and passed tough a "switch/case" function where i can couple a action to each key. How do i make this key available in the controller?

      I would guess i have to create a boolean that can be changed by the pressing of the key. If i understand right, the status of any device is always hold on the device itself. The information in the controller is just a copy of that status. The boolean can be changed by either the keypad button(internally in the arduino code), or the controller (a script or a manual button press in the GUI). Am i right so far?

      • Now i need to know how i can present the boolean to the controler as a "switch"' so its added to the devices.
      • I also need to know how to sent changes to changes of the boolean to the controller (pressing the button)
      • I'm guessing that receiving the messages from the controller works the same as for the relays? Or is there a easier way?

      I would really need some simplified example code, as my understanding of the mysensors code is very basic! (I have read most of all the api documentation, but u still dont understand how to write the code)

      Your help would be very appreciated!

      posted in My Project
      SuperKris
      SuperKris
    • RE: Computer power supply as 12/5/3.3V whole house power supply

      I'm not sure i really understand... Are you talking about powering all the mysensor modules through out the whole house by a single source? If so i can hardly imagine why one would like to do this. This would completely go against the mysensors idea. Such a system would be more fragile, use more power than necessary, and just be very ugly and overcomlicated because of all the wiring.

      If your talking about usage on a switchboard only, it makes a lot more sense. Still, arduino's and all compatible systems use a very low amount of energy. I power a raspberry pi 2, 2 arduino's, a chip amp, and a couple of other modules with a $ 2,- step down converter of aliexpress. The consumption is so low, the load indicator doesn even switch on most of the time.

      In other words, unless your powering heavy equipment, a computer PSU is a huge overkill. I would recommend buying a cheap industrial DIN rail supply of aliexpess or another source. In the end this might even be cheaper. Its saver and a whole less work for sure!

      posted in My Project
      SuperKris
      SuperKris
    • RE: Retrofit sensors into 240v LED Night Light : Help a novice?

      The kind of "PSU" thats is in that night light is not ideal for a mysensors application. I suggest you use this one:

      https://www.domoticz.com/forum/viewtopic.php?f=42&t=7832

      I think using the housing is a good idea, but please throw away those electronics.

      Here in the netherlands we have a cheap ass store called "Action" where they sell those 433mhz controlled remote plug in switches. You get 3 of them + a remote control for just € 10,-. I think they can be a pretty good housing too.

      posted in My Project
      SuperKris
      SuperKris
    • RE: How is a message from the controller written to a digital pin?

      @martinhjelmare said:

      Thanks again! It works now! I thought there would be a function similar to message.type, but i could not find it. The relay sketch is still a bit confusing to me, but i came up with the following solution. It seems to work...

      Is this a effective way to do this, or is there a much easier way without using the if statement?

      void incomingMessage(const MyMessage &message) {
        if (message.type == V_LIGHT && message.sensor == CHILD_ID1)
          {
          S_VALVE1 = message.getBool();
          gw.send(MSG_V1.set(S_VALVE1 ? 1 : 0));
          }
        if (message.type == V_LIGHT && message.sensor == CHILD_ID2)
          {
          S_VALVE2 = message.getBool();
          gw.send(MSG_V2.set(S_VALVE2 ? 1 : 0));
          }
      }
      
      posted in Development
      SuperKris
      SuperKris
    • RE: How is a message from the controller written to a digital pin?

      @martinhjelmare said:

      It works, thank you very, very, much!!! I checked the brackets multiple times, but i did not see the fault! But it works now!

      I cleaned up the code a bit, and tried to copy and modify it for the 2nd valve. The code below does not work. I understand why it doesnt work, but i do not understand how to fix it.

      The incommingMessage function does not seem to check for what variable/child ID the message was meant. It only checks if the message is of the V_LIGHT type. If the message is V_LIGHT, it changes the boolean S_VALVE1. It however also changes S_VALVE2.

      I does not check for the child ID that is sent by the controller. How do i make it check for the child ID so i can switch them individually?

      // -------- USED LIBARIES -----------
      #include <MySensor.h>
      #include <SPI.h>
      
      // -----------DEFINE----------------
      
      // Names and identification. This will appear in controller
      #define MYS_NAME "Irrigation Computer"
      #define MYS_VER "0.2"
      #define NODE_ID 100 //Used for the node ID
      #define CHILD_ID1 101 //Used for valve 1
      #define CHILD_ID2 102 //Used for valve 2
      
      // Defines which IO pins are used 
      #define SWITCH1 4
      #define SWITCH2 5
      #define MOTOR1 6
      #define MOTOR2 7
      
      // Variables for switching the valves 
      boolean S_VALVE1 = false; // desired status valve 1
      boolean S_VALVE2 = false; // desired status valve 2
      int ONTIME1 = 0; // turn on for X time (countdown)
      int ONTIME2 = 0; // turn on for X time (countdown)
      
      MySensor gw;
      MyMessage MSG_V1(CHILD_ID1, V_LIGHT);
      MyMessage MSG_V2(CHILD_ID2, V_LIGHT);
      
      // ------------SETUP---------------      
      // *** Identification ***  
      void setup(){
        gw.begin(incomingMessage, NODE_ID, false); //mysensors initialization. Function incomming message
        gw.sendSketchInfo(MYS_NAME, MYS_VER); //sent sketch info an version to controler
        gw.present(CHILD_ID1, S_LIGHT); //child ID and type of device 1 as seen in controler 
        gw.present(CHILD_ID2, S_LIGHT); //child ID and type of device 2 as seen in controler
        
        // *** IO SETUP ***
        pinMode(SWITCH1,INPUT_PULLUP); //set switch 1 as a input (pin number defined in DEFINE)
        pinMode(SWITCH2,INPUT_PULLUP); //set switch 2 as a output (pin number defined in DEFINE)
        pinMode(MOTOR1,OUTPUT); //set motor 1 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR1,LOW); //Activate internal pull-down for motor 1
        pinMode(MOTOR2,OUTPUT); //set motor 2 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR2,LOW); //Activate internal pull-down for motor 2
      
      // *** MySensors functions *** 
        gw.send(MSG_V1.set(S_VALVE1 ? 1 : 0)); // Sents status of valve back to controler
        gw.send(MSG_V2.set(S_VALVE2 ? 1 : 0)); // Sents status of valve back to controler
      
      }
      // ------------LOOP---------------
      void loop() 
      {
        gw.process();
         
      /*// *** Serial print for debugging ***  
        Serial.println("");
        Serial.println("");
        Serial.println("");
        Serial.println("------------------------------");
        Serial.println("Current I/O values");
        Serial.println("------------------------------");
        Serial.print("Desired status of valve 1= ");
        Serial.println(S_VALVE1);
        Serial.print("Switch 1= ");
        Serial.println(digitalRead(SWITCH1));
        Serial.print("Motor 1= ");
        Serial.println(digitalRead(MOTOR1));
        Serial.println("");
        Serial.print("Desired status of valve 2= ");
        Serial.println(S_VALVE2); //TEST PURPOSE ONLY!!
        Serial.print("Switch 2= ");
        Serial.println(digitalRead(SWITCH2));
        Serial.print("Motor 2= ");
        Serial.println(digitalRead(MOTOR2));
        Serial.println("------------------------------");
        delay(500); */
      
      // ------------ I/O logic of valve 1 -------------------
      // This code controles the valves based on the status of boolean S_VALVE1. 0 = valve should be closes, 1 = valve should be open
        // If valve 1 should be on, but switch 1 sais valve 1 is still off, turn on motor 1 to open te valve
        if (S_VALVE1 == true && digitalRead(SWITCH1) == HIGH)
          {
          digitalWrite(MOTOR1, HIGH);  
          }
        // If valve 1 should be on, and switch 1 sais valve 1 is currely on, the valve is in the right position, and the motor should stop turning 
        if (S_VALVE1 == true && digitalRead(SWITCH1) == LOW)
          {
          digitalWrite(MOTOR1, LOW);
          }
        //If valve 1 should be off, but switch 1 sais valve 1 is still on, turn on motor to close the valve
        if (S_VALVE1 == false && digitalRead(SWITCH1) == LOW)
          {
          digitalWrite(MOTOR1, HIGH); 
          }  
        // If valve 1 should be off, and switch 1 sais valve 1 is currently off, the valve is in the right position, and the motor should stop turning 
        if (S_VALVE1 == false && digitalRead(SWITCH1) == HIGH)
          {
          digitalWrite(MOTOR1, LOW);
          } 
      // -----------End of I/O logic of valve 1------------------
      // Below is the logic of valve 2. The code works the same a valve 1, but is uncommented and more compact.
        if (S_VALVE2 == true && digitalRead(SWITCH2) == HIGH)
          {digitalWrite(MOTOR2, HIGH);} 
        if (S_VALVE2 == true && digitalRead(SWITCH2) == LOW)
          {digitalWrite(MOTOR2, LOW);}
        if (S_VALVE2 == false && digitalRead(SWITCH2) == LOW)
          {digitalWrite(MOTOR2, HIGH);}  
        if (S_VALVE2 == false && digitalRead(SWITCH2) == HIGH)
          {digitalWrite(MOTOR2, LOW);} 
      // -----------End of I/O logic of valve 2------------------ 
      }
      
      void incomingMessage(const MyMessage &message) {
        if (message.type == V_LIGHT) 
          {
          S_VALVE1 = message.getBool();
          gw.send(MSG_V1.set(S_VALVE1 ? 1 : 0));
          }
        if (message.type == V_LIGHT) 
          {
          S_VALVE2 = message.getBool();
          gw.send(MSG_V2.set(S_VALVE2 ? 1 : 0));
          }
      }
      
      posted in Development
      SuperKris
      SuperKris
    • RE: How is a message from the controller written to a digital pin?

      Thanks! This helps me understand a little bit better. I tried adding the incoming.Message part before, but i keep ketting this error when i try to upload:

      'incomingMessage' was not declared in this scope

      I do not understand why it does this! I cant find any faults in the syntax, and other sketches that use this do not give this error. (like the relay actor example)

      This is the updated code now:

      // -------- USED LIBARIES -----------
      #include <SPI.h>
      #include <MySensor.h>
      
      
      // -----------DEFINE----------------
      
      // Name and version of sketch. This will appear in conroler
      #define MYS_NAME "Irrigation Computer"
      #define MYS_VER "0.1.1"
      
      // Defines which IO pins are used 
      #define SWITCH1 4
      #define SWITCH2 5
      #define MOTOR1 6
      #define MOTOR2 7
      
      // Variables for switching the valves 
      boolean S_VALVE1 = false; // desired status valve 1
      boolean S_VALVE2 = false; // desired status valve 2
      int ONTIME1 = 0; // turn on for X time (countdown)
      int ONTIME2 = 0; // turn on for X time (countdown)
      
      MySensor gw;
      MyMessage msg(101, V_LIGHT);
      
      //TEST PURPOSE ONLY!!!
      //#define FAKEONMESSAGE1 3 //TEST PURPOSE ONLY!!!
      
      
      // ------------SETUP---------------      
      
      // *** Identification ***  
      void setup() {
        gw.begin(incomingMessage); //mysensors initialization 
        gw.sendSketchInfo(MYS_NAME, MYS_VER); //sent sketch info an version to controler
        gw.present(101, S_LIGHT); //child ID and type of device 1 as seen in controler 
        gw.present(102, S_LIGHT); //child ID and type of device 2 as seen in controler
        
      // *** IO SETUP ***
        // Switch 1
        pinMode(SWITCH1,INPUT_PULLUP); //set switch 1 as a input (pin number defined in DEFINE)
        // Switch 2
        pinMode(SWITCH2,INPUT_PULLUP); //set switch 2 as a output (pin number defined in DEFINE)
        // Motor 1
        pinMode(MOTOR1,OUTPUT); //set motor 1 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR1,LOW); //Activate internal pull-down
        // Motor 2
        pinMode(MOTOR2,OUTPUT); //set motor 2 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR2,LOW); //Activate internal pull-down  
      
        gw.send(msg.set(S_VALVE1 ? 1 : 0));
      
      //TEST PURPOSE ONLY!!!
      //pinMode(FAKEONMESSAGE1,INPUT_PULLUP); //TEST PURPOSE ONLY!!!
      
      }
      
      // ------------LOOP---------------
      
      void loop() 
      {
        gw.process();
         
        // *** Serial print for debugging ***  
        Serial.println("");
        Serial.println("");
        Serial.println("");
        Serial.println("Current I/O values");
      
      //  Serial.print("Fake on message= "); //TEST PURPOSE ONLY!!!
      //  Serial.println(digitalRead(FAKEONMESSAGE1)); //TEST PURPOSE ONLY!!!
      
        Serial.print("status on boolean= "); //TEST PURPOSE ONLY!!!
        Serial.println(S_VALVE1); //TEST PURPOSE ONLY!!!
      
        Serial.print("Switch 1= ");
        Serial.println(digitalRead(SWITCH1));
      
        Serial.print("Motor 1= ");
        Serial.println(digitalRead(MOTOR1));
        
        Serial.print("Switch 2= ");
        Serial.println(digitalRead(SWITCH2));
      
        Serial.print("Motor 2= ");
        Serial.println(digitalRead(MOTOR2));
      
        delay(500); 
        
      
      //  if (digitalRead(FAKEONMESSAGE1) == HIGH) //TEST PURPOSE ONLY!!!
      //    {
      //    S_VALVE1 = true; //TEST PURPOSE ONLY!!!
      //    }
      //  if (digitalRead(FAKEONMESSAGE1) == LOW) //TEST PURPOSE ONLY!!!
      //    {
      //    S_VALVE1 = false; //TEST PURPOSE ONLY!!!
      //    }
      
        // If valve 1 should be on, but switch 1 sais valve 1 is still off, turn on motor 1 to open te valve
        if (S_VALVE1 == true && digitalRead(SWITCH1) == HIGH)
          {
          digitalWrite(MOTOR1, HIGH);  
          }
        // If valve 1 should be on, and switch 1 sais valve 1 is currely on, the valve is in the right position, and the motor should stop turning 
        if (S_VALVE1 == true && digitalRead(SWITCH1) == LOW)
          {
          digitalWrite(MOTOR1, LOW);
          }
        //If valve 1 should be off, but switch 1 sais valve 1 is still on, turn on motor to close the valve
        if (S_VALVE1 == false && digitalRead(SWITCH1) ==  LOW)
          {
          digitalWrite(MOTOR1, HIGH); 
          }  
        // If valve 1 should be off, and switch 1 sais valve 1 is currently off, the valve is in the right position, and the motor should stop turning 
        if (S_VALVE1 == false && digitalRead(SWITCH1) == HIGH)
          {
          digitalWrite(MOTOR1, LOW);
          }
      }
      }
      
      void incomingMessage(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) 
        {
          S_VALVE1 = message.getBool();
          gw.send(msg.set(S_VALVE1 ? 1 : 0));
        }
      }
      

      Thanks for the tip on the missing I/O code. I think i accidentally deleted it trying all kinds of stuff to make the communication work.

      posted in Development
      SuperKris
      SuperKris
    • RE: How is a message from the controller written to a digital pin?

      Thank you very, very much for all that info. I think it helped a lot, but i can still not get it to do anything with te received message.

      I did learn a not of other thing about arduino, and was able to write some of my code needed for the I/O. The only thing i need it to do now is to change boolean S_VALVE1 but i just cant get it to work! I tried reading the api again, but that stuff just looks very advanced to me. How do i change the boolean with by sending a 1 or 0 from my controler? (Domoticz). Af far as i can see, this part is working.

      Can anyone tell me what is wrong in my sketch, and how i can fix it?

      If i can get this to work, ill try to switch to a V_CUSTOM or V_DIMMER that set a countdown which controlls the boolean, but i want to start simple...

      // -------- USED LIBARIES -----------
      #include <SPI.h>
      #include <MySensor.h>
      
      
      // -----------DEFINE----------------
      
      // Name and version of sketch. This will appear in conroler
      #define MYS_NAME "Irrigation Computer"
      #define MYS_VER "0.1.1"
      
      // Defines which IO pins are used 
      #define SWITCH1 4
      #define SWITCH2 5
      #define MOTOR1 6
      #define MOTOR2 7
      
      // Variables for switching the valves 
      boolean S_VALVE1 = false; // desired status valve 1
      boolean S_VALVE2 = false; // desired status valve 2
      int ONTIME1 = 0; // turn on for X time (countdown)
      int ONTIME2 = 0; // turn on for X time (countdown)
      
      //TEST PURPOSE ONLY!!!
      //#define FAKEONMESSAGE1 3 //TEST PURPOSE ONLY!!!
      
      MySensor gw;
      
      // ------------SETUP---------------      
      
      // *** Identification ***  
      void setup() {
        gw.begin(); //mysensors initialization 
        gw.sendSketchInfo(MYS_NAME, MYS_VER); //sent sketch info an version to controler
        gw.present(101, S_LIGHT); //child ID and type of device 1 as seen in controler 
        gw.present(102, S_LIGHT); //child ID and type of device 2 as seen in controler
        
      // *** IO SETUP ***
        // Switch 1
        pinMode(SWITCH1,INPUT_PULLUP); //set switch 1 as a input (pin number defined in DEFINE)
        // Switch 2
        pinMode(SWITCH2,INPUT_PULLUP); //set switch 2 as a output (pin number defined in DEFINE)
        // Motor 1
        pinMode(MOTOR1,OUTPUT); //set motor 1 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR1,LOW); //Activate internal pull-down
        // Motor 2
        pinMode(MOTOR2,OUTPUT); //set motor 2 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR2,LOW); //Activate internal pull-down  
      
      //TEST PURPOSE ONLY!!!
      //pinMode(FAKEONMESSAGE1,INPUT_PULLUP); //TEST PURPOSE ONLY!!!
      
      
      }
      
      // ------------LOOP---------------
      
      void loop() 
      {
        gw.process();
         
        // *** Serial print for debugging ***  
        Serial.println("");
        Serial.println("");
        Serial.println("");
        Serial.println("Current I/O values");
      
      //  Serial.print("Fake on message= "); //TEST PURPOSE ONLY!!!
      //  Serial.println(digitalRead(FAKEONMESSAGE1)); //TEST PURPOSE ONLY!!!
      
        Serial.print("status on boolean= "); //TEST PURPOSE ONLY!!!
        Serial.println(S_VALVE1); //TEST PURPOSE ONLY!!!
      
        Serial.print("Switch 1= ");
        Serial.println(digitalRead(SWITCH1));
      
        Serial.print("Motor 1= ");
        Serial.println(digitalRead(MOTOR1));
        
        Serial.print("Switch 2= ");
        Serial.println(digitalRead(SWITCH2));
      
        Serial.print("Motor 2= ");
        Serial.println(digitalRead(MOTOR2));
      
        delay(500); 
        
      
      //  if (digitalRead(FAKEONMESSAGE1) == HIGH) //TEST PURPOSE ONLY!!!
      //    {
      //    S_VALVE1 = true; //TEST PURPOSE ONLY!!!
      //    }
      //  if (digitalRead(FAKEONMESSAGE1) == LOW) //TEST PURPOSE ONLY!!!
      //    {
      //    S_VALVE1 = false; //TEST PURPOSE ONLY!!!
      //    }
      
        // If valve 1 should be on, but switch 1 sais valve 1 is still off, turn on motor 1 to open te valve
        if (S_VALVE1 == true && digitalRead(SWITCH1) == HIGH)
          {
          digitalWrite(MOTOR1, HIGH);  
          }
        // If valve 1 should be on, and switch 1 sais valve 1 is currely on, the valve is in the right position, and the motor should stop turning 
        if (S_VALVE1 == true && digitalRead(SWITCH1) == LOW)
          {
          digitalWrite(MOTOR1, LOW);
          }
        //If valve 1 should be off, but switch 1 sais valve 1 is still on, turn on motor to close the valve
        if (S_VALVE1 == false && digitalRead(SWITCH1) ==  LOW)
          {
        // If valve 1 should be off, and switch 1 sais valve 1 is currently off, the valve is in the right position, and the motor should stop turning 
        if (S_VALVE1 == false && digitalRead(SWITCH1) == HIGH)
          {
          digitalWrite(MOTOR1, LOW);
          }
      }
      }
      
      void incomingMessage(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) 
           {
           S_VALVE1 = message.getBool();
           }   
        }
      
      
      posted in Development
      SuperKris
      SuperKris
    • RE: How is a message from the controller written to a digital pin?

      I'm not sure is i understand anything of that fist sentence... Im such a noob 😞 Can you please clarify?

      Off course i had a look at the relay actor example. I tried to recreate the basics of it, but i'm not able to write message from the controller to a pin. I think my sketch receives the data from the controller, there was defiantly something in the serial monitor, but i just dont understand how this part works.

      I've read everything i could understand in the API, but for me that doesnt seem te be enough for me to understand how i can use the radio signal transmitted by the controller.

      If i understand right, a sensor that only transmits should just sent a data message to the controller. While i didn't try this yet, i do think i understand the basics from reading the API. The receiving part is not explained as detailed, or am i missing something?

      Please tell me if i understand this right: I have to put gw.process(); in the void loop part so the mysensors library keeps checking for messages. Is this true, or are there other ways? I would assume this uses a lot of battery, and i want to run on just 2 AA batteries.

      The rest of code does not take place in the void loop. Below is the part from the example sketch that i assume makes the relay switch.

      }
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LIGHT) {
           // Change relay state
           digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           // Store state in eeprom
           gw.saveState(message.sensor, message.getBool());
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      

      So if i read this right this does the following:
      If the message type is equal too V_LIGHT (How does the arduino know which message i'm talking about?)
      Then change the state of a digital output.... a lot that i do not understand....

      Anyway, if i bring this back to the basics, i would assume the following would work:

      void incomingMessage(const MyMessage &message) {
        if (message.type == V_LIGHT) {
           // Change relay state
           digitalWrite(MOTOR1, HIGH);
        }
      }
      

      But this does absolutely nothing.

      posted in Development
      SuperKris
      SuperKris
    • How is a message from the controller written to a digital pin?

      First of im sorry for this probably stupid question. Ive been reading a the API, example sketches, and arduino tutorials for a couple of nights now. With all i learned i was able to write some code, but i'm very stuck at the point where messages from the controller are actually written to a pin of the memory of the arduino.

      To learn how to use Arduino and Mysensors, i want to make a very simple relay actor to start with. I think i have all the pin setup right. The commented debug shows the values right in the serial monitor. The V_LIGHT is seen in Domoticz and it seems like it sends the values.

      Even with all the reading and trying, i still dont understand how i can receive the messages and get them in my code. For my application i dont need to remember the values once the arduino is turned off. Can you guys help me understand? I'm sorry i'm such a noob.

      I'm trying to hook up a irrigation computer to my controller (Domoticz) You can find the whole story here. I think i figured out how i'm going to make Domoticz sent a "on for X minutes" code. I'm either using V_CUSTOM or V_DIMMER. Domoticz will sent a value of 10, 20, 30, 40, that represents 1,5,10, 20, etc, minutes on time. When the time is counted down to 0 i want the system to turn off again and sent a "off" command to the controller.

      // -------- USED LIBARIES -----------
      #include <SPI.h>
      #include <MySensor.h>
      
      
      // -----------DEFINE----------------
      
      // Name and version of sketch. This will appear in conroler
      #define MYS_NAME "Irrigation Computer"
      #define MYS_VER "0.1.1"
      
      // Defines which IO pins are used 
      #define SWITCH1 4
      #define SWITCH2 5
      #define MOTOR1 6
      #define MOTOR2 7
      
      MySensor gw;
      
      
      // ------------SETUP---------------      
      
      // *** Identification ***  
      void setup() {
        gw.begin(); //mysensors initialization 
        gw.sendSketchInfo(MYS_NAME, MYS_VER); //sent sketch info an version to controler
        gw.present(101, S_LIGHT); //child ID and type of device 1 as seen in controler 
        gw.present(102, S_LIGHT); //child ID and type of device 2 as seen in controler
        
      // *** IO SETUP ***
        // Switch 1
        pinMode(SWITCH1,INPUT_PULLUP); //set switch 1 as a input (pin number defined in DEFINE)
        // Switch 2
        pinMode(SWITCH2,INPUT_PULLUP); //set switch 2 as a output (pin number defined in DEFINE)
        // Motor 1
        pinMode(MOTOR1,OUTPUT); //set motor 1 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR1,LOW); //Activate internal pull-down
        // Motor 2
        pinMode(MOTOR2,OUTPUT); //set motor 2 as a output (pin number defined in DEFINE)
        digitalWrite(MOTOR2,LOW); //Activate internal pull-down  
      }
      
      // ------------LOOP---------------
      
      void loop() 
      {
        gw.process();
         
        /* *** Serial print for debugging ***  
        Serial.println("");
        Serial.println("");
        Serial.println("");
        Serial.println("Current I/O values");
      
        Serial.print("Switch 1= ");
        Serial.println(digitalRead(SWITCH1));
      
        Serial.print("Motor 1= ");
        Serial.println(digitalRead(MOTOR1));
        
        Serial.print("Switch 2= ");
        Serial.println(digitalRead(SWITCH2));
      
        Serial.print("Motor 2= ");
        Serial.println(digitalRead(MOTOR2));
        
        delay(1000);
        /*
      }
      
      posted in Development
      SuperKris
      SuperKris
    • RE: Irrigation computer with MySensor. Noob needs some help.

      Thanks for the reply! At this point i have no experience with LUA, but from my earlier experiments with domoticz and mysensors, i do not see what i need the LUA script for.

      I want som make de controler (domitcz) as stupid as possible. Domotics must decide when the irrigation must be activated, but it must not turn it of unless i give a manual command is given.

      I want the system the external device (Arduino/mysensors) to control when the irrigation should stop. I do not want this logic in Domoticz. If domotics or the RPi crashes or the transmission fails, the irrigation system will never receive a off command, and will keep running.

      Therefore i want Domitcs to tell the system to activate for a X amount of minutes. Alternatively it could be just 3 different "on signals" for a duration of 5, 10 and 30 minutes.

      Currently i'm already experimenting with the relay and binary switch example as basis, but i still have no idea what i'm doing. I was hoping there already was a standard (domitcs compatible) senor type that could sent a value from domotics to the mysensor device.

      I dont think a opto coupler is needed as everything will run on 2 AA batteries. No that that arduino is going to damage the fet controling the motors. Maybe i'll use a diode to make sure the uC of the irrigation device will not be damaged, but i dont even think that is really needed.

      posted in My Project
      SuperKris
      SuperKris
    • RE: Irrigation computer with MySensor. Noob needs some help.

      Nobody? Its very hard for me to know where to start. I want a good combination between the controller (domiticz) and the sensors available in mysensors

      posted in My Project
      SuperKris
      SuperKris
    • Irrigation computer with MySensor. Noob needs some help.

      I'm doing my first real Mysenors project. Off course i already build a working gateway, and did a couple of example nodes like the relay and DHT11 sensor to test. But that is about as far as it goes. I have never written any code (just 1 phyton script 2 weeks ago). So this will be the first time i will really be writing code for the arduino. I need some directions to start with. I hope you can help.

      Some time ago before i started with automating my house, i bought a irrigation computer of aliexpress:
      0_1460060822128_sproeicomputer.JPG

      I want to hook this up to my house automation. Specificly a Raspberry Pi with Domoticz. In a later stage i will also build a sensor that checks how dry the ground is. I will create a function that will check is the ground is too dry in my vegetable garden, and if the forecast says it wil not rain for another 12 hours or so, it will be watered.

      I opened up the computer and it turns out to be very simple to hack. It has 2 sets of the following: A motor with gears turning a valve around. When the valve is closed a mechanical switch is open, and output voltage is logical 1 (VCC). When the valve is turned open, the switch shorts to ground, and the output is a logical 0 (GND)

      The arduino output i need is simple
      Standby state: Logical 1 input for arduino
      Opening valve: Logical 1 output from arduino to a FET to spin the motor.
      Valve opened: Input changes to 0. Output to fet must change to 0 directly so the motor stops.
      Closing valve: Logical 1 output from arduino to a FET to spin the motor.
      Valve closed (stand by state): Input changes to 1. Output to fet must change to 0 directly so the motor stops.

      Instead of sending on or off commands, i want to send a "Turn on for XXX minutes commands". The reason for this is that the water will always turn off. Even if the controler crashes or the transmission fails.

      Additionally i want the status of the valves to be available in the controller. Also this system will run on 2 AA batteries, so the code needs to be efficient. I'm planing on using a 3V Pro Mini

      I already build a demo setup on a breadboard using a Nano V3 some LED's and some switches.

      No i just needs some advice on where to start. Is there a sketch that is a good base for this? Also, can you guys recommend "a function from the library" that can sent a "go on for X seconds" command and is compatible with Domoticz?

      Your help is very appreciated!

      0_1460060338169_IMG_20160407_221316869 (1).jpg

      posted in My Project
      SuperKris
      SuperKris
    • RE: Ethernet vs Serial gateway performance.

      I received most most of the hardware i ordered and did a couple of simple builds this evening.

      First i build the serial gateway. I used a nano clone with a standard nRF24L01+ module. Installed the regular arduino software with the MySensors 1.5.4 library, and used the standard serial gateway example. It was a very easy 5 seconds install in Domoticz, and the gateway was directly recognized as "MySensors Gateway USB Version: 1.5.4"

      Next i build a humidity sensor and a relay actuator. Both on nano clones with a standard example sketch. At first they dint show up, but i made a couple of faults and had a bad quality power supply. After correcting them they showed up in domoticz, and seem to work really well.

      I have no experience with Arduino, or MySensors, but i managed to build the gateway and 2 sensors in about 2 hours. I'm really very impressed with the quality and simplicity of the system so far!

      But to get back to the discussion; As i mentioned the serial gateway shows up as version 1.5.4. Maybe i understand this wrong, but this seems to be the most up to date version right? If so maybe the serial gateway is updated pretty well too, and the updating is no longer a issue.

      It seems to work very good on the USB of my raspberry, so currently i dont see any downside compared to a ethernet gateway. Am i overlooking something?

      The way i see it, the serial gateway is:

      • Much cheaper (Just a nano and a nRF24L01+ module)
      • Much smaller
      • Used less energie
      • Needs much less configuration

      I have a a W5100 ethernet shield and a Uno laying on my desk here, so if there is any advantage, i can build it in a sec.

      Any advise here?

      posted in Domoticz
      SuperKris
      SuperKris
    • RE: Slim Node scene controller/ keypad

      Hi AWI,

      Real nice design with all the small hardware. I have a tip for you on how you can make a very simple custom design membrane keypad.

      I used to work with POS scales. Most of the older designs had membrane keyboards. We fitted custom designs with the customers SKU's just by printing a new keyboard on plain paper. Then we used Sticky Laminating slides like these to seal the design and paste it to your keyboard.

      These sheets should not cost more than 1~2 $ per A4 sheet. Cold seal versions should be available, but most work with a machine. These machines van be found for approx 20,- $

      This way you should be able to build any custom layout if you have the MSpaint skills!

      posted in My Project
      SuperKris
      SuperKris
    • RE: Ethernet vs Serial gateway performance.

      @alexsh1

      So what kind of updates do these gateways get? Are these needed to improve stability and security? If yes, its understandable that the ethernet gateway needs more updates.

      If the updates bring new functionality and compatibility for the gateways, it's of course a very good reason to those the version that gets the most updates.

      If i design a new sensor, or copy a new design, what part of the software will be responsible for the sensor to show up in domoticz?

      • Does the gateway runs software that needs to be compatible with the sensor? So if i design a new sensor, lets say a weight scale, will the gateway process units in KG?
      • I run domoticz on my Raspberry with Jessie. Do i need to add new code or software to the Raspberry to work, or doesn't the raspberry run any mysensor software at all? (Just the serial USB software)
      • Will domotics be responsible to recognize the type of sensor? So will new type of sensor require a update or heavy customization on the build-in mysensor software?

      Depending on what part of the software handles what, it can be very important to take the gateway with the most updates.

      posted in Domoticz
      SuperKris
      SuperKris
    • RE: Ethernet vs Serial gateway performance.

      I have Domoticz with a RFlink (433mhz kit with aurel transiever on a arduino mega). Its connected to my raspberry pi 2 with Jessie trough USB. This works great. Domoticz always sees the RFlink kit, and communication works flawless.

      After reading al lot about mysensors i ordered a whole lot of of arduino and nRF24L01stuff. After reading this topic, i still dont see any real reasons for choosing USB(serial) or Ethernet.

      • I will place my mysensors gateway next to my Raspberry with Jessie
      • For not i only want to acces my nRF24L01 mysensor network with Domoticz
      • Power usage should be as low as possible
      • Connecting the gateway with Domoticz should be as plug and play as possible
      • I dont care about the extra costs of a ethernet gateway

      Next to the above, i have a small preference for a USB gateway, so i dont have to be carefull with IP addresses, configs, etc.

      What are the advantages or disadvantages between a USB(serial) gateway, and a Ethernet gateway? I'm planning to use a Arduino nano, or a UNO.

      Your advice is very welcome!

      posted in Domoticz
      SuperKris
      SuperKris