Actually I have my serial code as below:
public void readDLMSPacket(byte[] data, GXReplyData reply)
throws Exception {
if (data == null || data.length == 0) {
return;
}
reply.setError((short) 0);
Object eop = (byte) 0x7E;
Integer pos = 0;
boolean succeeded = false;
ReceiveParameters<byte[]> p = new ReceiveParameters<>(byte[].class);
p.setAllData(true);
p.setEop(eop);
p.setCount(5);
p.setWaitTime(WaitTime);
synchronized (serial.getSynchronous()) {
while (!succeeded) {
serial.send(data, null);
if (p.getEop() == null) {
p.setCount(1);
}
succeeded = serial.receive(p);
if (!succeeded) {
// Try to read again...
if (pos++ == 3) {
throw new RuntimeException(
"Failed to receive reply from the device in given time." + GXCommon.bytesToHex(p.getReply()));
}
Log.i("gurux.dlms", "Data send failed. Try to resend "
+ pos.toString() + "/3");
}
}
// Loop until whole DLMS packet is received.
while (!secureClient.getData(p.getReply(), reply)) {
if (p.getEop() == null) {
p.setCount(1);
}
if (!serial.receive(p)) {
// If echo.
if (reply.isEcho()) {
serial.send(data, null);
}
// Try to read again...
if (++pos == 3) {
throw new Exception(
"Failed to receive reply from the device in given time2." + GXCommon.bytesToHex(p.getReply()));
}
Log.i("gurux.dlms", "Data send failed. Try to resend "
+ pos.toString() + "/3");
}
}
}
if (reply.getError() != 0) {
if (reply.getError() == ErrorCode.REJECTED.getValue()) {
Thread.sleep(1000);
readDLMSPacket(data, reply);
} else {
throw new GXDLMSException(reply.getError());
}
}
}
There are a few functions which are serial specific. I am unable to convert them for socket. If I send the bytes directly to socket. I get the same response as the request.
It depends on what kind of BlueTooth device you are using. If Bluetooth device implements socket you can use network media. I believe that you need to make own media for Bluetooth.
We are using BLE with the help of a bluetooth probe. We are using BluetoothGattCallback for sending and receiving request. Can you please give an example or any idea on how to implement GXDLMS with this.
I believe best way to go is if you create new media. Select GXNet as template and change open, close, send and receive methods to communicate with your Bluetooth. In this way you don't need to change anything from the example. Othere option is that you made changes for the example for sending and receiving bytes over Bluetooth.
I am still stuck with the BLE communication with the DLMS meter. On sending the request to the BLE I am receiving junk hex values. Please help me with this.
I am still stuck with the BLE communication with the DLMS meter. On sending the request to the BLE I am receiving junk hex values. Please help me with this.
Hi,
I need to communicate with Energy meter which is integrated with BLE module. Need some basic functionality, In BLE module there are different Services, Characteristics(For Read, Write, Notify). I need to Write the data and read from energy meter. Please let me know as soon as possible. I need to develop Android mobile application.
Thanks in Advance.
Hi,
Hi,
You need to send generated bytes over Bluetooth by your self. GXDLMSSecureClient doesn't care how you send or receive bytes.
BR,
Mikko
Thanks for your quick
Thanks for your quick response.
Actually I have my serial code as below:
public void readDLMSPacket(byte[] data, GXReplyData reply)
throws Exception {
if (data == null || data.length == 0) {
return;
}
reply.setError((short) 0);
Object eop = (byte) 0x7E;
Integer pos = 0;
boolean succeeded = false;
ReceiveParameters<byte[]> p = new ReceiveParameters<>(byte[].class);
p.setAllData(true);
p.setEop(eop);
p.setCount(5);
p.setWaitTime(WaitTime);
synchronized (serial.getSynchronous()) {
while (!succeeded) {
serial.send(data, null);
if (p.getEop() == null) {
p.setCount(1);
}
succeeded = serial.receive(p);
if (!succeeded) {
// Try to read again...
if (pos++ == 3) {
throw new RuntimeException(
"Failed to receive reply from the device in given time." + GXCommon.bytesToHex(p.getReply()));
}
Log.i("gurux.dlms", "Data send failed. Try to resend "
+ pos.toString() + "/3");
}
}
// Loop until whole DLMS packet is received.
while (!secureClient.getData(p.getReply(), reply)) {
if (p.getEop() == null) {
p.setCount(1);
}
if (!serial.receive(p)) {
// If echo.
if (reply.isEcho()) {
serial.send(data, null);
}
// Try to read again...
if (++pos == 3) {
throw new Exception(
"Failed to receive reply from the device in given time2." + GXCommon.bytesToHex(p.getReply()));
}
Log.i("gurux.dlms", "Data send failed. Try to resend "
+ pos.toString() + "/3");
}
}
}
if (reply.getError() != 0) {
if (reply.getError() == ErrorCode.REJECTED.getValue()) {
Thread.sleep(1000);
readDLMSPacket(data, reply);
} else {
throw new GXDLMSException(reply.getError());
}
}
}
There are a few functions which are serial specific. I am unable to convert them for socket. If I send the bytes directly to socket. I get the same response as the request.
Your help would be deeply appreciated.
Thanks & Regards,
Sarbjit Singh
Hi,
Hi,
It depends on what kind of BlueTooth device you are using. If Bluetooth device implements socket you can use network media. I believe that you need to make own media for Bluetooth.
BR,
Mikko
Sir,
Sir,
We are using BLE with the help of a bluetooth probe. We are using BluetoothGattCallback for sending and receiving request. Can you please give an example or any idea on how to implement GXDLMS with this.
Thanks !
Regards,
Sarbjit Singh
Hi,
Hi,
I believe best way to go is if you create new media. Select GXNet as template and change open, close, send and receive methods to communicate with your Bluetooth. In this way you don't need to change anything from the example. Othere option is that you made changes for the example for sending and receiving bytes over Bluetooth.
BR,
Mikko
Hello Sir,
Hello Sir,
I am still stuck with the BLE communication with the DLMS meter. On sending the request to the BLE I am receiving junk hex values. Please help me with this.
Thanks !
Regards,
Sarbjit Singh
Hello Sir,
Hello Sir,
I am still stuck with the BLE communication with the DLMS meter. On sending the request to the BLE I am receiving junk hex values. Please help me with this.
Thanks !
Regards,
Sarbjit Singh
Hello Sir,
Hello Sir,
What kind of data you are sending and receiving? Can you paste sent and received hex strings here?
BR,
Mikko
Sir,
Sir,
This the authentication request:
7E A0 07 03 41 93 5A 64 7E
I am sending it through GXDLMSSecure client as:
secureClient = new GXDLMSSecureClient(true, 32, 1, Authentication.LOW, "XXXX", InterfaceType.HDLC);
I am giving you the converted response.
Regards,
Sarbjit Singh
Hi,
Hi,
The request is correct. What is the reply?
BR,
Mikko
Sir,
Sir,
Please see the attached screenshot after last 7E. I am receiving that response with error.
Thanks !
Regards,
Sarbjit Singh
Hi,
Hi,
Can you print reply as hex string?
BR,
Mikko
Sir,
Sir,
Please see the response in hex below the error message in attached screenshot.
Regards,
Sarbjit SIngh
Hi,
Hi,
This is the echo. This is not a reply from the meter. You have sent this data.
BR,
Mikko
Any Update? I am interested!
Any Update? I am interested!
Please sir, share the source code you trying to build
Hi,
Hi,
We have made a video about how you can read your meter using Bluetooth from Raspberry PI.
http://www.gurux.fi/bluetooth
BR,
Mikko
Did you happen to get an
Did you happen to get an example of this hurani?
Hi,
Hi,
I need to communicate with Energy meter which is integrated with BLE module. Need some basic functionality, In BLE module there are different Services, Characteristics(For Read, Write, Notify). I need to Write the data and read from energy meter. Please let me know as soon as possible. I need to develop Android mobile application.
Thanks in Advance.
Hi Sandeep,
Hi Sandeep,
Please, create a new topic if you have a new question. I'll answer your question there.
https://www.gurux.fi/ForumRules
BR,
Mikko