Carl.c
(C)
January 31, 2020, 8:57pm
1
Hello,
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?
Thanks.
Sorry for my bad english.
Wolfgang_S
(Wolfgang_S)
January 31, 2020, 9:07pm
2
Hi Carl,
have a look at https://www.openhab.org/addons/bindings/serial1/ . You need to decode the received BASE64 string.
Carl.c
(C)
January 31, 2020, 9:27pm
3
Thanks for replay.
Problem is not when I received data. Problem is sending data over serial port. I use command
ItemName.SendCommand
rossko57
(Rossko57)
January 31, 2020, 10:37pm
4
Here’s a post about sending hex
I have a few US-100 serial ultrasonic distance sensors, I think I understand how to get data from the sensor, but before I do that I need to send 0x55 out that port.
My item for reading the sensor is:
String Hydrogen_Peroxide_Sensor {serial="/dev/ttyUSB1@9600,BASE64"}
and another
I am trying to send a packet of HEX codes out the serial port, but every time I try to send the packet every number is correct so long as it is below 0x3F or 63 in decimal. I am using a Null modem cable to view the sent serial data in a terminal program. Very new at OpenHAB so any help would be great.
This is the line I use…
sendCommand(RS485Bus,’\u0091\u0002\u0001\u0008\u0059\u0010\u0020\u0002’)
As mentioned all the values are sent correctly except the \u0091 which shows up as 0x3F. Any valu…
Carl.c
(C)
February 1, 2020, 7:16pm
5
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.
rossko57
(Rossko57)
February 1, 2020, 7:52pm
6
Show us your rule, if that works.
Carl.c
(C)
February 1, 2020, 8:53pm
7
When I have this in Rule:
Serial_Port.sendCommand(’\u00AA\u0001\u0020\u0000\u0003\u0001\u0010\u0000\u000A\u0003\u0007\u0002\u0071\u0055’)
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)
}
Serial_Port.sendCommand(hexCommand)
Not working.
Wolfgang_S
(Wolfgang_S)
February 2, 2020, 10:47am
8
Hi Carl,
the backslash in
\u00AA
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
Serial_Port.sendCommand(hexCommand)
}
I tested the conversion itself but not if the sendcommand itself works.
end
1 Like
Carl.c
(C)
February 2, 2020, 11:20am
9
Many thanks, your code is working.
Problem is solved