Can someone please put me out of my misery
I am trying to emulate the Arduino EASYSERIAL so I can send a struct from the ESP to the Arduino.
Simple enough you might think.. We start with 0x06 and 0x85 then send our data and then a checksum.
Here is my struct...
/// ***** experiment transferring easytransfer format to Arduino display
typedef struct {
//put variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE DISPLAY BOARD
uint8_t cmd;
int16_t passed;
uint8_t humidity;
uint32_t thetime;
int8_t internal;
int8_t external;
uint8_t pre;
uint8_t heat;
uint8_t hold;
int8_t offset;
uint8_t set;
uint8_t fallback;
uint8_t falltemp;
uint8_t thermenable;
uint8_t dusk_hour;
uint8_t dusk_min;
uint8_t dawn_hour;
uint8_t dawn_min;
} transmit_lcdX;
transmit_lcdX transmit_lcd;
Here is my function...
//Sends out struct in binary, with header, length info and checksum
void ICACHE_FLASH_ATTR EasyTransfer_sendData( uint8_t *bfr, uint8_t size){
static uint8_t buf[40];
uint8_t CS;
CS = size;
buf[0]=0x06;
buf[1]=0x85;
buf[2]=CS;
for(int i = 0; i<size; i++){
CS^=*(bfr+i);
buf[i+3]=*(bfr+i);
}
buf[size+3]=CS;
uart0_tx_buffer(buf,size+4);
}
Simple enough.. and here's what's going out of the serial port (32 bytes in total as it turns out)
06 85 1C 00 00 00 00 00 00 00 00 27 FB C8 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5D
06 85 1C 00 00 00 00 00 00 00 00 28 FB C8 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52
06 85 1C 00 00 00 00 00 00 00 00 29 FB C8 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53
06 85 1C 00 00 00 00 00 00 00 00 2A FB C8 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50
Looks lovely doesn't it - the header is in the right place, the checksum is in the right place - and it looks like it is changing... what I'm doing here is updating the 32 bit TIME variable within the struct every second and blasting out the data..
Except for one thing - according to my calculations, the first 3 bytes are the header and length - then there should be FOUR bytes before the time -- not EIGHT!
uint8_t cmd;
int16_t passed;
uint8_t humidity;
uint32_t thetime;
Here is the call in action...
transmit_lcd.thetime=myRtc;
EasyTransfer_sendData(&transmit_lcd, sizeof(transmit_lcd));
Clearly I'm doing something wrong but I've been staring at this for so long now I've lost the plot. Anyone know what's wrong here?