Skip to main content
More relevant title, link to the rc-switch library
Source Link
Edgar Bonet
  • 44.3k
  • 4
  • 41
  • 79

Convert char buffer How to Stringtransmit string data using the rc-switch library?

I am using rcswitch librarythe rc-switch library for sending and receiving data. In rcswitch library, there is no method to send string data. I am using below method to send the string message in char buffer.

send_string("Hello World!");
---------------------------

void send_string(const char *str)
{
int i = 0;

for (char *p = str; *p; p++ ) {
mySwitch.send((i<<8) + *p, 16);
i++;
}
mySwitch.send((i<<8) + 255, 16);
}

And I am receiving is using this Serial.print((char)mySwitch.getReceivedValue()); build in method. But I am getting this message.

H
H
H
e
e
e
l
l
l
l
l
l
o
o
o



W
W
W
o
o
o
l
l
l
d
d
d
!
!
!

Now how can I get my original message?

Convert char buffer to String

I am using rcswitch library for sending and receiving data. In rcswitch library, there is no method to send string data. I am using below method to send the string message in char buffer.

send_string("Hello World!");
---------------------------

void send_string(const char *str)
{
int i = 0;

for (char *p = str; *p; p++ ) {
mySwitch.send((i<<8) + *p, 16);
i++;
}
mySwitch.send((i<<8) + 255, 16);
}

And I am receiving is using this Serial.print((char)mySwitch.getReceivedValue()); build in method. But I am getting this message.

H
H
H
e
e
e
l
l
l
l
l
l
o
o
o



W
W
W
o
o
o
l
l
l
d
d
d
!
!
!

Now how can I get my original message?

How to transmit string data using the rc-switch library?

I am using the rc-switch library for sending and receiving data. In rcswitch library, there is no method to send string data. I am using below method to send the string message in char buffer.

send_string("Hello World!");
---------------------------

void send_string(const char *str)
{
int i = 0;

for (char *p = str; *p; p++ ) {
mySwitch.send((i<<8) + *p, 16);
i++;
}
mySwitch.send((i<<8) + 255, 16);
}

And I am receiving is using this Serial.print((char)mySwitch.getReceivedValue()); build in method. But I am getting this message.

H
H
H
e
e
e
l
l
l
l
l
l
o
o
o



W
W
W
o
o
o
l
l
l
d
d
d
!
!
!

Now how can I get my original message?

Source Link

Convert char buffer to String

I am using rcswitch library for sending and receiving data. In rcswitch library, there is no method to send string data. I am using below method to send the string message in char buffer.

send_string("Hello World!");
---------------------------

void send_string(const char *str)
{
int i = 0;

for (char *p = str; *p; p++ ) {
mySwitch.send((i<<8) + *p, 16);
i++;
}
mySwitch.send((i<<8) + 255, 16);
}

And I am receiving is using this Serial.print((char)mySwitch.getReceivedValue()); build in method. But I am getting this message.

H
H
H
e
e
e
l
l
l
l
l
l
o
o
o



W
W
W
o
o
o
l
l
l
d
d
d
!
!
!

Now how can I get my original message?