Best plugin to start from for 2-way serial communication

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
fluppie
Normal user
Posts: 79
Joined: 09 Oct 2015, 13:23

Best plugin to start from for 2-way serial communication

#1 Post by fluppie » 06 Jun 2019, 00:36

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
}

fluppie
Normal user
Posts: 79
Joined: 09 Oct 2015, 13:23

Re: Best plugin to start from for 2-way serial communication

#2 Post by fluppie » 03 Aug 2019, 10:57

Anyone who can tell me which serial plugin is using the best for send / receive within the plugin?

TD-er
Core team member
Posts: 1339
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Best plugin to start from for 2-way serial communication

#3 Post by TD-er » 03 Aug 2019, 13:12

I am already working on it.
See my progress here:
https://github.com/TD-er/ESPEasy/tree/f ... rial_proxy

Current status:
It can read a string from serial and send it (as a string) to a controller.

Still to do:
- user define init string (to initiate device connected)
- Add some timeout settings (when is a sentence finished, or when to send init string again)
- Add pin to allow to reset connected device
- Option to interpret received data as numerical.
- Receive strings/values from controller. (that's going to be a lot of work)

fluppie
Normal user
Posts: 79
Joined: 09 Oct 2015, 13:23

Re: Best plugin to start from for 2-way serial communication

#4 Post by fluppie » 05 Aug 2019, 11:09

OK cool, I tried the custom and dev build. Or should I self-compile to get this one in?

TD-er
Core team member
Posts: 1339
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Best plugin to start from for 2-way serial communication

#5 Post by TD-er » 05 Aug 2019, 20:47

Self compile.
I have not yet included in any build, since it is really a work in progress.
But since it also needed some changes in the rest of ESPeasy I didn't want to wait to long to merge it or else I may trouble myself in merging future pull requests.
So that's why I already merged it, but it will change in the next week.
A work-in-progress so to speak.

fluppie
Normal user
Posts: 79
Joined: 09 Oct 2015, 13:23

Re: Best plugin to start from for 2-way serial communication

#6 Post by fluppie » 07 Aug 2019, 14:28

Do I need to define/undefine something? Since it's not appearing in the normal, testing and dev build when self-compiling.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests