Hi,
I’m trying to send API frame (hexadecimal) from a PC to a Zigbee S2C, attached to an Arduino.
Arduino is connected to the PC (Serial, pin 0/1) and Zigbee S2C (software serial pin 2/3 ; XBserial).
It works fine if the Arduino send itself the API frame, with the following code :
byte XBdata;
byte PCdata;
void setup ()
{
Serial.begin(38400);
XBserial.begin(38400);
// send one time the API frame (OK)
PCdata = {0x7E, 0x00, 0x04, 0x08, 0x01, 0x4E, 0x44, 0x64); // AT command (ND)
XBSerial.write(PCdata, 8);
}
void loop()
{
// print on PC serial console the result (OK)
if (XBserial.available())
{
XBdata = XBserial.read();
Serial.print(XBdata, HEX);
}
}
But, I would like to send API frame from the PC instead from Arduino.
So in a nutshell :
1 - read the data (API frame) from the PC (serial)
2 - write / send the data on Zigbee S2C (software serial)
3 - read (software serial) and print (serial) the answer to PC
I’ve tried this way, but no result (following data send from PC : “7E 00 04 08 01 4E 44 64 \r”, via the Arduino IDE serial monitor)
byte XBdata;
String PCdata;
void setup ()
{
Serial.begin(38400);
XBserial.begin(38400);
}
void loop()
{
// print on PC serial console the result from XBEE
if (XBserial.available())
{
XBdata = XBserial.read();
Serial.print(XBdata, HEX);
}
// send to XBEE API frame received form PC
if (Serial.available())
{
PCdata = Serial.readStringUntil(‘\r‘);
XBserial.print(PCdata);
}
}
Self-analysis : readStringUntil give a String and not a byte array, so I can’t use XBserial.write.
Do you have an idea about what’s wrong ? is there an good way to achieve that ?
Many thanks and best regards,