Interactive MQTT packet manipulation shell based on IPython
You would love it if your are an expert of MQTT and Python
pip install imqtt
or installing from source code
python setup.py install
$ imqtt
In [1]: c = TCPClient(host = '127.0.0.1', port = 1883)
('connected to', '127.0.0.1', 1883)
In [2]: p = ConnectPacket()
In [3]: c.Send(p)
Out[3]: <__main__.TCPClient instance at 0x215c518>
In [4]: ack = c.Recv()
In [5]: ack
Out[5]: <ConnackPacket <FixedHeader ControlPacketType: 0x2, ControlPacketFlags: 0, RemainingLength: 2>, Flags: 0x1, ReturnCode: 0x0>
In [6]: pp = PublishPacket(Topic = '/imqtt/test', Payload = 'Hello world', QoS = 1, PacketID = 1)
In [7]: pp
Out[7]: <PublishPacket <FixedHeader ControlPacketType: 0x3, ControlPacketFlags: 0, RemainingLength: 0>, Dup: 0, QoS: 1, Retain: 0, PacketID: 1, Topic: /imqtt/test, Payload: Hello world>
In [8]: c.Send(pp).Recv()
Out[8]: <PubackPacket <FixedHeader ControlPacketType: 0x4, ControlPacketFlags: 0, RemainingLength: 2>, PacketID: 1>
Welcome to imqtt !
An iteractive MQTT packet manipulation shell based on IPython.
Github: https://github.com/shafreeck/imqtt
In [1]: s = TCPServer(host = '127.0.0.1', port = 1883)
listening on 127.0.0.1 1883
In [2]: s.Serve()
Packet received
This is an interactive environment, and being triggered when there was a packet received.
There are some varibles you can use:
self: the tcp server object
buf : current data received
p : the packet that unmarshaled from buf
Also, all python features are avaliable. Type 'exit()' or press 'Ctrl-D' to quit the shell.
In [1]: p
Out[1]: <ConnectPacket <FixedHeader ControlPacketType: 0x1, ControlPacketFlags: 0, RemainingLength: 17>, Protocol: bytearray(b'MQTT'), Version: 4, <Flags UsernameFlag: 0, PasswordFlag: 0, WillRetain: 0, WillQoS: 0, WillFlag: 0, CleanSession: 1>, KeepAlive: 300, ClientID: bytearray(b'imqtt'), Username: , Password: >
In [2]: self.Send(ConnackPacket())
Out[2]: <imqtt.TCPServer at 0x10b890e10>
In [3]: exit()
Continue to serve...