Serial Port - Base64

I have problem with serial port, when I send data Base64 encoded.

Port definition: serial="/dev/ttyAMA0@38400,CHARSET(ISO-8859-1),BASE64"

Data to send: AA012000030110000A0307027155 (hex)
Base64 : qgEgAAMBEAAKAwcCcVU=

On hadware serial a get ASCII number of Base64 characters: q 0x71, g 0x67 …

But I need this AA012000030110000A0307027155 (hex)

What is wrong?


Sorry for my bad english.

Hi Carl,
have a look at . You need to decode the received BASE64 string.

Thanks for replay.
Problem is not when I received data. Problem is sending data over serial port. I use command

Here’s a post about sending hex

and another

It is working, but only when is command hardcoded in rule. But in my case I need dynamic create a command…It looks like is impossible to do it.

Show us your rule, if that works.

When I have this in Rule:

It is working. But this:

val hex = new String(‘AA012000030110000A0307027155’)

val hexCommand = new String(’’)
for ( var j = 0; j < hex.length(); j+=2 ) {
hexCommand = hexCommand+"\"+“u00”+hex.substring(j, j+2)

Not working.

Hi Carl,
the backslash in
is used as an escape identifier.
The backslash in your code is a literal backslash and does not escape the character after it.
Your may try this code in your rule:

  val hex = new String('AA012000030110000A0307027155')
  val hexCommand = new String('')

  for ( var j = 0; j < hex.length(); j+=2 ) {
     hexCommand = hexCommand + Integer::parseInt( hex.substring( j, j+2 ), 16 ) as char

I tested the conversion itself but not if the sendcommand itself works.

1 Like

Many thanks, your code is working.

Problem is solved :slight_smile: