Error sending switch command at Gateway



  • Hello All...
    I am having a problem with sending a 4 relay block code to Domoticz Gateway … sometimes the relays switch without any problem, but other times, it breaks out to an "Error sending switch command".

    I saw an earlier post at https://forum.mysensors.org/topic/4658/solved-error-sending-switch-command with the same issue. The solution proffered there didn't have much impart. One second it's working fine and the next its breaking into errors.

    I couldn't find a .1uf Capacitor, so I used an electrolytic 1uf instead. Worked fine in another Nfr+ radio Project, but I don't know if that's the problem here. My sketch is a follows:-

    // Example sketch showing how to control physical relays. 
    // This example will remember relay state even after power failure.
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    #define MY_NODE_ID 6  // Set this to fix your Radio ID or use AUTO or 1
    #define MY_REGISTRATION_FEATURE // Forece registration
    #define MY_REGISTRATION_RETRIES 5
    
    #include <Wire.h>
    #include <TimeLib.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <LCD.h>
    #include <LiquidCrystal.h>
    #include <LiquidCrystal_I2C.h>
    
    // For Debug
    #ifdef DEBUG_ON
    #define DEBUG_PRINT(x)   Serial.print(x)
    #define DEBUG_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_PRINT(x)
    #define DEBUG_PRINTLN(x)
    #define SERIAL_START(x)
    #endif
    
    #define RELAY_PIN 2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 4 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    #define SKETCH_NAME "Swimming Pool Node"
    #define SKETCH_VERSION "0.1.4"
    #define CHILD_ID 0
    
    MyMessage msg(1,V_LIGHT);
    unsigned long SLEEP_TIME = 5000;   // Sleep time inbetween reads in milliseconds
    void setup()
    {
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
    //    digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);   // to remember last state
        digitalWrite(pin, loadState? 0 : 0);   // Keep everything off after power failure
      }
    }
    
    void presentation() { 
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
    
      // Fetch relay status
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
        pinMode(pin, OUTPUT); // Then set relay pins in output mode  
    //    boolean savedState = loadState(sensor); // Set relay to last known state (using eeprom storage)
    //    digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
    //    send(msg.set(savedState? 0 : 1));
      }
          DEBUG_PRINTLN(F("Sensor Presentation Complete"));
    }
    void loop() 
    {
    // Alway process incoming messages whenever possible
    // Sleep until interrupt comes in on motion sensor. Send update every two minute.
    //  sleep(digitalPinToInterrupt(msg.sensor-1+RELAY_PIN), CHANGE, SLEEP_TIME);
    wait(SLEEP_TIME);
    }
    void receive(const MyMessage &message){
    // Change relay state if message is receieved
    
       if (message.type == V_STATUS){
       digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
       saveState(message.sensor-1+RELAY_PIN, message.getBool());
    // Write some debug info
       Serial.print("Incoming change for sensor ID: ");
       Serial.print(message.sensor);
       Serial.print(", New status: ");
       Serial.println(message.getBool());
        } 
      }
    

    I hear tagging this trio solves problems, so here goes... @tekka, @kk02067 and @hek to help me with this one. So sorry guys.



  • @eme Okay I solved this by redoing the MySensors Gateway added 4.7uf cap and everything works fine now.



  • @eme If you are talking on the side of the nRF24 radio module then yes, the 4.7uf or above AFAIK is recommended in here as a minimum. I could see this happening if there were occasional packet collisions with the gateway because the radio cannot refresh fast enough due to of the quick draw of power on the radio.


 

155
Online

8.7k
Users

9.5k
Topics

99.9k
Posts