Try this sketch
#include <SafeString.h>
#include <Wire.h>
//#include <TimeLib.h>
//#include <DS1307RTC.h>
#include <SoftwareSerial.h>
byte packet1[] = {0x7E, 0x00, 0x21}; //Byte delimitador y Longitud de trama
byte packet2[] = {0x10, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x41, 0x4E, 0xF1, 0x24, 0xFF, 0xFE, 0x00, 0x00,}; //Id de trama, tipo de trama, direccion de 64bits, opciones y numero de brincos.
// 00:11:46 05/01/2021 == 19 chars
byte fullPacket[3 + 14 + 19 + 1];// (start + length) + (type+address) + date + checksum = 37
// length of data, including mode and address but witout checksum
// without checksum length is 33 = 0x21
char buffer [25]; // 19 for date +1 for terminating '\0' so 25 should be OK
#define DEBUG SafeString::Output
void setup() {
Serial.begin(9600);
for (int i = 10; i > 0; i--) {
Serial.print(' '); Serial.print(i);
delay(500);
}
Serial.println();
Serial.println("DS1307RTC convertir valores a HEX");
Serial.println("-------------------");
// comment this line out to remove error msgs and debug output
SafeString::setOutput(Serial); // for error msgs and debug
}
void loop() {
//tmElements_t tm;
//if (RTC.read(tm)) {
if (1) {
// sprintf(buffer, "%02d:%02d:%02d %02d/%02d/%04d", tm.Hour , tm.Minute, tm.Second, tm.Day, tm.Month, tmYearToCalendar(tm.Year));
sprintf(buffer, "%02d:%02d:%02d %02d/%02d/%04d", 5 , 6, 7, 8, 9, 2021);
Serial.println(buffer); // con este print compruebo que la fecha y hora
// build fullpacket
size_t idx = 0;
memmove(fullPacket + idx, packet1, sizeof(packet1));
idx += sizeof(packet1);
memmove(fullPacket + idx, packet2, sizeof(packet2));
idx += sizeof(packet2);
if ((idx + 19 + 1) > sizeof(fullPacket)) {
// fullPacket size wrong
Serial.println(F("fullPacket size wrong"));
}
memmove(fullPacket + idx, buffer, 19);
idx += 19;
// should have just one byte left for check sum
if ((idx + 1) != sizeof(fullPacket)) {
// fullPacket size wrong
Serial.println(F("fullPacket size wrong"));
}
int chksum = 0;
for (size_t i = 3; i < idx; i++) { // skip frame start and length, stop before last byte (the checksum
chksum += fullPacket[i]; // will wrap around
}
chksum = (0xff & chksum);
chksum = (0xff) & (0xff - chksum);
fullPacket[idx] = chksum;
idx++; // the total length of the full packet
if (idx != sizeof(fullPacket)) {
Serial.println(F("fullPacket size error"));
}
// print out packet
size_t printSize = idx * 3; // ..<space>
cSF(sfPacket, printSize);
for (size_t i = 0; i < idx; i++) {
//sfPacket += "0x";
if (fullPacket[i] < 16) {
sfPacket += '0'; // add leading 0
}
sfPacket.print(fullPacket[i], HEX); // you can print to SafeStrings
sfPacket.print(' ');
}
Serial.println(sfPacket);
// xbee.write (fullpacket , idx); O los concateno y los mando juntos.
delay(10000);
}
}