Adding a local RCSwitch to a serial gateway crashes it


  • Hardware Contributor

    I have build a serial gateway based on the arduino nano that has a 433Mhz receiver connected to it. I used the same receiver connected to an arduino uno with the rc-switch library (advanced receive example) and was able to receive a signal send by a switch.
    I have now connected that receiver to pin 2 (int 0) of the nano and uploaded this sketch:

    #define MY_DEBUG 
    #define MY_DEBUG_VERBOSE_SIGNING
    
    // Enable leds
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    #define MY_DEFAULT_ERR_LED_PIN 4
    #define MY_DEFAULT_TX_LED_PIN 5
    #define MY_DEFAULT_RX_LED_PIN 6
    
    #define MY_SIGNING_SOFT // Enables software signing
    #define MY_SIGNING_REQUEST_SIGNATURES // Always request signing from nodes that support it
    #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 // floating pin for randomness
    
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL RF24_PA_HIGH
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <RCSwitch.h>
    
    RCSwitch wirelessSwitch = RCSwitch();
    const int RECEIVER_PIN = 0;
    
    // add the decimal codes for your switches here
    unsigned long switches[] = {12587348, 12587346, 12587345};
    int numberOfSwitches = 3;
    
    void setup() { 
      // Setup locally attached sensors
      wirelessSwitch.enableReceive(RECEIVER_PIN);  // Receiver on interrupt 0 => that is pin #2
    }
    
    void presentation() {
     // Present locally attached sensors 
      sendSketchInfo("433 Wireless + Serial Gateway", "13052017");
      
      for (int i = 0; i < numberOfSwitches; i++) {
        present(i, S_DOOR); // s_door has tripped, s_binary might be a choice too 
      }
    }
    
    void loop() { 
      // Send locally attached sensor data here 
      if (wirelessSwitch.available()) {
    
        unsigned long received_val = wirelessSwitch.getReceivedValue();
    
        //Serial.print("Pressed button ");
        //Serial.print(received_val);
    
        for (int i = 0; i < numberOfSwitches; i++) {
          if (received_val == switches[i]) {
            //Serial.print(". Recognized! Its button ");
            //Serial.println(i);
            send(MyMessage(i, V_TRIPPED).set(true));
          }
        }
    
        // software debounce
        wait(500);
        wirelessSwitch.resetAvailable();
      }
    }
    

    I wasn't able to get any reaction to the switch this time though. Is there any obvious error in my sketch? Or is it not possible to use an interrupt driven lib on the gateway? I had a similar setup on a "normal" mysensors node and that one is working without problems.

    PS Is there a way to enable normal serial.println() on the gateway for testing? At the moment I have no clue if the gateway receives the buttons presses at all because the (commented) print's are just ignored.



  • @LastSamurai
    I did more or less the same, but two calls are different in my setting

    In presentation() I use this call, but that is not your problem
    present(i, S_BINARY, "Relais");

    I suggest to change the send() method like this, because you first have to select the relay with setSensor()
    send(msgRelay.setSensor(CHILD_ID_RELAY1+i).set((bool)bValue));


  • Hardware Contributor

    @dirkc Thanks for your answer!
    I will try you code, but doesn't mine do the same?

    send(
      MyMessage(i, V_TRIPPED) // <-- same as msgRelay.setSensor(CHILD_ID_RELAY1+i)?!
      .set(true));
    

  • Hardware Contributor

    So I have done some more debugging and have testend the 433Mhz receiver by flashing the advanced demo sketch from the RC library. Everything is working fine that way. Then I added a better receiver and tried again. Now the my sketch that I have postet above worked just fine (and send the wireless key's presses to my controller).

    I did get another problem with that one though: the gateway kept crashing while sending/receiving message from other mysensor nodes. Randomly switching on some lights worked while others didn't. Also after some tries the RX/TX leds on my boards just stayed on. Only a hard reset of the gateway can get it in working condition again. After restarting suddenly some of the messages seem to come through (lights turning on, messages in the log of the controller). Also the voltage converter on the board got very hot, so I am guessing the radio was non-stop sending.
    Reflashing the normal gateway sketch without any local sensors makes the gateway work without any problems again.

    So the local sensor part must somehow interfere with the normal gateway stuff. Any idea how, or how to fix this? I have my 433Mhz bridge mysensors node running nearly the same code (just without the gateway part, its just a normal node) running without such problems...


  • Hardware Contributor

    Has anyone an idea how to fix this problem with local sensors?


  • Mod

    @LastSamurai said in Adding a local RCSwitch to a serial gateway crashes it:

    Also the voltage converter on the board got very hot, so I am guessing the radio was non-stop sending.

    I really doubt if that was the issue. An nrf24 uses a few tens of milliamps when sending. Even a lousy voltage regulator should be able to supply that.
    Maybe you had a short somewhere (ground loop?)


  • Hardware Contributor

    @Yveaux I finally got to do some more testing. Its really strange. The voltage regulator problem never occurred again (and its an pa+lna module so the power usage is a little higher).

    I did lots of tests and this is what I found:

    • while I just ignore the buttons everything is working fine (no buttons pressed)
    • if I press a button that does nothing on the controller everything still seems to be working just fine most of the time. Sometimes version 3 still happens
    • if I press a button that runs a script on the controller everything seems to stop working after some seconds, at least most of the times. The gateway becomes unresponsive (sometimes it restarts) and the leds (RX/TX) stay on. The only thing that helps is a manual restart of the gateway

    The script that is running works just fine with my external 433Mhz to Mysensors gateway and simply switches on a rgbw node if the button gets pressed.

    I am out of ideas currently. Does someone have another idea how to fix or even how to test to get to the actual problem?


  • Hardware Contributor

    OK newest update: my gateway stop working at all today. I did not even get any reactions on the serial port. So I tried to reprogram it => no reaction either.
    I had to manually reflash the bootloader and load the normal gateway sketch (without the 433Mhz stuff again). So I guess there is some kind of overflow somewhere caused by the code. The normal gateway sketch runs without any problems. No idea where the error is yet.


Log in to reply
 

Suggested Topics

  • 1
  • 6
  • 3
  • 1
  • 1
  • 10

15
Online

11.4k
Users

11.1k
Topics

112.7k
Posts