Navigation

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

    Meister_Petz

    @Meister_Petz

    9
    Reputation
    40
    Posts
    878
    Profile views
    1
    Followers
    0
    Following
    Joined Last Online

    Meister_Petz Follow

    Best posts made by Meister_Petz

    • Multisensor Multiactuator Sketch / Testboard - tested with FHEM Controller

      Hi,

      because I needed a test board with lots of sensors and getting used to do MySensor Sketches as well as FHEM Controller configuration. This is what I came up with:

      My Testboard includes:

      Sensors:

      • Temperature - Thermoresistor - PIN A3
      • Temperature - Dallas DS1820 - PIN 6
      • Lightlevel - Photoresistor - PIN A0

      Switches:

      • 2x Pushbuttons - PIN 5 and A4
      • Magnet Switch - PIN 7

      Actuators:
      The Actuators can be switched on normally (by sending 0 or 1) or can do something predifined (by sending 2 or 3).

      • 2x LEDs - PIN 3 and PIN 4
      • Piezo Buzzer - PIN A5

      This is how it looks:
      Alt text

      Alt text

      The MySensors Code:
      The code is very simple, to make it easy for beginners like me, making adjustments and understanding what happens.

          #include <MySensor.h>
          #include <SPI.h>
          MySensor gw;
          
          // Child ID s - Triggers - Buttons, Motion Sensors...
          #define TRIGGER1_ID 1 // Trigger 1
          #define TRIGGER2_ID 2 // Trigger 2
          #define TRIGGER3_ID 3 // Trigger 3
          /*
          #define TRIGGER4_ID 4 // Trigger 4
          #define TRIGGER5_ID 5 // Trigger 5
          #define TRIGGER6_ID 6 // Trigger 6
          #define TRIGGER7_ID 7 // Trigger 7 
          #define TRIGGER8_ID 8 // Trigger 8
          #define TRIGGER9_ID 9 // Trigger 9
          */
          
          // Child ID s - Actuators - Relays, LEDs,...
          #define ACTUATOR1_ID 11 // Actuator 1 - LED Orange
          #define ACTUATOR2_ID 12 // Actuator 2 - LED Red
          #define ACTUATOR3_ID 13 // Actuator 3 - PIEZO
          /*
          #define ACTUATOR4_ID 14 // Actuator 4
          #define ACTUATOR5_ID 15 // Actuator 5
          #define ACTUATOR6_ID 16 // Actuator 6
          #define ACTUATOR7_ID 17 // Actuator 7 
          #define ACTUATOR8_ID 18 // Actuator 8
          #define ACTUATOR9_ID 19 // Actuator 9
          */
          
          // Child ID s - Continuous Sensors - Temperature Sensors, Lightlevel Sensors,...
          #define SENSOR1_ID 21 // Sensor 1
          #define SENSOR2_ID 22 // Sensor 2
          #define SENSOR3_ID 23 // Sensor 3
          /*
          #define SENSOR4_ID 24 // Sensor 4
          #define SENSOR5_ID 25 // Sensor 5
          #define SENSOR6_ID 26 // Sensor 6
          #define SENSOR7_ID 27 // Sensor 7
          #define SENSOR8_ID 28 // Sensor 8
          #define SENSOR9_ID 29 // Sensor 9
          */
          
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          // DEFINITIONS
          //-----------------------------------------------------------------------------------------------------------
          
            //------------------------------------------------------------------------
            // Triggers - Triggers - Triggers - Triggers - Triggers - Triggers
            //------------------------------------------------------------------------
            // DEFINITIONS - Push Buttons, Door Sensors,...
            #include <Bounce2.h>
            
            // Trigger PINS - Digital PIN -> Button -> GND
              #define TRIGGER1_PIN  5  
              #define TRIGGER2_PIN  18 // A4  
              #define TRIGGER3_PIN  7
              /*
              #define TRIGGER4_PIN  7
              #define TRIGGER5_PIN  7
              #define TRIGGER6_PIN  7
              #define TRIGGER7_PIN  7
              #define TRIGGER8_PIN  7
              #define TRIGGER9_PIN  7
              */
          
            // Bounce 
              Bounce debouncer1 = Bounce(); 
              Bounce debouncer2 = Bounce();
              Bounce debouncer3 = Bounce();
              /*
              Bounce debouncer4 = Bounce(); 
              Bounce debouncer5 = Bounce();
              Bounce debouncer6 = Bounce();
              Bounce debouncer7 = Bounce(); 
              Bounce debouncer8 = Bounce();
              Bounce debouncer9 = Bounce();
              */
            
            // MyMessage
              MyMessage msg01(TRIGGER1_ID,V_TRIPPED);
              MyMessage msg02(TRIGGER2_ID,V_TRIPPED);
              MyMessage msg03(TRIGGER3_ID,V_TRIPPED);
              /*
              MyMessage msg04(TRIGGER4_ID,V_TRIPPED);
              MyMessage msg05(TRIGGER5_ID,V_TRIPPED);
              MyMessage msg06(TRIGGER6_ID,V_TRIPPED);
              MyMessage msg07(TRIGGER7_ID,V_TRIPPED);
              MyMessage msg08(TRIGGER8_ID,V_TRIPPED);
              MyMessage msg09(TRIGGER9_ID,V_TRIPPED);
              */
          
          
            // Some Variables
              int oldTrigValue1=-1;
              int oldTrigValue2=-1;
              int oldTrigValue3=-1;
              /*
              int oldTrigValue4=-1;
              int oldTrigValue5=-1;
              int oldTrigValue6=-1;
              int oldTrigValue7=-1;
              int oldTrigValue8=-1;
              int oldTrigValue9=-1;
              */
              
              
            //------------------------------------------------------------------------
            // Actuators - Actuators - Actuators - Actuators - Actuators - Actuators
            //------------------------------------------------------------------------
            // DEFINITIONS - LEDs, Relays, ...
            
            // Actuators PINS - DIGITAL PIN to Actuator
              #define ACTUATOR1_PIN  3 
              #define ACTUATOR2_PIN  4
              #define ACTUATOR3_PIN  19
              /*
              #define ACTUATOR1_PIN  7 
              #define ACTUATOR2_PIN  7
              #define ACTUATOR3_PIN  7
              #define ACTUATOR1_PIN  7 
              #define ACTUATOR2_PIN  7
              #define ACTUATOR3_PIN  7
              */
              
              #define ACTUATOR_ON 1
              #define ACTUATOR_OFF 0
              
              bool state;
              
            //------------------------------------------------------------------------
            // Sensors - Sensors - Sensors - Sensors - Sensors - Sensors - Sensors
            //------------------------------------------------------------------------
            // DEFINITIONS - Temperatur, Humidity, Lightlevel,...
            
            // Sensor PINS 
              #define SENSOR1_PIN  A3 // AnalogTemp on A3
              #define SENSOR2_PIN  6 // Digi
              #define SENSOR3_PIN  A0 // LightLevel Sensor
              /*
              #define SENSOR4_PIN  3
              #define SENSOR5_PIN  3
              #define SENSOR6_PIN  3
              #define SENSOR7_PIN  3
              #define SENSOR8_PIN  3
              #define SENSOR9_PIN  3
              */
              
            // MyMessage V_TEMP, V_LIGHT_LEVEL, ... depending on Sensor Type
              MyMessage msg11(SENSOR1_ID,V_TEMP);
              MyMessage msg12(SENSOR2_ID,V_TEMP);
              MyMessage msg13(SENSOR3_ID,V_LIGHT_LEVEL);
              /*
              MyMessage msg14(SENSOR4_ID,V_TEMP);
              MyMessage msg15(SENSOR5_ID,V_TEMP);
              MyMessage msg16(SENSOR6_ID,V_TEMP);
              MyMessage msg17(SENSOR7_ID,V_TEMP);
              MyMessage msg18(SENSOR8_ID,V_TEMP);
              MyMessage msg19(SENSOR9_ID,V_TEMP);
              */
              
              // Interval for each Sensor Read (number of loops) 1000000 = ca. 60 Sec - Adruino Nano ATmega 328
                long int sensorInterval1 = 100000;
                long int sensorInterval2 = 100000;
                long int sensorInterval3 = 100000;
                /*
                long int sensorInterval4 = 1000000;
                long int sensorInterval5 = 1000000;
                long int sensorInterval6 = 1000000;
                long int sensorInterval7 = 1000000;
                long int sensorInterval8 = 1000000;
                long int sensorInterval9 = 1000000;
                */
              
              // Special Config for each Sensor
                // SENSOR 1
                // SENSOR 2
                  // Dallas Temp Sensor
                  #include <OneWire.h>
                  #include <DallasTemperature.h>      
                  OneWire oneWire(SENSOR2_PIN);
                  DallasTemperature sensors(&oneWire);
                  boolean receivedConfig = false;
                  boolean metric = true; 
                
                // SENSOR 3
                // SENSOR 4
                // SENSOR 5
                // SENSOR 6
                // SENSOR 7
                // SENSOR 8
                // SENSOR 9
              
              //for sending only if value changed  
              float lastRead1;
              float lastRead2;
              float lastRead3;
              float lastRead4;
              float lastRead5;
              float lastRead6;
              float lastRead7;
              float lastRead8;
              float lastRead9;
              
              //for loops
              long int sI1 = sensorInterval1;
              long int sI2 = sensorInterval2;
              long int sI3 = sensorInterval3;
              /*
              long int sI4 = sensorInterval4;
              long int sI5 = sensorInterval5;
              long int sI6 = sensorInterval6;
              long int sI7 = sensorInterval7;
              long int sI8 = sensorInterval8;
              long int sI9 = sensorInterval9;
              */
            
          
          
              
            
          
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          // VOID SETUP - VOID SETUP - VOID SETUP - VOID SETUP - VOID SETUP
          //-----------------------------------------------------------------------------------------------------------
          
           void setup()  
          {  
            gw.begin(incomingMessage, AUTO, true);
          
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("3But.2Led.1DigTemp.1LightSens", "1.4.1");
          
            //------------------------------------------------------------------------
            // Triggers - Triggers - Triggers - Triggers - Triggers - Triggers
            //------------------------------------------------------------------------ 
            // VOID SETUP
            
                pinMode(TRIGGER1_PIN,INPUT);
                pinMode(TRIGGER2_PIN,INPUT);
                pinMode(TRIGGER3_PIN,INPUT);
                /*
                pinMode(TRIGGER4_PIN,INPUT);
                pinMode(TRIGGER5_PIN,INPUT);
                pinMode(TRIGGER6_PIN,INPUT);
                pinMode(TRIGGER7_PIN,INPUT);
                pinMode(TRIGGER8_PIN,INPUT);
                pinMode(TRIGGER9_PIN,INPUT);
                */
              
              // Activate internal pull-up
                digitalWrite(TRIGGER1_PIN,HIGH);
                digitalWrite(TRIGGER2_PIN,HIGH);
                digitalWrite(TRIGGER3_PIN,HIGH);
                /*
                digitalWrite(TRIGGER4_PIN,HIGH);
                digitalWrite(TRIGGER5_PIN,HIGH);
                digitalWrite(TRIGGER6_PIN,HIGH); 
                digitalWrite(TRIGGER7_PIN,HIGH);
                digitalWrite(TRIGGER8_PIN,HIGH);
                digitalWrite(TRIGGER9_PIN,HIGH); 
                */
              
            
              // After setting up the button, setup debouncer
                debouncer1.attach(TRIGGER1_PIN);
                debouncer2.attach(TRIGGER2_PIN);
                debouncer3.attach(TRIGGER3_PIN);
                /*
                debouncer4.attach(TRIGGER4_PIN);
                debouncer5.attach(TRIGGER5_PIN);
                debouncer6.attach(TRIGGER6_PIN);
                debouncer7.attach(TRIGGER7_PIN);
                debouncer8.attach(TRIGGER8_PIN);
                debouncer9.attach(TRIGGER9_PIN);
                */
                
                debouncer1.interval(5);
                debouncer2.interval(5);
                debouncer3.interval(5);
                /*
                debouncer4.interval(5);
                debouncer5.interval(5);
                debouncer6.interval(5);
                debouncer7.interval(5);
                debouncer8.interval(5);
                debouncer9.interval(5);
                */
              
              // present all Triggers to Gateway
                gw.present(TRIGGER1_ID, S_DOOR);  
                gw.present(TRIGGER2_ID, S_DOOR);
                gw.present(TRIGGER3_ID, S_DOOR);
                /*
                gw.present(TRIGGER4_ID, S_DOOR);  
                gw.present(TRIGGER5_ID, S_DOOR);
                gw.present(TRIGGER6_ID, S_DOOR);
                gw.present(TRIGGER7_ID, S_DOOR);  
                gw.present(TRIGGER8_ID, S_DOOR);
                gw.present(TRIGGER9_ID, S_DOOR);
                */
                
            //------------------------------------------------------------------------
            // Actuators - Actuators - Actuators - Actuators - Actuators - Actuators
            //------------------------------------------------------------------------
            // VOID SETUP
          
                pinMode(ACTUATOR1_PIN, OUTPUT);
                pinMode(ACTUATOR2_PIN, OUTPUT);
                pinMode(ACTUATOR3_PIN, OUTPUT);
                /*
                pinMode(ACTUATOR4_PIN, OUTPUT);
                pinMode(ACTUATOR5_PIN, OUTPUT);
                pinMode(ACTUATOR6_PIN, OUTPUT);
                pinMode(ACTUATOR7_PIN, OUTPUT);
                pinMode(ACTUATOR8_PIN, OUTPUT);
                pinMode(ACTUATOR9_PIN, OUTPUT);
                */ 
                
              // present all Actuators to Gateway
                gw.present(ACTUATOR1_ID, S_LIGHT);
                gw.present(ACTUATOR2_ID, S_LIGHT);
                gw.present(ACTUATOR3_ID, S_LIGHT);
                /*
                gw.present(ACTUATOR4_ID, S_LIGHT);
                gw.present(ACTUATOR5_ID, S_LIGHT);
                gw.present(ACTUATOR6_ID, S_LIGHT);
                gw.present(ACTUATOR7_ID, S_LIGHT);
                gw.present(ACTUATOR8_ID, S_LIGHT);
                gw.present(ACTUATOR9_ID, S_LIGHT);
                */
                
              // FETCH old State and SET old state
                bool state1 = gw.loadState(ACTUATOR1_ID); digitalWrite(ACTUATOR1_ID, state1?ACTUATOR_ON:ACTUATOR_OFF);
                bool state2 = gw.loadState(ACTUATOR2_ID); digitalWrite(ACTUATOR2_ID, state2?ACTUATOR_ON:ACTUATOR_OFF);
                bool state3 = gw.loadState(ACTUATOR3_ID); digitalWrite(ACTUATOR3_ID, state3?ACTUATOR_ON:ACTUATOR_OFF);
                /*
                bool state4 = gw.loadState(ACTUATOR4_ID); digitalWrite(ACTUATOR4_ID, state4?ACTUATOR_ON:ACTUATOR_OFF);
                bool state5 = gw.loadState(ACTUATOR5_ID); digitalWrite(ACTUATOR5_ID, state5?ACTUATOR_ON:ACTUATOR_OFF);
                bool state6 = gw.loadState(ACTUATOR6_ID); digitalWrite(ACTUATOR6_ID, state6?ACTUATOR_ON:ACTUATOR_OFF);
                bool state7 = gw.loadState(ACTUATOR7_ID); digitalWrite(ACTUATOR7_ID, state7?ACTUATOR_ON:ACTUATOR_OFF);
                bool state8 = gw.loadState(ACTUATOR8_ID); digitalWrite(ACTUATOR8_ID, state8?ACTUATOR_ON:ACTUATOR_OFF);
                bool state9 = gw.loadState(ACTUATOR9_ID); digitalWrite(ACTUATOR9_ID, state9?ACTUATOR_ON:ACTUATOR_OFF);
                */
                
            //------------------------------------------------------------------------
            // Sensors - Sensors - Sensors - Sensors - Sensors - Sensors - Sensors
            //------------------------------------------------------------------------
            // VOID SETUP  
                
              // present all Sensors to Gateway - S_TEMP, S_LIGHT_LEVEL,... depending an SENSOR type
                gw.present(SENSOR1_ID, S_TEMP);
                gw.present(SENSOR2_ID, S_TEMP); 
                gw.present(SENSOR3_ID, S_LIGHT_LEVEL);
                /*
                gw.present(SENSOR4_ID, S_TEMP);
                gw.present(SENSOR5_ID, S_TEMP);
                gw.present(SENSOR6_ID, S_TEMP);
                gw.present(SENSOR7_ID, S_TEMP);
                gw.present(SENSOR8_ID, S_TEMP);
                gw.present(SENSOR9_ID, S_TEMP);
                */     
               
                
              // Special SETUP for each Sensor
                // SENSOR 1
                // SENSOR 2 - Dallas Temp Sensor
                  sensors.begin();
                
                // SENSOR 3
                // SENSOR 4
                // SENSOR 5
                // SENSOR 6
                // SENSOR 7
                // SENSOR 8
                // SENSOR 9
          }
          
          
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          // VOID LOOP - VOID LOOP - VOID LOOP - VOID LOOP - VOID LOOP - VOID LOOP
          //-----------------------------------------------------------------------------------------------------------
          
          //  Check if digital input has changed and send in new value
          void loop() 
          {
            gw.process();
            
            //------------------------------------------------------------------------
            // Triggers - Triggers - Triggers - Triggers - Triggers - Triggers
            //------------------------------------------------------------------------ 
            // LOOP
            
                debouncer1.update();
                debouncer2.update();
                debouncer3.update();
                /*
                debouncer4.update();
                debouncer5.update();
                debouncer6.update();
                debouncer7.update();
                debouncer8.update();
                debouncer9.update();
                */
              
              // Get the update value
                int value1 = debouncer1.read(); 
                int value2 = debouncer2.read();
                int value3 = debouncer3.read();
                /*
                int value4 = debouncer4.read(); 
                int value5 = debouncer5.read();
                int value6 = debouncer6.read();
                int value7 = debouncer7.read(); 
                int value8 = debouncer8.read();
                int value9 = debouncer9.read();
                */
           
              // Send in the new value - if value changed    
                if (value1 != oldTrigValue1) { gw.send(msg01.set(value1==LOW ? 1 : 0)); oldTrigValue1 = value1; }
                if (value2 != oldTrigValue2) { gw.send(msg02.set(value2==LOW ? 1 : 0)); oldTrigValue2 = value2; }
                if (value3 != oldTrigValue3) { gw.send(msg03.set(value3==LOW ? 1 : 0)); oldTrigValue3 = value3; }
                /*
                if (value4 != oldTrigValue4) { gw.send(msg04.set(value4==LOW ? 1 : 0)); oldTrigValue4 = value4; }
                if (value5 != oldTrigValue5) { gw.send(msg05.set(value5==LOW ? 1 : 0)); oldTrigValue5 = value5; }
                if (value6 != oldTrigValue6) { gw.send(msg06.set(value6==LOW ? 1 : 0)); oldTrigValue6 = value6; }
                if (value7 != oldTrigValue7) { gw.send(msg07.set(value7==LOW ? 1 : 0)); oldTrigValue7 = value7; }
                if (value8 != oldTrigValue8) { gw.send(msg08.set(value8==LOW ? 1 : 0)); oldTrigValue8 = value8; }
                if (value9 != oldTrigValue9) { gw.send(msg09.set(value9==LOW ? 1 : 0)); oldTrigValue9 = value9; }
                */
          
            //------------------------------------------------------------------------
            // Sensors - Sensors - Sensors - Sensors - Sensors - Sensors - Sensors
            //------------------------------------------------------------------------ 
            // LOOP
          
               // Sensor1 - Analog Temp
               if (sI1 == sensorInterval1){
                 sI1 = 0;
                 int sensorRead1 = analogRead(SENSOR1_PIN);
                 if (lastRead1 != sensorRead1){
                   float sensorCalc = (sensorRead1 / 10) - 45.5;
                   gw.send(msg11.set(sensorCalc,1));
                   lastRead1 = sensorRead1;
                 } 
               }
          
               // Sensor2 - Digital Temp Dallas
               if (sI2 == sensorInterval2){
                 sI2 = 0;
                 sensors.requestTemperatures();
                 float sensorRead2 = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(0):sensors.getTempFByIndex(0)) * 10.)) / 10.;
                 if (lastRead2 != sensorRead2){
                   gw.send(msg12.set(sensorRead2,1));
                   lastRead2 = sensorRead2;
                 }
               }
              
               // Sensor3 - Light Level
               if (sI3 == sensorInterval3){
                 sI3 = 0;
                 int sensorRead3 = analogRead(SENSOR3_PIN);
                 if (lastRead3 != sensorRead3){
                   gw.send(msg13.set(sensorRead3,1));
                   lastRead3 = sensorRead3;
                 }  
               }
               /*
               // Sensor4
               if (sI4 == sensorInterval4){
                 sI4 = 0;
                 // put here the read sensor function like:
                 // float sensorRead4 = analogRead(SENSOR4_PIN);
                 if (lastRead4 != sensorRead4){
                   gw.send(msg14.set(sensorRead4));
                   lastRead4 = sensorRead4;
                 }
               }
               // Sensor5
               // Sensor6
               // Sensor7
               // Sensor8
               // Sensor9
               */
               
              sI1++;
              sI2++;
              sI3++;
              /*
              sI4++;
              sI5++;
              sI6++;
              sI7++;
              sI8++;
              sI9++;
              */
          } 
          
          
          
          //------------------------------------------------------------------------
          //------------------------------------------------------------------------
          //------------------------------------------------------------------------
          // VOID INCOMING MESSAGE - VOID INCOMING MESSAGE - VOID INCOMING MESSAGE
          //------------------------------------------------------------------------
          
          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");
            }
            
            //------------------------------------------------------------------------
            // Actuators - Actuators - Actuators - Actuators - Actuators - Actuators
            //------------------------------------------------------------------------
            // VOID INCOMING MESSAGE
              if (message.type==V_LIGHT) {
                int actPin;
                      
                if (message.sensor == 11){ actPin = ACTUATOR1_PIN; }
                if (message.sensor == 12){ actPin = ACTUATOR2_PIN; }
                if (message.sensor == 13){ actPin = ACTUATOR3_PIN; }
                 /*
                if (message.sensor == 14){ actPin = ACTUATOR4_PIN; }
                if (message.sensor == 15){ actPin = ACTUATOR5_PIN; }
                if (message.sensor == 16){ actPin = ACTUATOR6_PIN; }
                if (message.sensor == 17){ actPin = ACTUATOR7_PIN; }
                if (message.sensor == 18){ actPin = ACTUATOR8_PIN; }
                if (message.sensor == 19){ actPin = ACTUATOR9_PIN; }
                */
                
                  //------------------------------------------------------------------------
                  // switch Actuator normally
                  //------------------------------------------------------------------------
                    if (message.getInt() < 2) {
                      state = message.getBool();
          
                      digitalWrite(actPin, state?ACTUATOR_ON:ACTUATOR_OFF);
                      gw.saveState(message.sensor, state);
                      //Serial.print("normal Change for Actor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool());
                    }
                  
                  //------------------------------------------------------------------------
                  // switch Actuator predifined
                  //------------------------------------------------------------------------
                  
                    if (message.getInt() == 2){
                      // BLINK 1x
                      digitalWrite(actPin, LOW);
                      delay(2000);
                      digitalWrite(actPin, HIGH);
                      delay(500);
                      digitalWrite(actPin, LOW);
                      delay(2000);
                  
                      // set state back to old state
                      gw.loadState(message.sensor);
                      digitalWrite(actPin, state?ACTUATOR_ON:ACTUATOR_OFF);
                      MyMessage msgTmp(message.sensor,V_LIGHT);
                      gw.send(msgTmp.set(state));
                    }
                    
                    if (message.getInt() == 3){
                      // BLINK 2x
                      digitalWrite(actPin, LOW);
                      delay(2000);
                      digitalWrite(actPin, HIGH);
                      delay(500);
                      digitalWrite(actPin, LOW);
                      delay(500);
                      digitalWrite(actPin, HIGH);
                      delay(500);
                      digitalWrite(actPin, LOW);
                      delay(2000);
                  
                      // set state back to old state
                      gw.loadState(message.sensor);
                      digitalWrite(actPin, state?ACTUATOR_ON:ACTUATOR_OFF);
                      MyMessage msgTmp(message.sensor,V_LIGHT);
                      gw.send(msgTmp.set(state));
                    }
                 
              }
          
          }
      

      Within FHEM Controller:

      Alt text

      The FHEM.cfg Code:
      And some example of my FHEM.cfg, how to use it:
      #------------------------------------------------------#
      # Testboard #
      #------------------------------------------------------#
      define Testboard MYSENSORS_DEVICE 100
      attr Testboard IODev gateway
      attr Testboard mapReading_brightness23 23 brightness
      attr Testboard mapReading_switch11 11 switch
      attr Testboard mapReading_switch12 12 switch
      attr Testboard mapReading_switch13 13 switch
      attr Testboard mapReading_temperature21 21 temperature
      attr Testboard mapReading_temperature22 22 temperature
      attr Testboard mapReading_tripped1 1 tripped
      attr Testboard mapReading_tripped2 2 tripped
      attr Testboard mapReading_tripped3 3 tripped
      attr Testboard mode repeater
      attr Testboard room MySensorsTB
      attr Testboard setCommands on1:switch11:on off1:switch11:off on2:switch12:on off2:switch12:off on3:switch13:on off3:switch13:off ack11:switch11:2 ack12:switch11:3 ack21:switch12:2 ack22:switch12:3 ack31:switch13:2 ack32:switch13:3
      attr Testboard setReading_switch11 on,off
      attr Testboard setReading_switch12 on,off
      attr Testboard setReading_switch13 on,off
      attr Testboard version 1.4.1

          #------------------------------------------------------#
          # Actuators                                            #
          #------------------------------------------------------#
          
           # Orange LED
           define OrangeLED dummy
            attr OrangeLED group Schalter
            attr OrangeLED room MySensorsTB
            attr OrangeLED setList on off 2 3
            attr OrangeLED webCmd on:off:2:3
            # normal Switch on
            define OrangeLED1 notify OrangeLED:on set Testboard on1
            define OrangeLED0 notify OrangeLED:off set Testboard off1
            # predefined Switching
            define OrangeLEDack1 notify OrangeLED:2 set Testboard ack11
            define OrangeLEDack2 notify OrangeLED:3 set Testboard ack12
          
           # Red LED
           define RedLED dummy
            attr RedLED group Schalter
            attr RedLED room MySensorsTB
            attr RedLED setList on off 2 3
            attr RedLED webCmd on:off:2:3
            # normal Switch on
            define RedLED1 notify RedLED:on set Testboard on2
            define RedLED2 notify RedLED:off set Testboard off2
            # predefined Switching
            define RedLEDack1 notify RedLED:2 set Testboard ack21
            define RedLEDack2 notify RedLED:3 set Testboard ack22
          
           # PIEZO
           define PIEZO dummy
            attr PIEZO group Schalter
            attr PIEZO room MySensorsTB
            attr PIEZO setList on off 2 3
            attr PIEZO webCmd on:off:2:3
            # normal Switch on
            define PIEZO1 notify PIEZO:on set Testboard on3
            define PIEZO2 notify PIEZO:off set Testboard off3
            # predefined Switching
            define PIEZOack1 notify PIEZO:2 set Testboard ack31
            define PIEZOack2 notify PIEZO:3 set Testboard ack32
          
          #------------------------------------------------------#
          # Sensordata                                           #
          #------------------------------------------------------#
          # Analog Temperature Sensor
          define AnalogTemp dummy
            attr AnalogTemp event-on-change-reading state
            attr AnalogTemp room MySensorsTB
            attr AnalogTemp group Sensors
            # get all 30 Sec. Temp from Testboard
            define AnalogTempCopy at +*00:00:30 { my $d= ReadingsVal("Testboard","temperature21",0);; fhem("set AnalogTemp $d");;}
            # in eigene Log Datei schreiben
            define AnalogTempLog FileLog ./log/Log_AnalogTemp-%Y-%m-%d.log AnalogTemp
              attr AnalogTempLog group SensorLogs
              attr AnalogTempLog logtype text
              attr AnalogTempLog room MySensorsTB
          
          define DigiTemp dummy
            attr DigiTemp event-on-change-reading state
            attr DigiTemp room MySensorsTB
            attr DigiTemp group Sensors
            # get all 30 Sec. Temp from Testboard
            define DigiTempCopy at +*00:00:30 { my $d= ReadingsVal("Testboard","temperature22",0);; fhem("set DigiTemp $d");;}
            # in eigene Log Datei schreiben
            define DigiTempLog FileLog ./log/Log_DigiTemp-%Y-%m-%d.log DigiTemp
              attr DigiTempLog group SensorLogs
              attr DigiTempLog logtype text
              attr DigiTempLog room MySensorsTB
          
          define LightLevel dummy
            attr LightLevel event-on-change-reading state
            attr LightLevel room MySensorsTB
            attr LightLevel group Sensors
            # get all 30 Sec. Temp from Testboard
            define LightLevelCopy at +*00:00:30 { my $d= ReadingsVal("Testboard","brightness23",0);; fhem("set LightLevel $d");;}
            # in eigene Log Datei schreiben
            define LightLevelLog FileLog ./log/Log_LightLevel-%Y-%m-%d.log LightLevel
              attr LightLevelLog group SensorLogs
              attr LightLevelLog logtype text
              attr LightLevelLog room MySensorsTB
      posted in My Project
      Meister_Petz
      Meister_Petz
    • RE: TX RX ERR - LED for Sensors

      now without delay() but with LEDs are on for a number of loops (millis()) didn't work smoothly)

         #include <MySensor.h>
          #include <SPI.h>
          MySensor gw;
          
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          // DEFINITIONS
          //-----------------------------------------------------------------------------------------------------------
          
            //------------------------------------------------------------------------
            // POWER RX TX LED
            //------------------------------------------------------------------------
            // Definitions 
            
                 // choose one Mode
                   // All with one LED => LEDMode = 1
                   // POWER seperate   => LEDMode = 2
                   // only TX and RX   => LEDMode = 3 
                   // 3 seperate LEDS  => LEDMode = 4
                   // RX TX combined, no PWR LED  => LEDMode = 5
                   // for a power LED, I would connect a LED between GND and VCC in general.
                   
                 const int LEDMode = 5; // 2 3 4 5 (0 is off)
                 
                 // does not need to be modified
                 // Mode 1
                 #define LEDPwrRXTXPin 4
                 
                 // Mode 2
                 #define LEDPwrPin1 3
                 #define LEDRXTXPin 4
                 
                 // Mode 3
                 #define LEDRXPin 3
                 #define LEDTXPin 4
                 
                 // Mode 4
                 #define LEDPwrPin2 14
                 #define LEDRXPin2 3
                 #define LEDTXPin2 4
                 
                 // Mode 5
                 #define LEDRXTXPin2 4
        
                 int blinkRX = 0;
                 int blinkTX = 0;
                 int blinkLoopTX = 0;
                 int blinkOffTX = 500; // number of Loops until blink is off
                 int blinkLoopRX = 0;
                 int blinkOffRX = 500; // number of Loops until blink is off
             
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          // VOID SETUP - VOID SETUP - VOID SETUP - VOID SETUP - VOID SETUP
          //-----------------------------------------------------------------------------------------------------------
          
           void setup()  
          {  
            gw.begin(incomingMessage, AUTO, true);
                
            //------------------------------------------------------------------------
            // POWER RX TX LED
            //------------------------------------------------------------------------
            // VOID SETUP
                // does not need to be modified
                 // All with one LED => LEDMode = 1
                 if (LEDMode == 1){
                   pinMode(LEDPwrRXTXPin, OUTPUT);
                 }
                   
                 // POWER seperate => LEDMode = 2
                 if (LEDMode == 2){
                   pinMode(LEDPwrPin1, OUTPUT);
                   pinMode(LEDRXTXPin, OUTPUT);
                 }
                   
                 // only TX and RX => LEDMode = 3
                 if (LEDMode == 3){
                   pinMode(LEDRXPin, OUTPUT);
                   pinMode(LEDTXPin, OUTPUT);
                 }
                   
                 // 3 seperate LEDS => LEDMode = 4
                 if (LEDMode == 4){
                   pinMode(LEDPwrPin2, OUTPUT);
                   pinMode(LEDTXPin, OUTPUT);
                   pinMode(LEDRXPin, OUTPUT);
                 }
                 
                 // no POWERLEd only RX TX combined => LEDMode = 5
                 if (LEDMode == 5){
                   pinMode(LEDRXTXPin2, OUTPUT);
                 }
          }
         
          
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          //-----------------------------------------------------------------------------------------------------------
          // VOID LOOP - VOID LOOP - VOID LOOP - VOID LOOP - VOID LOOP - VOID LOOP
          //-----------------------------------------------------------------------------------------------------------
          
          //  Check if digital input has changed and send in new value
          void loop() 
          {
            gw.process();
            
            //------------------------------------------------------------------------
            // POWER RX TX LED
            //------------------------------------------------------------------------
            // VOID LOOP
            // does not need to be modified
            
            if (LEDMode == 1){
              if (blinkTX == 0 && blinkRX == 0){digitalWrite(LEDPwrRXTXPin,HIGH);}
              if (blinkTX == 1 || blinkRX == 1){
                digitalWrite(LEDRXTXPin, LOW);
                if (blinkLoopTX >= blinkOffTX){ blinkTX = 0; blinkRX = 0; blinkLoopTX = 0;}
                blinkLoopTX++;
              }
            }
            
            if (LEDMode == 2){
              digitalWrite(LEDPwrPin1,HIGH);
              if (blinkTX == 0 && blinkRX == 0){digitalWrite(LEDRXTXPin,LOW);}
              if (blinkTX == 1 || blinkRX == 1){
                digitalWrite(LEDRXTXPin, HIGH);
                if (blinkLoopTX >= blinkOffTX){ blinkTX = 0; blinkRX = 0; blinkLoopTX = 0;}
                blinkLoopTX++;
              }
            }
            
            if (LEDMode == 3){
              digitalWrite(LEDRXPin,LOW);
              if (blinkTX == 0){digitalWrite(LEDTXPin,LOW);}
              if (blinkTX == 1){
                digitalWrite(LEDTXPin, HIGH);
                if (blinkLoopTX >= blinkOffTX){ blinkTX = 0; blinkLoopTX = 0;}
                blinkLoopTX++;
              }
              if (blinkRX == 0){digitalWrite(LEDRXPin,LOW);}
              if (blinkRX == 1){
                digitalWrite(LEDRXPin, HIGH);
                if (blinkLoopRX >= blinkOffRX){ blinkRX = 0; blinkLoopRX = 0;}
                blinkLoopRX++;
              }
            }
            
            if (LEDMode == 4){
              digitalWrite(LEDPwrPin2,HIGH);
              if (blinkTX == 0){digitalWrite(LEDTXPin2,LOW);}
              if (blinkTX == 1){
                digitalWrite(LEDTXPin2, HIGH);
                if (blinkLoopTX >= blinkOffTX){ blinkTX = 0; blinkLoopTX = 0;}
                blinkLoopTX++;
              }
              if (blinkRX == 0){digitalWrite(LEDRXPin2,LOW);}
              if (blinkRX == 1){
                digitalWrite(LEDRXPin2, HIGH);
                if (blinkLoopRX >= blinkOffRX){ blinkRX = 0; blinkLoopRX = 0;}
                blinkLoopRX++;
              }
              
            }
            if (LEDMode == 5){
              if (blinkTX == 0 && blinkRX == 0){digitalWrite(LEDRXTXPin2,LOW);}
              if (blinkTX == 1 || blinkRX == 1){
                digitalWrite(LEDRXTXPin2, HIGH);
                if (blinkLoopTX >= blinkOffTX){ blinkTX = 0; blinkRX = 0; blinkLoopTX = 0;}
                blinkLoopTX++;
              }
            }
            
            //------------------------------------------------------------------------
            // YOUR CODE
            //------------------------------------------------------------------------
            // VOID LOOP
        
            // !!! at  gw.send(msg.set...); there also needs to be a - blinkTX = 1; - !!! 
            
          }
         
          //------------------------------------------------------------------------
          //------------------------------------------------------------------------
          //------------------------------------------------------------------------
          // VOID INCOMING MESSAGE - VOID INCOMING MESSAGE - VOID INCOMING MESSAGE
          //------------------------------------------------------------------------
          
          void incomingMessage(const MyMessage &message) {
            //------------------------------------------------------------------------
            // POWER RX TX LED
            //------------------------------------------------------------------------
            // INCOMING MESSAGE
            blinkRX = 1;
           
            //------------------------------------------------------------------------
            // YOUR CODE
            //------------------------------------------------------------------------
            // INCOMING MESSAGE
          
          }
      posted in Hardware
      Meister_Petz
      Meister_Petz
    • RE: My 2AA battery sensor

      ok, I did some testing and succeeded:

      This is the important part of the Arduino code:

      String allSens = String(sensor1) + " " + String(sensor2);
      gw.send(msg1.set(allSens.c_str()));
      

      This is the FHEM code:

      define Sensor MYSENSORS_DEVICE 20
      attr Sensor IODev MSGateway
      attr Sensor mapReading_brightness1 1 brightness
      attr Sensor mode node
      attr Sensor version 1.5
      attr Sensor userReadings Bat Deg
      
      # split and copy to userReadings
      define Sensor.copy at +*00:02:00 {my $a = ReadingsVal("Sensor","brightness1",1);; my @b = split(/\ /,$a);; fhem("setreading Sensor Bat $b[0]");; fhem("setreading Sensor Grad $b[1]");;}
      

      P.S.: when I had this in fhem.cfg I had to use @@ instead of only one @

      This is my complete Arduino code for a Battery Sensor with Dallas Temp:

        
      #include <MySensor.h>
      #include <SPI.h>
      
      #define SketchName "Sensor-send-all"
      #define SketchVer "1.2"
      #define NodeID 20
      
      unsigned long SleepTime = 828523; // 55234 = 1 Minute --- 828523 = 15 Minuten
        
      MySensor gw;
      
      // this is the one which sends everything
      #define SENSOR1_ID 1 // Sensor 1 - allAtOnceMessage
          
        //------------------------------------------------
        // Sensor PINS 
          #define SENSOR1_PIN  A0 // BattLevel
          #define SENSOR2_PIN  6  // Dallas
            
        // MyMessage V_TEMP, V_LIGHT_LEVEL, ... depending on Sensor Type
           MyMessage msg1(SENSOR1_ID,V_LIGHT_LEVEL); // Sensor 5 - allAtOnceMessage
      
        //------------------------------------------------
        // Dallas Temp
           #include <OneWire.h>
           #include <DallasTemperature.h>      
           OneWire oneWire(SENSOR2_PIN);
           DallasTemperature sensors(&oneWire);
           boolean receivedConfig = false;
               
           float firstRun = 1;
           boolean metric = true;
        
      void setup()  
        {  
          // use the 1.1 V internal reference
          analogReference(INTERNAL);
          delay(500); // Allow time for radio if power used as reset <<<<<<<<<<<<<< Experimented with good result 
        
          gw.begin(NULL, NodeID, false);
        
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo(SketchName, SketchVer);
              
          // present all Sensors to Gateway - S_TEMP, S_LIGHT_LEVEL,... depending an SENSOR type
          gw.present(SENSOR1_ID, S_LIGHT_LEVEL);     
              
          sensors.begin();  
        }
        
        
      void loop() 
        {
          gw.process();
      
             // wait some time to get all parts powered up
             if (firstRun == 1){
                delay(5000);
                firstRun = 0;
             } else {
                delay(1000);
             }
             
             //----------------------
             // Sensor1 - Battery Voltage - Part 1
                int sensorRead10 = analogRead(SENSOR1_PIN); 
      
             //----------------------
             // Sensor2 - DAL
               sensors.requestTemperatures();
               int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
               gw.sleep(conversionTime);
               float sensorRead2 = static_cast<float>(static_cast<int>((metric?sensors.getTempCByIndex(0):sensors.getTempFByIndex(0)) * 10.)) / 10.;
      
             //----------------------
             // Sensor1 - Battery Voltage - Part 2
                int sensorRead11 = analogRead(SENSOR1_PIN);
                //Volt der Battery
                
                float sensorRead1 = (sensorRead10 + sensorRead11 + sensorRead12) / 3 * 0.0033;  // should be 0.003363075 my Batteries are different
                float test = sensorRead10;
      
      
             //----------------------
             // send all to fhem
                String allComb = String(sensorRead1) + " " + String(sensorRead2);
                gw.send(msg1.set(allComb.c_str()));
      
            gw.sleep(SleepTime);
        } 
        
       
      
      posted in My Project
      Meister_Petz
      Meister_Petz
    • NRF24L01+ with external antenna - don't work

      Hi,

      I have 2 of these NRF24L01+ with external antenna

      http://www.ebay.de/itm/310651702557

      if I connect them like the ones with onboard antenna I just get this message:
      "req node id"

      then nothing.

      if I connect the normal ones it works.

      any idea?

      Many Thanks

      Petz

      posted in Troubleshooting
      Meister_Petz
      Meister_Petz

    Latest posts made by Meister_Petz

    • ESP8266gateway with sensor

      Hi,

      I would like to use the ESP8266gateway standalone with a sensor. I used the ESP8266gateway sketch and it connects without problems to my controller, but I can't get it to send a message to the controller (FHEM).

      I made a very easy code, for testing. It would just be "light level" but in this case even without a sensor, just sending "100".

      /*
        */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
      #define MY_BAUD_RATE 9600
      
      // Enables and select radio type (if attached)
      //#define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      #define MY_GATEWAY_ESP8266
      
      #define MY_WIFI_SSID "this is the SSID"
      #define MY_WIFI_PASSWORD "And the password"
      
      // Enable UDP communication
      //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below
      
      // Set the hostname for the WiFi Client. This is the hostname
      // it will pass to the DHCP server if not static.
      #define MY_HOSTNAME "ESP8266_Greenhouse"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      //#define MY_IP_ADDRESS 192,168,178,87
      
      // If using static ip you can define Gateway and Subnet address as well
      //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
      //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // The port to keep open on node server mode
      #define MY_PORT 5003
      
      // How many clients should be able to connect to this gateway (default 1)
      //#define MY_GATEWAY_MAX_CLIENTS 2
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 10, 0, 78, 204
      //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org"
      
      // Set blinking period
      //#define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Led pins used if blinking feature is enabled above
      //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
      
      #include <MySensors.h>
      #define CHILD_ID_LIGHT 0
      
      MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      
      uint32_t WAIT_TIME = 1200; // Sleep time between reads (in milliseconds)
      
      
      
      void setup()
      {
      	
      }
      
      void presentation()
      {
        sendSketchInfo("GreenhouseWifiNode", "1.0");
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      }
      
      void loop()
      {
      	//Light
        int16_t lightLevel = 100;
        Serial.println(lightLevel);
        send(msgLight.set(lightLevel));
      
        wait(WAIT_TIME);
      }
      

      This is the serial output:

      connected with Eichenstrasse, channel 3
      dhcp client start...
      ip:10.0.78.206,mask:255.255.255.0,gw:10.0.78.1
      5137 GWT:TIN:CONNECTING...
      5165 GWT:TIN:IP: 10.0.78.206
      5196 MCO:BGN:STP
      5213 MCO:REG:NOT NEEDED
      5238 MCO:BGN:INIT OK,TSP=NA
      100
      100
      100
      100
      100
      100
      100
      100
      pm open,type:2 0
      100
      100
      100
      100
      ...
      

      Any ideas what I do wrong?

      Bildschirmfoto 2021-01-30 um 21.50.16.png

      posted in Hardware
      Meister_Petz
      Meister_Petz
    • RE: ESP8266 ... doesn't connect to sensors

      Good point! I use FHEM... the Gateway is connected... so FHEM maybe the Problem...

      posted in Troubleshooting
      Meister_Petz
      Meister_Petz
    • ESP8266 ... doesn't connect to sensors

      Hi,

      my WLAN Gateway (ESP8266) doesn't connect to sensors or the other way round.

      On the sensor side:
      In serial monitor my test sensor asks for an ID but there is no reply

      On the WLAN Gateway side:
      In serial monitor:

      • I can see the sensors broadcasts
      • I can see, that the gateway switches to inclusion mode, by the inc button
      • but no transfer to the sensors is sent out

      Any ideas?

      Many Thanks

      Petz

      posted in Troubleshooting
      Meister_Petz
      Meister_Petz
    • RE: Digital Poti on same Pins as NRF24L01+ how can I solve this?

      sorry... I'm blind...
      maybe I can change it here:

      int CS = 10;
      

      sorry again

      posted in Development
      Meister_Petz
      Meister_Petz
    • RE: Digital Poti on same Pins as NRF24L01+ how can I solve this?

      The Poti only uses SPI.h no other library is involved. And I don't find anything about PIN 10 in the mysensors.h. Where can I change that for the NRF24L01+?

      Thanks

      Petz

      posted in Development
      Meister_Petz
      Meister_Petz
    • Digital Poti on same Pins as NRF24L01+ how can I solve this?

      HI,

      I would like to use a digital poti (MCP 4131). It uses the SPI.h and PINs 10/11/13 which collides with the NRF24L01+ pins.

      How can I solve this?

      Many Thanks

      Petz

      posted in Development
      Meister_Petz
      Meister_Petz
    • Serial Gateway 1.5 - LEDs not working any more

      Hi,
      the leds at my SerialGateway are not working. No LED lights up when receceiving - trasmitting - inclusion mode. Is there something to be done with 1.5

      I tested with the blink sketch and all leds are fine.

      Many Thanks

      Petz

      posted in Development
      Meister_Petz
      Meister_Petz
    • RE: Node is sending - but no reads....

      Ok, in addition, I found out, that everything works fine if I let nodes talk to the gateway directly. If the nodes are behind repeaters (I tried 3 different ones) they can send alright but they don't receive reads.

      posted in Development
      Meister_Petz
      Meister_Petz
    • RE: How to receive time?

      @LastSamurai said:

      Define a variable at the start of your program and safe the time in the variable that can then be accessed from the main loop too.

      Many Thanks... obvious now...

      posted in Development
      Meister_Petz
      Meister_Petz
    • RE: How to receive time?

      Probably I was unclear. time is showing up nicely. But home can I get this variable back to be used in "void loop"?

      posted in Development
      Meister_Petz
      Meister_Petz