As from Arduino IDE 0022, we can use standard strings.
For sending via RFM12, I've defined the following 'payload structure':
datatype struct
{
string sensor;
int value1;
int value2;
long value3;
} Payload;
Payload payload;
string sensorTMP1={"TOG04"};
I set the payload.sensor=sensorTMP1
When I want to send the payload, the send command hangs on the rf12_sendStart(0,&payload,sizeof payload,2); (using the jeenode RFM12 library).
I assume it has something to do with the string datatype in the payload structure, because when I send only int, float or chars it works.
Is there a simple way to solve this and still has the advantage using a string datatype ?
Sorry for the mistake, I can't copy my real code at this moment.
Indeed, the declarations should be 'String' with a capital.
So I use the String constructor (not called a string datatype):
datatype struct
{
String sensor;
int value1;
int value2;
long value3;
} Payload;
Payload payload;
String sensorTMP1="TOG04";
The send command = rf12_sendStart(0,&payload,sizeof payload,2);
struct
{
String sensor;
int value1;
int value2;
long value3;
}
The String does not itself contain the string of characters, but only contains a pointer to another buffer. When you send this struct to the other side, it will arrive with a pointer to memory garbage. If you want to send the sensor value as a fixed length (and it will have to be fixed length) sequence of chars, then define your struct like this:
struct
{
char sensor[8]; // or whatever the maximum length is, plus one
int value1;
int value2;
long value3;
}