[PYTHON] Automatically generate EDT for ECHONET telegram

Purpose

code

MessageGenerator4ECHONET-Lite.py


#! /uer/bin/env python
# -*- coding: utf-8 -*-

import sys

#initial value
setget_flag = True      # True:set,False:I don't know if 0 or 1, which represents the time of get, is faster.
i = 0                   #counter
ipv6Addr = "AAAAAAAA"   #Dummy value. It's actually longer, but it doesn't matter right now, so leave it as it is.

GET_E2 = b"\x10\x81\x12\x34\x05\xFF\x01\x02\x88\x01\x62\x01\xE2\x00"
#Integrated electric energy measurement value history 1(Positive measurement)(EPC=0xE2)
SET_E5_base = "1081123405FF010288016201E501"
#Accumulation history collection date 1(0:On the day 1~99:Days of the previous day)(EPC=E5)

#The while statement is used for the convenience of the application destination.
while 1:
    if setget_flag == True:
        #Behavior at set
        #Create an E5 telegram
        SET_E5 = bytes.fromhex(SET_E5_base + '{:02X}'.format(i))
        command = "SKSENDTO 1 {0} 0E1A 1 {1:04X} {2}".format(ipv6Addr, len(SET_E5), SET_E5)
        setget_flag = False  #False flag:to get
        print(command)
    else :
        #Behavior at get
        #The E2 telegram is the same every time, so leave it as it is
        command = "SKSENDTO 1 {0} 0E1A 1 {1:04X} {2}".format(ipv6Addr, len(GET_E2), GET_E2)
        setget_flag = True   #Flag True:to set
        i += 1               #Increment on the telegram side to be sent later
        print(command)
    #When the number of telegrams created is 100, the thread winter ends
    if i == 100:
        print("100th thread winter end")
        sys.exit()  ####Thread winter end####

result

SKSENDTO 1 AAAAAAAA 0E1A 1 000F b'\x10\x81\x124\x05\xff\x01\x02\x88\x01b\x01\xe5\x01\x00'
SKSENDTO 1 AAAAAAAA 0E1A 1 000E b'\x10\x81\x124\x05\xff\x01\x02\x88\x01b\x01\xe2\x00'
~abridgement~
SKSENDTO 1 AAAAAAAA 0E1A 1 000F b'\x10\x81\x124\x05\xff\x01\x02\x88\x01b\x01\xe5\x01c'
SKSENDTO 1 AAAAAAAA 0E1A 1 000E b'\x10\x81\x124\x05\xff\x01\x02\x88\x01b\x01\xe2\x00'
100th thread winter end

Consideration

Reference material

How to write Python comments and comment outs

Postscript

Recommended Posts

Automatically generate EDT for ECHONET telegram
Automatically generate a polarity dictionary used for sentiment analysis
Generate Custom Sizes for ArtRage4