Remote socket (int Help)

I am using remote controlled sockets in my home and have a remote connected to my arduino.
When I send SR410# through Serial I want the arduino to send channel ‘4’ and Socket ‘1’ to the remote. ‘mySwitch.switchOff(Ch, Sk);’
But insted of sending (4, 1) it sends 13.

How can I format it so it will send ‘(Ch, Sk)-(4, 1)’ and not (13).
Thanks For any help you can give me.

Here is the snip of code.

void DeviceRemote() {
  
  //Set int from Serial in.
  int Ch = inputString[2]; //Channel
  int Sk = inputString[3]; //Socket
  int Vl = inputString[4]; //Value 0 or 1 'On or Off'
   
  if (Vl == '0') {
    mySwitch.switchOff(Ch, Sk); //<--Instead of sending (4, 1) it sends (13) to the remote.
    Serial.println(Ch, Sk);
    LedBlink();
  }
  if (Vl == '1') {
     mySwitch.switchOff(Ch, Sk); //<--Instead of sending (4, 1) it sends (13) to the remote.
    Serial.println(Ch, Sk);
    LedBlink();
  }
}

As we can't see the definition of mySwitch.switchOff(), it's impossible to tell whether that is right or not.

This

Serial.println(Ch, Sk);

is saying print Ch, using the number base Sk. If you wanted to end up with, say, '4, 1', then you would do

Serial.print(Ch);
Serial.print(", ");
Serial.println(Sk);

Thanks for your reply.

Sorry I was using ‘Serial.print’ just to show what it was doing.
What I want is to have (4, 1) sent to mySwitch.switchOff.

I need to keep Ch and Sk as there original value and send then to - mySwitch.switchOff(Ch, Sk); ‘‘mySwitch.switchOff(4, 1);’’

I am using #include <RCSwitch.h> ‘http://code.google.com/p/rc-switch/wiki/HowTo_OperateLowCostOutlets

All the examples on that page show that the first argument to the switchOff() method is a string. You are calling the method with an int. Why?

Post ALL of your code. We can not see how inputString is defined. If it is an array of characters, then is is easy to do what you want.

The idea is I can set the Channel and Socket and State through Serial without writing multiple lines of (mySwitch.switchOff(4,1) OR mySwitch.switchOn(4,2)) and calling them on if statements.

So if I send SR410#
S=Set / R=Remote / 4=Channel / 1=Socket / 0=Off / #=End of msg.
Or SR321#
Set Remote Channel 3 Socket 2 Turn On.

Here is the Code.

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

String inputString = "";         
boolean stringComplete = false; 

void setup() {
  
  pinMode(13, OUTPUT);
  
  Serial.begin(9600);
  inputString.reserve(200);
   
  mySwitch.enableTransmit(9);
  
}

void loop() {
    
  
  // print inputString when a # arrives:
  if (stringComplete) {
    Serial.println(inputString);
  
  // Check first letter for S or G:
  if (inputString[0] == 'S') {
    ActionSet();
  }
  if (inputString[0] == 'G') {
    ActionGet();
  }
  
  // clear the string and reset stringComplete:
    inputString = "";
    stringComplete = false;
    
  }
}

void serialEvent() {
  
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    inputString += inChar;

    if (inChar == '#') {
      stringComplete = true;
    } 
  }
}


void ActionSet() {
  
  if (inputString[1] == 'R') {
    DeviceRemote();
  }
}


void ActionGet() {
  
  LedBlink();
}

void LedBlink() {
 
  digitalWrite(13, HIGH);
  delay(500);             
  digitalWrite(13, LOW); 
}


void DeviceRemote() {
  
  int Ch = inputString[2]; //Channel
  int Sk = inputString[3]; //Socket
  int Vl = inputString[4]; //Value 0 or 1 'On or Off'
   
  if (Vl == '0') {
    mySwitch.switchOff(Ch, Sk);
    Serial.println(inputString);
    LedBlink();
  }
  if (Vl == '1') {
    mySwitch.switchOn(Ch, Sk);
    Serial.println(inputString);
    LedBlink();
  }
}

If you send, using the Serial Monitor, “SR410#”, then in DeviceRemote(), you are setting Ch, Sk, and Vl to ‘4’, ‘1’, and ‘0’, which, of course, are not the same as 4, 1, and 0.

The mySwitch.switchOff() has two overloads - one takes a string and an int and the other takes two ints. You are calling the two int version, but the data that is in those two ints is not what you think it is.

Try:

  int Ch = inputString[2] - '0'; //Channel
  int Sk = inputString[3] - '0'; //Socket
  int Vl = inputString[4] - '0'; //Value 0 or 1

so that, given “SR410”, Chm Sk, and Vl end up containing 4. 1. and 0, respectively.

Yes that worked.

Now I see why that was happening. I spent a few days trying to workout why. lol

Thank you so much for your help.

Regards Mick