Im simply trying to pass my payload to another device that has the same architecture and struct. I'm using UART to transfer, and modeling the protocol from EasyTransfer.
When I call Serial.print((char*)mydata.data);
in Transfer it prints Hello World as expected.
Calling that same line in Receive prints a '?' to console. This may be some background behavior with Arduino, or I'm just not casting/handling the pointers correctly. How can I get this print out to function properly?
Transfer Sketch
#include <EasyTransfer.h>
//create object
EasyTransfer TransferObject;
//Struct contents must be idential to struct from other board
#define PAYLOAD_SIZE 255
struct SEND_DATA_STRUCTURE
{
int blinks;
int pause;
uint8_t data[PAYLOAD_SIZE];
};
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;
void setup()
{
Serial.begin(9600);
//#define details(name) (byte*)&name,sizeof(name)
TransferObject.begin(details(mydata), &Serial);
pinMode(13, OUTPUT);
//initalize not so random number generator
randomSeed(analogRead(0));
}
void loop()
{
//mydata.blinks = random(5);
//mydata.pause = random(5);
//Create payload to transfer
char* payload = "Hello World!";
//Fill array with data
strncpy((char *)mydata.data, payload, PAYLOAD_SIZE);
//Print sample
Serial.print((char*)mydata.data);
//send the entire struct
TransferObject.sendData();
delay(5000);
}
Receive Sketch
#include <EasyTransfer.h>
//create object
EasyTransfer TransferObject;
//Struct contents must be idential to struct from other board
#define PAYLOAD_SIZE 255
struct RECEIVE_DATA_STRUCTURE
{
int blinks;
int pause;
uint8_t data[PAYLOAD_SIZE];
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;
void setup(){
Serial.begin(9600);
//#define details(name) (byte*)&name,sizeof(name)
TransferObject.begin(details(mydata), &Serial);
pinMode(13, OUTPUT);
}
void loop()
{
//check and see if a data packet has come in.
if(TransferObject.receiveData())
{
Serial.print("active");
//print data payload
Serial.print((char*)mydata.data);
}
//you should make this delay shorter then your transmit delay or else messages could be lost
delay(250);