def main(): global args, cfg parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', dest='config', default='config.cfg', help="Config file. Default: config.cfg") args = parser.parse_args() config = configparser.ConfigParser() config.read(args.config) cfg = config['listener'] llg.setLevel(cfg['debug']) me.listen(recv_packet)
def udp_listen_thread(bclient): global last last = {} me.listen(recv_packet_from_udp)
Created on 26.12.2018 @author: dz Listen to all the traffic on MQTT/UDP, print ''' # will work even if package is not installed import sys sys.path.append('..') #sys.path.append('../mqttudp') import mqttudp.engine as me def recv_packet(pkt): if pkt.ptype != me.PacketType.Publish: print(str(pkt.ptype) + ", " + pkt.topic + "\t\t" + str(addr)) return print(pkt.topic + "=" + pkt.value + "\t\t" + str(pkt.addr)) if __name__ == "__main__": print("Will dump all MQTT/UDP packets recv'd") #me.set_bind_address( "192.168.1.100" ) #me.set_bind_address( "fe80::cc0e:5f41:9089:d43c%5:" ) #me.set_broadcast_address( "192.168.255.255" ) me.listen(recv_packet)
def recv_thread(): me.listen(relcom.recv_packet)
"node/name" : "Unnamed", "node/location" : "Nowhere", # items we want to send out. # remote configuration must tell # us which topics to use "topic/test" : "test", "topic/ai0" : "unnamed_ai0", "topic/di0" : "unnamed_di0", "topic/pwm0" : "unnamed_pwm0", } def send_thread(): while True: n = str(random.randint(0, 9)) print( "Send "+n ) rcfg.publish_for( "test", n ) time.sleep(2) if __name__ == "__main__": print( "Will demonstrate remote config, now run tools/viewer and open remote config UI" ) rcfg.init( init_items ) st = threading.Thread(target=send_thread, args=()) st.start() mq.listen( rcfg.recv_packet )