Sending command to RN2903

Hi,

I need to send ascii command to RN2903 from Arduino to send data from the output buffer. The format is to send data is "mac tx uncnf 15 ". If I sent a dummy data in HEX form it is accepting perfectly. But when I send for the sensor data, its showing invalid_param. The code I used is
given below for your reference.

mydata = String(output_buffer);
prefix_string = String(“mac tx uncnf 15 “);
postfix_string = String(”\r\n”);
final_string = prefix_string + mydata + postfix_string;

for (int i = 0; i < final_string.length(); i++)
{
Serial.write(final_string[0]); //Push each char 1 by 1 on each loop pass
}

Kindly help me to fix this issue.

Serial.write(final_string[0]);  Same character?

Please remember to use code tags when posting code.

Same character? I am sorry. May I know what you mean?

jinoramson:
Same character? I am sorry. May I know what you mean?

You're sending the same character, over and over again.

I can't believe that's what you intended.

(I'm also unclear why you're combining three Strings to do this, or why you're even using Strings at all)

Yeah. That’s the syntax to give commands to RN2903. The command to send data is "mac tx uncnf 15 and the data I need to give it from the output_buffer.

For instance, if I give with a dummy data(0+1.08+0.00+23.1) in HEX format, "Serial.write (“mac tx uncnf 15302b312e30382b302e30302b32332e310a0a\r\n”), it is accepting perfectly.

Great! Glad you fixed it.

But if I give the data from the buffer, I have used the following code but its not accepting.

mydata = String(output_buffer);
prefix_string = String(“mac tx uncnf 15 “);
postfix_string = String(”\r\n”);
final_string = prefix_string + mydata + postfix_string;

for (int i = 0; i < final_string.length(); i++)
{
Serial.write(final_string[0]); //Push each char 1 by 1 on each loop pass
}

You’re still sending the same character, over and over again.

Stop doing that.

Stop. Think.
Does the receiver care if the string it receives was as the result of a single write, or three, or ‘n’ writes (where ‘n’ is the number of characters in the string)?

Please try to acquire the habit of posting code in code tags.

The receiver requires single write. So I have tried like this to give ,

mydata = String(output_buffer);
         prefix_string = String("mac tx uncnf 15 ");
         postfix_string = String("\r\n");
         final_string = prefix_string + mydata + postfix_string;
         Serial.write(final_string);

But its showing an error, 'no matching function for call to ‘HardwareSerial::write(String&)’, then I added #include <HardwareSerial.h>. But still I am getting the same error. 'no matching function for call to ‘HardwareSerial::write(String&)’.

The receiver requires single write.

"Serial.write ("mac tx uncnf 15302b312e30382b302e30302b32332e310a0a\r\n"), it is accepting perfectly.

vs your (flawed) for loop?

I think not.

Please stop and think.

Hi

The receiver requires single write. So I am supposed to give like this ,

mydata = String(output_buffer);
         prefix_string = String("mac tx uncnf 15 ");
         postfix_string = String("\r\n");
         final_string = prefix_string + mydata + postfix_string;
         Serial.write(final_string);

But its showing an error, 'no matching function for call to ‘HardwareSerial::write(String&)’, then I added #include <HardwareSerial.h>. But still I am getting the same error. 'no matching function for call to ‘HardwareSerial::write(String&)’.

Looking forward to hear the solution.

Try the three write solution.
Do it without Strings.

(I can see from your IP address that you're using a university network, so I assume you're a student. I'm not going to write a solution, because I believe students should think for themselves. You've already been pointed at two solutions - it's up to you to figure it out)

Yeah, its simple.

Serial.write(final_string[i]);

But I need to convert the output_buffer into ASCII, then HEX, then if I write the final_string, the receiver will accept it.

OK, so you've figured out that the data doesn't need to be sent in a single write, (and that you dont want to sendthesame character over and over again) so now it should be pretty clear that it doesn't need to be in a String either.

Hi,

I have figured out the issue in sending with multiple write, but my receiver wont accept it. I have to give it in single write. I didn't figure out that issue yet . If you help me, it would be a great.

You do NOT have to do it with a single write - that makes no sense if you apply even a little thought.
What you DO have to do is send the correct data.

I have tried like this as per your information. It shows the compilation error as, HardwareSerial::write (String&unsigned int);

 mydata = String(output_buffer);
      prefix_string = String("mac tx uncnf 15 ");
      postfix_string = String("\r\n");
      final_string = prefix_string + mydata + postfix_string;
      Serial.write(final_string,sizeof(final_string));

I NEVER instructed you to do that.
I told you NOT to use Strings.
I suggested you tried a three write solution.
How did that go?

Could any of the teaching staff help you?
It's what you're paying them for.

I am sorry.

I have tried

Serial.write(final_string,sizeof(final_string));
Serial.write(final_string); In bothe the cases, i am getting error. And I cannot use this Serial.write(val); for my requirement.

Serial.write ("mac tx uncnf 15302b312e30382b302e30302b32332e310a0a\r\n")

According to you, this works

So, you have a preamble "mac tx uncnf 15 ",
you have a post fix "\r\n"
And you have data string "15302b312e30382b302e30302b32332e310a0a"

So, what happens with

Serial.print ("mac tx uncnf 15 ");
Serial.print (mydata);
Serial.print ("\r\n");

?

You are making things harder for yourself by your insistence on using Strings.
You are making things harder for us by only posting snippets of code and not specifying whether "error messages" are compiler errors or runtime errors.