Page 1 of 1

Best plugin to start from for 2-way serial communication

Posted: 06 Jun 2019, 00:36
by fluppie
I want to develop a serial plugin for ESP Easy that sends and receives commands over software serial.
Which plugin is the best to start from? Using 2-way communication, send and receive.

For example the command to fetch the serial number of the connected device:

Code: Select all

byte stx[] = {0x02};
byte etx[] = {0x03};
byte ack[] = {0x06};
byte cmd1[] = {0x30, 0x34, 0x36, 0x34}; //0464 // Serial Number
byte cmd2[] = {0x30, 0x38, 0x36, 0x38}; //0868 // Unknown
byte cmd3[] = {0x30, 0x39, 0x36, 0x39}; //0969 // Operating time

        mySerial.write(stx[0]);
        mySerial.write(cmd1[0]);
        mySerial.write(cmd1[1]);
        mySerial.write(cmd1[2]);
        mySerial.write(cmd1[3]);
        mySerial.write(etx[0]);
Then to parse incoming data:

Code: Select all

        
//============serial num=============//
void serial_num()
{
  data_array[10] = 0; //terminate original string early
  Serial.print("Serial number: ");
  Serial.println(&data_array[2]);

}

void operating_time()
{
  data_array[10] = 0; //terminate original string early
  runningtime = strtoul(&data_array[2], NULL, 16);
  Serial.println(runningtime); // in quarter seconds

  Serial.print("Running Time: ");
  float runningtimef = runningtime;
  Serial.println(runningtimef / 4 / 60 / 60); // divide decimal number / 4 / 60 / 60 to get running time in hours
}