You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 17, 2021. It is now read-only.
I noticed a strange behaviour when I tried to send and receive raw byte date on a serial device. Sometimes I would get completely different bytes in the rule that handled the serial port string item. Later I found out that this seams to be a problem because OpenHab uses UTF-8 to build strings by default. This means that if certain bytes are sent over the serial port those are encoded to a different byte by the UTF-8 standard.
I also created a forum thread for this issue here, but didn't receive any feedback so far.
Expected Behavior
I expect that the bytes that are sent by the serial device appear 1 to 1 in the string item received in the OpenHab rule.
Current Behavior
By the current behaviour all bytes from serial ports are being UTF-8 encoded and decoded. Devices that are not using UTF-8 to send data may have problems with this.
Possible Solution
I already tested some changes and it seams to work very good with my device now. I made the following changes in SerialDevice.java:
Line 279 changed to: sb.append(new String(readBuffer, 0, bytes, Charset.forName(“ISO-8859-1”)));
Line 328 changed to: result = Base64.encodeBase64String(result.getBytes(Charset.forName(“ISO-8859-1”)));
Line 386 changed to: outputStream.write(msg.getBytes(Charset.forName(“ISO-8859-1”)));
The question is if this should be the default and only charset or if some devices or if the charset should be customizable for each device.
Steps to Reproduce (for bugs)
Just send some bytes that would be UTF-8 decoded to a different byte (e.g. 0xAE ) and see if the correct byte is inserted into the string. Here is also a small example that can be run in ecplise in a simple test application:
I noticed a strange behaviour when I tried to send and receive raw byte date on a serial device. Sometimes I would get completely different bytes in the rule that handled the serial port string item. Later I found out that this seams to be a problem because OpenHab uses UTF-8 to build strings by default. This means that if certain bytes are sent over the serial port those are encoded to a different byte by the UTF-8 standard.
I also created a forum thread for this issue here, but didn't receive any feedback so far.
Expected Behavior
I expect that the bytes that are sent by the serial device appear 1 to 1 in the string item received in the OpenHab rule.
Current Behavior
By the current behaviour all bytes from serial ports are being UTF-8 encoded and decoded. Devices that are not using UTF-8 to send data may have problems with this.
Possible Solution
I already tested some changes and it seams to work very good with my device now. I made the following changes in SerialDevice.java:
Line 279 changed to: sb.append(new String(readBuffer, 0, bytes, Charset.forName(“ISO-8859-1”)));
Line 328 changed to: result = Base64.encodeBase64String(result.getBytes(Charset.forName(“ISO-8859-1”)));
Line 386 changed to: outputStream.write(msg.getBytes(Charset.forName(“ISO-8859-1”)));
The question is if this should be the default and only charset or if some devices or if the charset should be customizable for each device.
Steps to Reproduce (for bugs)
Just send some bytes that would be UTF-8 decoded to a different byte (e.g. 0xAE ) and see if the correct byte is inserted into the string. Here is also a small example that can be run in ecplise in a simple test application:
Your Environment
OpenHabian on Raspberry Pi 3
The text was updated successfully, but these errors were encountered: