💬 OH 433Mhz Mysensors Bridge




  • Hardware Contributor

    I have just received two new (433 Mhz) switches that I will add to my network 🙂 I also just upgraded my serial gateway to use a PLNA+ module and an external power supply, which seems to make the whole network react a little faster too. I will post a update once its done. I might also design a proper pcb for this bridge, maybe even in combination with a gateway.


  • Hero Member

    @LastSamurai , thanks for the great work. I just built one of these and it is working great.

    If your controller accepts long scene numbers (like my Vera does), we have the option to present it as a scene controller, instead individual buttons. The scene number will be the number of the button pressed. That makes life easy to add new panels around the house.

    Bellow is the sketch I created, based on your example. I also added a short/long-press logic, so for example for a 3-button panel, 6 different scenes can be triggered.

    /*
      This is a gateway node between mysensors and 433Mhz devices. A 433Mhz receiver is connected to pin 3 (int 1).
      This works with any 433Mhz device (as long as rc-switch understands the protocol).
    
      This is based on the MySensors network: https://www.mysensors.org
      This uses the rc-switch library to detect button presses: https://github.com/sui77/rc-switch
    
      Written by Oliver Hilsky 07.03.2017
      Adjusted to Scene controller by Ricardo Vendrame  03.06.2017 
    */
    
    #define LONG_PRESS_OFFSET 10000000UL  // Offset for long-press
    #define LONG_PRESS_COUNT  5           // Number of messages for long-press
    
    #define MY_RADIO_NRF24
    //#define MY_NODE_ID 25
    #define MY_BAUD_RATE 115200
    #define MY_DEBUG    // Enables debug messages in the serial log
    #define VCC_PIN 5
    #define GND_PIN 2
    #define RECEIVER_PIN 3
    
    //#include <EEPROM.h>
    #include <SPI.h>
    #include <MyConfig.h>
    #include <MySensor.h>
    //#include <Vcc.h>
    #include <RCSwitch.h>
    
    MySensor gw; 
    MyMessage msgSceneOn( 0 , V_SCENE_ON ); 
    MyMessage msgSceneOff( 0, V_SCENE_OFF ); 
    
    RCSwitch wirelessSwitch = RCSwitch();
    
    // Short/long press control 
    unsigned long lastreceive, count; 
    
    // add the decimal codes for your switches here
    unsigned long received_val; 
    
    void presentation()
    {
       
    #ifdef MY_NODE_ID
      gw.begin(NULL, MY_NODE_ID, false);
    #else
      gw.begin(NULL,AUTO,false);
    #endif
    
      gw.sendSketchInfo("433 Wireless Gateway", "1.0");
      gw.present( 0 , S_SCENE_CONTROLLER );
    
    }
    
    void setup() {
      
      Serial.begin(MY_BAUD_RATE); 
    
      // Power to Radio... 
      pinMode( VCC_PIN , OUTPUT ); 
      pinMode( GND_PIN , OUTPUT ); 
      digitalWrite( GND_PIN , LOW ); 
      digitalWrite( VCC_PIN , HIGH ); 
    
      // mySensors startup
      presentation(); 
      
      // Enable 433 receiving 
      wirelessSwitch.enableReceive(RECEIVER_PIN-2);  // Receiver on interrupt 
      
      Serial.println("Started listening on pin 3 for incoming 433Mhz messages");
    
      lastreceive = millis(); 
      
    }
    
    void loop() {
    
      gw.process(); 
      
      if ( wirelessSwitch.available() ) {  
    
        if ( ( millis() - lastreceive ) <= 200 ) count ++;
          else count = 1; 
          
        received_val = wirelessSwitch.getReceivedValue();
        wirelessSwitch.resetAvailable();
    
        lastreceive = millis(); 
        //Serial.println( lastreceive ); 
        
      }
    
      if ( count >= LONG_PRESS_COUNT || 
       ( ( millis() - lastreceive ) > 200 && count > 0 ) ) {
        
        // Send scene ID to the gateway
        if ( count >= LONG_PRESS_COUNT ) 
           received_val += LONG_PRESS_OFFSET;
            
        gw.send( msgSceneOn.set( received_val )); 
        
        Serial.print("Scene ");
        Serial.print( received_val ); 
        Serial.println( count < LONG_PRESS_COUNT ? " ON" : " OFF"); 
    
        // software debounce
        gw.wait(750); 
        //delay(750);
        count = 0; 
        wirelessSwitch.resetAvailable();
    
    
      } 
    
    }
    
    

    The edge for short/long press is defined by count of messages received (each message takes about 100ms to be received), so the default "5" in the sketch defines >= ~500ms as long press.

    #define LONG_PRESS_COUNT  5           // Number of messages for long-press
    

    And to distinguish between short and long press, a offset is added to the button number, defined here:

    #define LONG_PRESS_OFFSET 10000000UL  // Offset for long-press
    

  • Hardware Contributor

    Wow, great! Its alway nice to see others using my work too. Your code improvement seem to be very helpful too.
    I have most recently also integrated this directly into my gateway build (see here). I am still struggling with code there though.



Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts