I managed to write a python script based on some old documentation I found that fixed this:
import socket
debug = True
test_payload = True
def calculate_checksum(payload):
return sum(payload)
# Set up the connection
ip = "192.168.1.52"
port = 8899
header = [0x18, 0x96, 0x18, 0x20]
if test_payload:
payload_str = "MCU+VOL+050"
else:
# turn off beep
#payload_str = "MCU+PAS+RAKOIT:BEP:0&"
# volume increments=1
payload_str = "MCU+PAS+RAKOIT:VST:1&"
payload_bytes = [ord(c) for c in payload_str]
# Calculate the length of the payload
payload_length = len(payload_bytes)
length_bytes = [payload_length & 0xFF, (payload_length >> 8) & 0xFF, (payload_length >> 16) & 0xFF, (payload_length >> 24) & 0xFF]
# Calculate the checksum
checksum = calculate_checksum(payload_bytes)
checksum_bytes = [checksum & 0xFF, (checksum >> 8) & 0xFF, (checksum >> 16) & 0xFF, (checksum >> 24) & 0xFF]
# Add reserved bytes (assuming 8 reserved bytes as in the original example)
reserved_bytes = [0x00] * 8
# Create the full message with header, length, checksum, reserved, and payload bytes
message = header + length_bytes + checksum_bytes + reserved_bytes + payload_bytes
message_bytes = bytes(message)
#print([f'0x{byte:02x}' for byte in message_bytes])
if debug:
print("---- DEBUG ---- ")
print("Header: ", bytes(header))
print("Length: ", bytes(length_bytes))
print("Checksum: ", bytes(checksum_bytes))
print("Reserved: ", bytes(reserved_bytes))
print("Payload: ", bytes(payload_bytes))
print("My message: ", message_bytes)
if test_payload:
expected_message_bytes = bytes([0x18, 0x96, 0x18, 0x20, 0x0b, 0x00, 0x00, 0x00, 0xc1, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x43, 0x55, 0x2b, 0x56, 0x4f, 0x4c, 0x2b, 0x30, 0x35, 0x30])
if debug:
print("Expected message:", expected_message_bytes)
# Compare the message_bytes and expected_message_bytes
if message_bytes == expected_message_bytes:
print("The message_bytes is correct!")
else:
print("The message_bytes is not correct.")
# Create a socket object and connect to the specified IP and port
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, port))
# Send the new payload
s.sendall(message_bytes)
# Wait for a response (optional)
response = s.recv(1024)
print(f"Received response: {response}")
# Close the connection
s.close()