예제 #1
0
class JNMQTTMate(Mate):
    def __init__(self, option, devinfo, coupleid, logger):
        self._jnmqtt = JNMQTT(option, DevInfo(devinfo), logger)
        super(JNMQTTMate, self).__init__(option, devinfo, coupleid, logger)

    def connect(self):
        self._jnmqtt.connect(True)
        super(JNMQTTMate, self).connect()
        return True

    def close(self):
        self._jnmqtt.close()
        super(JNMQTTMate, self).close()

    def start(self, writecb):
        self._jnmqtt.start(self.onmsg)
        super(JNMQTTMate, self).start(writecb)
        self.connect()

    def stop(self):
        self._jnmqtt.stop()
        super(JNMQTTMate, self).stop()
        self.close()

    def writeblk(self, blk):
        self._jnmqtt.writeblk(blk)

    def onmsg(self, client, obj, blk):
        print("JNMQTTMate Received mblock '" + str(blk.payload) +
              "' on topic '" + blk.topic + "' with QoS " + str(blk.qos))
        #mrchoi87
        self._logger.info("JNMQTTMate Received mblock '" + str(blk.payload) +
                          "' on topic '" + blk.topic + "' with QoS " +
                          str(blk.qos))

        msg = self._jnmqtt.getpropermsg(blk)
        if msg is None:
            self._logger.warn("The message is not proper " + str(blk))
            return None

#        try:
        tmp = blk.topic.split('/')

        if JNMQTT._SVR == tmp[2] and JNMQTT._STAT == tmp[3]:
            if blk.payload == _STAT_ON:
                self._logger.info("The server is OK now.")
            else:
                self._logger.warn("The server might have some problems.")

        if BlkType.isrequest(msg.gettype()):
            ret = self.writecb(msg)
        else:
            self._logger.warn("Wrong message : " + blk.payload)
예제 #2
0
 def __init__(self, option, devinfo, coupleid, logger):
     self._jnmqtt = JNMQTT(option, DevInfo(devinfo), logger)
     super(JNMQTTMate, self).__init__(option, devinfo, coupleid, logger)
예제 #3
0
 def __init__(self, option, devinfo, coupleid, logger):
     self._jnmqtt = JNMQTT(option, DevInfo(devinfo), logger)
     self._farmosdb = FarmosDB(option, DevInfo(devinfo), logger)
     super(FarmosMate, self).__init__(option, devinfo, coupleid, logger)