sending/receiving one float value

Started by stewl, December 04, 2013, 02:16:06 PM

stewl

I'm running w/ Motino Leos and want to send single temperature readings from one Leo to the other, wirelessly.
The example send/receive sketches are working fine sending ASCII strings, but I need to send a float value.
Just read the post & reply about "data struct for sending/receiving"
Is that the simplest way to send and receive just one float value?


Felix

Yes, since there's no text or anything else, you just fill a struct on one end and read it back on the other end. Can't get easier than that.

stewl

Thanks for your reply, Felix.

I am working with Motino Leos and using the RFM12B library
for the wireless components.

The example sketches you had posted in reply to someone else's question
uses a different library: RF69.

So far I have be able modify the sending sketch so it compiles OK with the RFM12B library
(I haven't loaded or tested it yet), but I cant see how to change the receiving sketch
to work with the 12B library because it uses different function names.

Is it possible, or can I use the RF69 library with the Leos?

Felix

You cannot use RFM69 lib with RFM12B.
The example is given so that you can see how it's doable. You will need to cast the struct as a byte array so the radio.Send() function can read it. Then uncast it on the other end into that same struct type. It's all just bare bones C++...

stewl

Again, Thank you Felix for the reply.

Unfortunately, I am not a C++ programmer, and I do not understand casting structs.
I've done a fair amount of non-object oriented programming with VB and a small amount
with the Arduino C.

But, I still need a bit of hand holding to be able to have one Leo send a float value to another.
Looks like I am restricted to the RFM12B library for those modules and can't take advantage of your routines that do this with other libraries.

The Leo demo programs send ASCII strings wirelessly.
Too bad there isn't a simple way to turn a float into a string that could be transmitted.

Stew

Felix

Hey Stew .. I understand, casting pointers and bouncing byte arrays can be a strange thing when you've been used to high level languages that give you variables for free :)
So basically in C everything is a byte, or multiple bytes. For instance an integer is 2 bytes but it can be 4 bytes sometimes, see http://arduino.cc/en/Reference/int
A struct is basically an instruction that tells the compiler that when it sees that data type (your struct) it means it's a bunch of bytes grouped together that will be interpreted as that type of struct, with whatever variables that struct holds.

The radio.Send() functions in the libraries take a byte array as the raw data to send, as a byte pointer and another argument that is the array length. Any type of data can be cast to a byte array. So you need to cast your struct to a byte array, then for the length you can use sizeof(theDataStruct) to get the length of that struct.

Then the Send() function will send that many bytes on the other end. Then on the other end you do the same, you read back [sizeof(theData)] bytes and cast them into a variable of the type of that same struct.

The code in the RFM69 lib can be easily ported to make it work with the RFM12B, but if you still need help I will make a note to post a struct sending example for RFM12B.


stewl

Thank you again Felix.

I really appreciate your creating the sketches for the RFM12B library.

I had tried several times to do that, and was quite close, but I would not have come up with the critical part:  theData = *(Payload*)radio.Data;

I look forward to trying these tomorrow.

Thank you for the superior support.

Stew

Felix