3 # This script can be used to configure the Inverter IDs
4 # on an Envertech EnverBridge device. This is a replacement
5 # for the "SetID" programm provided as a Win32 executable at
6 # http://www.envertec.com/uploads/bigfiles/Set%20ID.zip
7 # Tested online with the EnverBridge 202 and a EVT 560 module
10 # Logic seems the be the following:
11 # Take the inverter id, append the char 9 to 16 of the 16 char
12 # serial number. Do this for every pair of serial numbers.
13 # Sent this string in one UDP paket to the broadcast address on
14 # port 8765. Wait for a response paket to the broadcast address
17 from optparse import OptionParser
22 parser = OptionParser(usage="usage: %prog [options] MIIDs")
23 parser.add_option("-b", "--bid",
27 help="Serial Number of your EnverBridge")
28 (options, args) = parser.parse_args()
31 def validateMIID(miids):
33 idpattern = re.compile(r"^CN[0-9]{14}$")
35 print("Validating MIID", id)
36 if not idpattern.search(id):
37 print("Error: Invalid MIID", id)
41 print("Validation error, check your MIIDs, exiting")
45 def buildMIIDList(miids):
52 # minimal input validation
54 print("Error: missing MIIDs, provide at least one inverter serial")
59 # assemble message string and convert to bytes
60 message = str(options.bid) + buildMIIDList(args)
61 message = message.encode()
62 print('Sending to EnverBridge with ID', options.bid)
64 # Create a UDP client socket w/ broadcast
65 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
66 sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
68 # Create a UDP server socket we bind to to listen for broadcasts
69 ssock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
70 ssock.bind(('', 8764))
73 # Send data via broadcast to port 8765
74 print('Sending {!r}'.format(message))
75 server_address = ('<broadcast>', 8765)
76 sent = sock.sendto(message, server_address)
78 # Receive response on port 8764
79 print('Waiting to receive')
80 data, server = ssock.recvfrom(8764)
81 print('Received {!r}'.format(data))
84 print('Closing sockets')