Пример #1
0
def on_topicAllSignonReq(client, userdata, message):
    """ docstring"""

    on_topic_str = slaveTopicMaker.makeTopicSignonReq()

    logger.debugf("on_topic(%s) BEGIN", on_topic_str)

    logger.debugf("ID=%s= U=%s= Msg=%s=", client, userdata, message)

    jstr = message.payload.decode()
    logger.debugf("msg.topic=%s= payload=%s= qos=%s=", message.topic, jstr,
                  message.qos)

    rmtCfg = ConfigDict.fromJsonStr(jstr)

    rspTopicMaker = TopicMaker(rmtCfg.getMacAddrSelf())

    myCfgDct = ConfigListOfDict.getInstance().findConfigDict(
        activeNIF.getMacAddrAsHexStr(), mySysType)

    jstr = myCfgDct.toJsonStr()

    mqtt.publish(rspTopicMaker.makeTopicSignonRsp(), jstr, qos=0, retain=False)

    logger.debugf("on_topic(%s) END", on_topic_str)

    return
Пример #2
0
def on_topicCmd(client, userdata, message):
    """
        on_topicCmd
    """
    on_topic_str = slaveTopicMaker.makeTopicCmdReq()

    logger.debugf("on_topic(%s) BEGIN", on_topic_str)

    jstr = message.payload.decode()
    logger.debugf("msg.topic=%s= payload=%s= qos=%s=", message.topic, jstr,
                  message.qos)

    rmtCfg = ConfigDict.fromJsonStr()

    rspTopicMaker = TopicMaker(rmtCfg.getMacAddrSelf())

    rspTopic = rspTopicMaker.makeTopicCmdRsp()

    rmtCfg.setMqPub(rspTopic)

    rmtCfg.setMqSub(on_topic_str)

    rmtCfg.setCmdRsp('Command complete')

    jstr = rmtCfg.toJsonStr()

    mqtt.publish(rspTopic, jstr, qos=0, retain=False)

    logger.debugf("on_topic(%s) END", on_topic_str)

    return
Пример #3
0
def updateSlaveConfigDict(message):

    logger.debugf("newSlaveConfigDict BEGIN")

    jstr = message.payload.decode()

    logger.debugf("Msg=%s=" % jstr)

    rmtDct = ConfigDict.fromJsonStr(jstr)

    lclDct = ConfigListOfDict.getInstance().updateCfgDct(rmtDct)

    if not lclDct:
        ConfigListOfDict.getInstance().addConfigDict(rmtDct)
        rmtDct.setMsgLast()

    debugWriteConfigFileUpd(Constants.CFG_FILE_NAME_DEBUG_MASTER)

    logger.debugf("newSlaveConfigDict END")
    return
Пример #4
0
def updateLocalDhcpRecordWithRemoteData(mqttMessage):

    logger.debugf("updateLocalDhcpRecordWithRemoteData BEGIN")

    sstr = mqttMessage.payload.decode()  # convert from binary to string

    remoteDhcpDict = ConfigDict.fromJsonStr(sstr)

    localCfgDict = ConfigListOfDict.getInstance().updateCfgDct(remoteDhcpDict)

    if not localCfgDict:
        ConfigListOfDict.getInstance().appendConfigDict(remoteDhcpDict)
        localCfgDict = remoteDhcpDict

    localCfgDict.setMsgLast()

    debugWriteConfigFileUpd(Constants.CFG_FILE_NAME_DEBUG_DHCP)

    logger.debugf("msgPLd=%s=" % localCfgDict)

    logger.debugf("updateLocalDhcpRecordWithRemoteData END")

    return localCfgDict
Пример #5
0
###########################################################################################

SysLogger.initialize(__name__, 'master.log',
                     "%(asctime)s — %(name)s — %(levelname)s — %(message)s",
                     logging.DEBUG)

logger = SysLogger.getLogger()

logger.info("Log Started")

myMacAddr = hex(uuid.getnode())  # hex returns a string

dhcpConfig = ConfigListOfDict()
dhcpConfig.addConfigDict(Constants.CFG_DEFAULT_DHCP_RECORD)

dhcpRec = ConfigDict(Constants.CFG_DEFAULT_DHCP_RECORD)

###########################################################################################
###########################################################################################
###########################################################################################
###########################################################################################

msg = '{oc}"{s1}":"{s2}"{cc}'.format(oc='{',
                                     s1=Constants.CFG_KEY_MAC_SELF,
                                     s2=myMacAddr,
                                     cc='}')
logger.debug("Publishing::topic={}= msg={}=".format(dhcpRec.makeTopicDhcpReq(),
                                                    msg))

out = []
out.append(Constants.CFG_DEFAULT_DHCP_RECORD)