RF433MHZ sensor



  • Hi I found this sketch in the MySensors library, if does great to sniff 433 codes, can anybody assist in having it create devices that are able to transmit a 433 code to allow control of these devices?

    /*
     * This sketch demonstrates how to use InterruptChain to receive and
     * decode remote switches (old and new) and remote sensors.
     *
     * Basically, this sketch combines the features of the ShowReceivedCode
     * and ShowReceivedCodeNewKaku examples of RemoteSwitch and the
     * ThermoHygroReceiver of RemoteSensor all at the same time!
     *
     * After uploading, enable the serial monitor at 115200 baud.
     * When you press buttons on a 433MHz remote control, as supported by 
     * RemoteSwitch or NewRemoteSwitch, the code will be echoed.
     * At the same time, if data of a remote thermo/hygro-sensor is
     * received, as supported by RemoteSensor, it will be echoed as well.
     *
     * Setup:
     * - connect a 433MHz receiver on digital pin 2.
     *
     *
     * MySensor note: This example has not yet been adopted but can be used as an example
     * of receiving 433Mhz stuff. 
     * 
     * One idea could be to echo received 433 codes back to gateway to be able to pick up and
     * handle data over there.
     *
     */
    
    #include <RemoteReceiver.h>
    #include <NewRemoteReceiver.h>
    #include <SensorReceiver.h>
    #include <InterruptChain.h>
    
    void setup() {
      Serial.begin(115200);
    
      // Interrupt -1 to indicate you will call the interrupt handler with InterruptChain
      RemoteReceiver::init(-1, 2, showOldCode);
      
      // Again, interrupt -1 to indicate you will call the interrupt handler with InterruptChain
      NewRemoteReceiver::init(-1, 2, showNewCode);
    
      // And once more, interrupt -1 to indicate you will call the interrupt handler with InterruptChain
      SensorReceiver::init(-1, showTempHumi);
    
      // On interrupt, call the interrupt handlers of remote and sensor receivers
      InterruptChain::addInterruptCallback(0, RemoteReceiver::interruptHandler);
      InterruptChain::addInterruptCallback(0, NewRemoteReceiver::interruptHandler);
      InterruptChain::addInterruptCallback(0, SensorReceiver::interruptHandler);
    }
    
    void loop() {
       // You can do other stuff here!
    }
    
    // shows the received code sent from an old-style remote switch
    void showOldCode(unsigned long receivedCode, unsigned int period) {
      // Print the received code.
      Serial.print("Code: ");
      Serial.print(receivedCode);
      Serial.print(", period: ");
      Serial.print(period);
      Serial.println("us.");
    }
    
    // Shows the received code sent from an new-style remote switch
    void showNewCode(NewRemoteCode receivedCode) {
      // Print the received code.
      Serial.print("Addr ");
      Serial.print(receivedCode.address);
      
      if (receivedCode.groupBit) {
        Serial.print(" group");
      } else {
        Serial.print(" unit ");
        Serial.print(receivedCode.unit);
      }
      
      switch (receivedCode.switchType) {
        case NewRemoteCode::off:
          Serial.print(" off");
          break;
        case NewRemoteCode::on:
          Serial.print(" on");
          break;
        case NewRemoteCode::dim:
          Serial.print(" dim level ");
          Serial.print(receivedCode.dimLevel);
          break;
        case NewRemoteCode::on_with_dim:
          Serial.print(" on with dim level ");
          Serial.print(receivedCode.dimLevel);
          break;
      }
      
      Serial.print(", period: ");
      Serial.print(receivedCode.period);
      Serial.println("us.");
    }
    
    // Shows the received sensor data
    void showTempHumi(byte *data) {
      // is data a ThermoHygro-device?
      if ((data[3] & 0x1f) == 0x1e) {
        // Yes!
        byte channel, randomId;
        int temp;
        byte humidity;
    
        // Decode the data
        SensorReceiver::decodeThermoHygro(data, channel, randomId, temp, humidity);
      
        // Print temperature. Note: temp is 10x the actual temperature!
        Serial.print("Temperature: ");
        Serial.print(temp / 10); // units
        Serial.print('.');
        Serial.println(temp % 10); // decimal
      }
    }
    

    Regards


  • Hero Member

    For inspiration... this sketch uses a variant of the RemoteTransmitter libraries for European Home Easy (not the same as the UK/ world one). Basically just a creating a 433 Mhz transmitter. with fixed codes.

    https://codebender.cc/sketch:81535



  • does it need a specific library?
    Are codes held in the controller or the sketch?

    on compile I get

    sketch_feb24a:13: error: 'HomeEasyEUSwitch' does not name a type
    sketch_feb24a.ino: In function 'void incomingMessage(const MyMessage&)':
    sketch_feb24a:56: error: 'homeeasySwitch' was not declared in this scope


  • Hero Member

    @Terence-Faul Sorry, it was only meant for inspiration, there are some libraries needed. If you don't need the EU HomeEasy, you need to create an instance of the RemoteSwitch. For some examples just search for the Remoteswitch on the net.


  • Hero Member

    Hi Terence,
    There are a couple of protocols that can be transmitted via 433Mhz. There is no "universal"-receiver that understands all protocols. Which specific type of device do you want to control?



  • I am not sure, I bought some relays from Ebay.

    If I use the MySensors 433RF Sketch, the receiver recognises the remotes.

    /*
     * This sketch demonstrates how to use InterruptChain to receive and
     * decode remote switches (old and new) and remote sensors.
     *
     * Basically, this sketch combines the features of the ShowReceivedCode
     * and ShowReceivedCodeNewKaku examples of RemoteSwitch and the
     * ThermoHygroReceiver of RemoteSensor all at the same time!
     *
     * After uploading, enable the serial monitor at 115200 baud.
     * When you press buttons on a 433MHz remote control, as supported by 
     * RemoteSwitch or NewRemoteSwitch, the code will be echoed.
     * At the same time, if data of a remote thermo/hygro-sensor is
     * received, as supported by RemoteSensor, it will be echoed as well.
     *
     * Setup:
     * - connect a 433MHz receiver on digital pin 2.
     *
     *
     * MySensor note: This example has not yet been adopted but can be used as an example
     * of receiving 433Mhz stuff. 
     * 
     * One idea could be to echo received 433 codes back to gateway to be able to pick up and
     * handle data over there.
     *
     */
    
    #include <RemoteReceiver.h>
    #include <NewRemoteReceiver.h>
    #include <SensorReceiver.h>
    #include <InterruptChain.h>
    
    void setup() {
      Serial.begin(115200);
    
      // Interrupt -1 to indicate you will call the interrupt handler with InterruptChain
      RemoteReceiver::init(-1, 2, showOldCode);
      
      // Again, interrupt -1 to indicate you will call the interrupt handler with InterruptChain
      NewRemoteReceiver::init(-1, 2, showNewCode);
    
      // And once more, interrupt -1 to indicate you will call the interrupt handler with InterruptChain
      SensorReceiver::init(-1, showTempHumi);
    
      // On interrupt, call the interrupt handlers of remote and sensor receivers
      InterruptChain::addInterruptCallback(0, RemoteReceiver::interruptHandler);
      InterruptChain::addInterruptCallback(0, NewRemoteReceiver::interruptHandler);
      InterruptChain::addInterruptCallback(0, SensorReceiver::interruptHandler);
    }
    
    void loop() {
       // You can do other stuff here!
    }
    
    // shows the received code sent from an old-style remote switch
    void showOldCode(unsigned long receivedCode, unsigned int period) {
      // Print the received code.
      Serial.print("Code: ");
      Serial.print(receivedCode);
      Serial.print(", period: ");
      Serial.print(period);
      Serial.println("us.");
    }
    
    // Shows the received code sent from an new-style remote switch
    void showNewCode(NewRemoteCode receivedCode) {
      // Print the received code.
      Serial.print("Addr ");
      Serial.print(receivedCode.address);
      
      if (receivedCode.groupBit) {
        Serial.print(" group");
      } else {
        Serial.print(" unit ");
        Serial.print(receivedCode.unit);
      }
      
      switch (receivedCode.switchType) {
        case NewRemoteCode::off:
          Serial.print(" off");
          break;
        case NewRemoteCode::on:
          Serial.print(" on");
          break;
        case NewRemoteCode::dim:
          Serial.print(" dim level ");
          Serial.print(receivedCode.dimLevel);
          break;
        case NewRemoteCode::on_with_dim:
          Serial.print(" on with dim level ");
          Serial.print(receivedCode.dimLevel);
          break;
      }
      
      Serial.print(", period: ");
      Serial.print(receivedCode.period);
      Serial.println("us.");
    }
    
    // Shows the received sensor data
    void showTempHumi(byte *data) {
      // is data a ThermoHygro-device?
      if ((data[3] & 0x1f) == 0x1e) {
        // Yes!
        byte channel, randomId;
        int temp;
        byte humidity;
    
        // Decode the data
        SensorReceiver::decodeThermoHygro(data, channel, randomId, temp, humidity);
      
        // Print temperature. Note: temp is 10x the actual temperature!
        Serial.print("Temperature: ");
        Serial.print(temp / 10); // units
        Serial.print('.');
        Serial.println(temp % 10); // decimal
      }
    }
    

Log in to reply
 

Suggested Topics

21
Online

11.4k
Users

11.1k
Topics

112.7k
Posts