Rules, string parsing and serialsend

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
boolie
Normal user
Posts: 20
Joined: 23 May 2018, 21:35

Rules, string parsing and serialsend

#1 Post by boolie » 31 May 2018, 18:56

Hi All,

I'm looking at the way strings are handled by the serialsend command. I thought I would be able to escape tabs, newlines and the like and also to encode non-printable characters as \xAA, but everything I try to send is just sent exactly as typed, no parsing. I'm experimenting with trying to control some devices that have bespoke serial command protocols, some of which include non-printable characters and/or need carriage return or tab codes in the message.

Looking at the code in P20.ino, I see that serialsend simply takes the remainder of the line after the "serialsend" bit and sends it to serial.println(), presumably as a string type. This means that serial.println can't interpret any arguments in the remainder of the ESPEasy rule line and just takes it all as a literal ASCII string. That seems to stop it even converting the usual \n, \t, etc.

From P20:
<code>
case PLUGIN_WRITE:
{
String command = parseString(string, 1);
if (command == F("serialsend"))
{
success = true;
String tmpString = string.substring(11);
Serial.println(tmpString);
}
break;
}
</code>

Is there any way to encode a string within a rule, before then getting that string sent to the serial port?

Or would I have to think about writing a plug-in to handle arbitrary serial data streams? Doesn't seem to difficult (apart from finding the time!)
Various D1 & Sonoffs with ESPEasy, some Tasmota. Domoticz, Z-wave.
ESPEasy Patreon - keep up the good stuff, guys!

Post Reply

Who is online

Users browsing this forum: No registered users and 96 guests