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
}

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

Posted: 03 Aug 2019, 10:57
by fluppie
Anyone who can tell me which serial plugin is using the best for send / receive within the plugin?

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

Posted: 03 Aug 2019, 13:12
by TD-er
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)

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

Posted: 05 Aug 2019, 11:09
by fluppie
OK cool, I tried the custom and dev build. Or should I self-compile to get this one in?

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

Posted: 05 Aug 2019, 20:47
by TD-er
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.

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

Posted: 07 Aug 2019, 14:28
by fluppie
Do I need to define/undefine something? Since it's not appearing in the normal, testing and dev build when self-compiling.

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

Posted: 06 Sep 2019, 11:34
by fluppie
Any update on this? Is it included in the testing builds or do we need to uncomment something to use it?

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

Posted: 06 Sep 2019, 11:50
by TD-er
The SerialProxy plugin is merged into mega branch and should be included in the "custom" build (if that one is included in the nightly's)

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

Posted: 06 Sep 2019, 20:48
by fluppie
ESP_Easy_mega-20190903_custom_ESP8266_4M1M

Should be this one then :)?

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

Posted: 07 Sep 2019, 00:28
by TD-er
Yep, please let me know if you like the general idea of it or need some changes to make it really useful.
It is currently only sending 1 string you can specify in the plugin and sending any line of text to the controller you specify.
N.B. not all controllers support sending strings, but at least the MQTT controllers do.