Discovery Broadcast

The discovery broadcast can be used to find and identify CEMMs in the local network. The broadcast works by sending a UDP message to the broadcast IP of the network on port 9777. The data should be an utf-8 encoded string “cemm_query”. Each CEMM with core version 1.23 and above will respond to this query with an answer containing information about the CEMM, see the example response below.

{
    "ip": "192.168.2.115",
    "mac": "00:1E:C0:85:96:CC",
    "version": "1.24",
    "type": "CEMM_basic",
    "init_state": 1
}

 

A very basic Python implementation to execute the broadcast might look like:

import socket
import time

query_str = b"cemm_query"
broadcast_wait = 5
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
server.bind(("", 9777))
server.settimeout(broadcast_wait)
start = time.time()
server.sendto(query_str, ("192.168.2.255", 9777))
while time.time() < start + broadcast_wait:
    try:
        data, addr = server.recvfrom(1024)
        if data == query_str:
            continue
        else:
            print("%s:%s >>> %s" % (addr[0], addr[1], data))
    except socket.timeout:
        pass
server.close()

This script will output:

192.168.2.153:9777 >>> b'{"ip": "192.168.2.153", "mac": "D8:80:39:46:22:B5", "version": "1.23", "type": "CEMM_basic", "init_state": 1}'
192.168.2.115:9777 >>> b'{"ip": "192.168.2.115", "mac": "00:1E:C0:85:96:CC", "version": "1.24", "type": "CEMM_basic", "init_state": 1}'