RF433 MHZ connected to Serial Gateway



  • Hello,

    I'm running a few nodes with a serial gateway with Hats.io but I would like to add a 433 MHz transmitter directly on the gateway to control a few devices (ON / OFF with DiO codes), but I can't find a way to add it in the loop (via serial listening) without blocking the other messages coming from NRF24L01 nodes.
    Do you have an idea ?

    #define MY_DEBUG
    #define MY_GATEWAY_SERIAL
    #define MY_INCLUSION_MODE_FEATURE
    #define MY_INCLUSION_MODE_DURATION 60
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    #define MY_RADIO_NRF24
    
    #define MY_RF24_PA_LEVEL (RF24_PA_MAX)
    
    #define CHILD_ID_HUM  0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_STATE_RAD_SALON 4
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #include <DiOremote.h>
    const unsigned long OFF_CODE  = 1278825104;
    const unsigned long ON_CODE = 1278825088;
    const int TX_PIN = 2;
    DiOremote myRemote = DiOremote(TX_PIN);
    
    #include <Custom_SHT.h>
    Custom_SHT SHT;
    static bool metric = true;
    
    uint32_t period = 1 * 60000L;
    static const uint64_t UPDATE_INTERVAL = 60000;
    
    String incomingByte;
    
    
    void presentation()  
    { 
      // Send the sketch info to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.0");
    
      // Present sensors as children to gateway
      present(CHILD_ID_HUM, S_HUM,   "Humidity");
      present(CHILD_ID_TEMP, S_TEMP, "Temperature");
      //present(CHILD_ID_STATE_RAD_SALON, S_CUSTOM);
    
      metric = getControllerConfig().isMetric;
    }
    
    void setup()
    {
    
    }
    
    
    void loop()      
    {  
      // Read temperature & humidity from sensor.
    
      unsigned long start = millis();
      SHT.begin();
      float humidity = SHT.GetHumidity();
      float temperature = SHT.GetTemperature();
      static MyMessage msgHum( CHILD_ID_HUM,  V_HUM );
      static MyMessage msgTem(CHILD_ID_TEMP, V_TEMP);
    
      send(msgTem.set(temperature, 2));
      send(msgHum.set(humidity, 2));
      for( uint32_t tStart = millis();  (millis()-tStart) < period;  ){
        if (Serial.available() > 0) {
          // read the incoming byte:
          String Incoming = Serial.readString();
          if (Incoming = "0") {
          // say what you got:
          Serial.print("I received: ");
          Serial.println(incomingByte);
          myRemote.send(OFF_CODE);
          }
        if (Incoming = "1") {
          // say what you got:
          Serial.print("I received: ");
          Serial.println(incomingByte);
          myRemote.send(ON_CODE);
          }
        }
      }
      // Sleep until next update to save energy (deactivated for now)
      //sleep(UPDATE_INTERVAL); 
    }
    

    Thanks,


  • Mod

    Hi @ryolaxe, welcome to the forum.

    How to do this depends mainly on how the DiOremote library works. I tried to google for it, but wasn't able to find it. Could you share a link to its documentation/source code?



  • Hello and thanks for your reply,

    I don’t have a documentation but I downloaded it here : http://charleslabs.fr/fr/project-Contrôle+de+prises+DiO+avec+Arduino.

    But I think I could use RCSwitch instead.


  • Mod

    @ryolaxe seems like the protocol needs quite precise timing, so it might not be possible to send working commands and still handle incoming messages.

    One thing you could do is to set DiOremote_DEFAULT_TRY_COUNT to 1 and call myRemote.send 5 times from the loop, checking serial between each call. You would probably need to add a queue to handle the incoming messages.

    An (maybe easier) alternative is to move the code for the 433 transmitter to a separate node so it doesn't need to handle incoming messages for other nodes.



  • @mfalkvidd Alright.
    Thanks for your quick analysis, I’ll put it on a different node to start then if I find the time, i’ll Try to add it to the gateway.


  • Plugin Developer

    I tried to create a gateway with this functionality too, but stopped because it took too much memory, and indeed requires an uninterrupted high speeds burst of signals once in a while.

    I have now been working on a node that can recognise and replay signals. It's universal: it can copy and then recognise and replay any signal. Well, any signal from 4 to 16 bytes. Which is all of them as far as I can tell. No need to mess with timings, it figures that out as well. It compresses the signals an stores them in EEPROM. On average 25 replayable signals can be stored in 512 bytes of storage this way. If you only want to re-detect the signal it's about 50.

    If you wait a few days I'll have some working code I can share.


  • Plugin Developer

    As promised, here's a link to the project.


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 2
  • 3
  • 8
  • 17

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts