# on an Envertech EnverBridge device. This is a replacement
# for the "SetID" programm provided as a Win32 executable at
# http://www.envertec.com/uploads/bigfiles/Set%20ID.zip
-# Tested online with the EnverBridge 202 and Inverters which
-# have the same serial nummer on both labels.
+# Tested online with the EnverBridge 202 and a EVT 560 module
+# inverter.
#
# Logic seems the be the following:
# Take the inverter id, append the char 9 to 16 of the 16 char
# port 8765. Wait for a response paket to the broadcast address
# on port 8764.
-from optparse import OptionParser
+import argparse
import socket
import sys
import re
-parser = OptionParser(usage="usage: %prog [options] MIIDs")
-parser.add_option("-b", "--bid",
- action="store",
- type="int",
- dest="bid",
- help="Serial Number of your EnverBridge")
-(options, args) = parser.parse_args()
+parser = argparse.ArgumentParser()
+parser.add_argument("-b",
+ "--bid",
+ action="store",
+ type=int,
+ dest="bid",
+ required=True,
+ help="Serial Number of your EnverBridge")
+parser.add_argument("miids", nargs="+", help="MIIDs of your MicroInverter")
+args = parser.parse_args()
def validateMIID(miids):
def buildMIIDList(miids):
msg = ""
for id in miids:
- msg = msg + id[8:16] + id[8:16]
+ msg = msg + id[8:16]
return msg
-# minimal input validation
-if len(args) < 1:
- print("Error: missing MIIDs, provide at least one inverter serial")
- sys.exit(22)
-
-validateMIID(args)
+validateMIID(args.miids)
# assemble message string and convert to bytes
-message = str(options.bid) + buildMIIDList(args)
+message = str(args.bid) + buildMIIDList(args.miids)
message = message.encode()
-print('Sending to EnverBridge with ID', options.bid)
+print('Sending to EnverBridge with ID', args.bid)
# Create a UDP client socket w/ broadcast
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)