I need help from someone that can help me, I have the code bellow to try to connect to a Landis Energy meter, by a GSM modem connected to a COM port in my computer.
Everything goes well until the call to the meter that I get success with answer “CONNECT 9600”, but after that I try to send the authentication to the meter in the line “send_at_command_raw(client.snrmRequest(), ‘OK’)” but I never get any answer from the meter and after a few minutes the call disconnects.
I already tried to check if the bytearray generated by the client.snrmRequest()
I have this bytearray bytearray(b’~xa0x08x02x03x03x93x05w~’) -> ‘7ea0080203039305777e’
Bellow is the log of communication between the modem and the meter if is useful.
enter image description here
Can someone please try to put me in right direction?
Thank you
import serial, time
from gurux_dlms import GXDLMSClient, GXDLMSException, GXReplyData
from gurux_dlms.enums import InterfaceType, Authentication
from gurux_dlms.secure import GXDLMSSecureClient
def send_at_command(command, expected_response, timeout=120):
ser.write((command + 'r').encode())
ser.flush()
response = ''
end_time = time.time() + timeout
while time.time() < end_time:
if ser.in_waiting:
response += ser.read(ser.in_waiting).decode()
if expected_response in response:
return response
return response
def send_at_command_raw(command, expected_response, timeout=120):
ser.write(command)
ser.flush()
response = ''
end_time = time.time() + timeout
while time.time() < end_time:
if ser.in_waiting:
response += ser.read(ser.in_waiting).decode()
if expected_response in response:
return response
return response
# Set up serial connection to the GSM modem
ser = serial.Serial('COM4', baudrate=9600, timeout=1)
# Initialize the modem
response = send_at_command('AT', 'OK')
print(response)
# Dial the remote meter
response = send_at_command('ATD000000000', 'CONNECT')
print(response)
if 'CONNECT' in response:
print("Connected to the remote meter")
else:
print("Failed to connect to the remote meter")
ser.close()
exit()
# Create a DLMS client
client = GXDLMSSecureClient(True)
client.authentication = Authentication.NONE
client.password = b'00000000'
client.clientAddress = 1
client.serverAddress = 129
# Open the connection to the meter
try:
send_at_command_raw(client.snrmRequest(), 'OK')
except GXDLMSException as e:
print(f"Failed to read data from the meter: {e}")
# Close the serial connection
ser.write(b'+++r')
time.sleep(1)
response = send_at_command('ATH0', 'OK')
print(response)
ser.close()
I already tried to change many configurations in the authentication phase, but nothing helps.
Turtuga is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.