MqttMonitor/MqttReasonCodes.py

branch
eric7
changeset 123
3d7e63ed4fd1
parent 114
8c0e9e602124
child 129
9d54bf366323
equal deleted inserted replaced
122:28d69b9e1b6a 123:3d7e63ed4fd1
11 11
12 from paho.mqtt.packettypes import PacketTypes 12 from paho.mqtt.packettypes import PacketTypes
13 13
14 MqttReasonCodeNames = { 14 MqttReasonCodeNames = {
15 0: { 15 0: {
16 QCoreApplication.translate( 16 QCoreApplication.translate("MqttReasonCodeNames", "Success"): [
17 "MqttReasonCodeNames", "Success" 17 PacketTypes.CONNACK,
18 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC, 18 PacketTypes.PUBACK,
19 PacketTypes.PUBREL, PacketTypes.PUBCOMP, PacketTypes.UNSUBACK, 19 PacketTypes.PUBREC,
20 PacketTypes.AUTH], 20 PacketTypes.PUBREL,
21 QCoreApplication.translate( 21 PacketTypes.PUBCOMP,
22 "MqttReasonCodeNames", "Normal disconnection" 22 PacketTypes.UNSUBACK,
23 ): [PacketTypes.DISCONNECT], 23 PacketTypes.AUTH,
24 QCoreApplication.translate( 24 ],
25 "MqttReasonCodeNames", "Granted QoS 0" 25 QCoreApplication.translate("MqttReasonCodeNames", "Normal disconnection"): [
26 ): [PacketTypes.SUBACK]}, 26 PacketTypes.DISCONNECT
27 ],
28 QCoreApplication.translate("MqttReasonCodeNames", "Granted QoS 0"): [
29 PacketTypes.SUBACK
30 ],
31 },
27 1: { 32 1: {
28 QCoreApplication.translate( 33 QCoreApplication.translate("MqttReasonCodeNames", "Granted QoS 1"): [
29 "MqttReasonCodeNames", "Granted QoS 1" 34 PacketTypes.SUBACK
30 ): [PacketTypes.SUBACK]}, 35 ]
36 },
31 2: { 37 2: {
32 QCoreApplication.translate( 38 QCoreApplication.translate("MqttReasonCodeNames", "Granted QoS 2"): [
33 "MqttReasonCodeNames", "Granted QoS 2" 39 PacketTypes.SUBACK
34 ): [PacketTypes.SUBACK]}, 40 ]
41 },
35 4: { 42 4: {
36 QCoreApplication.translate( 43 QCoreApplication.translate(
37 "MqttReasonCodeNames", "Disconnect with will message" 44 "MqttReasonCodeNames", "Disconnect with will message"
38 ): [PacketTypes.DISCONNECT]}, 45 ): [PacketTypes.DISCONNECT]
46 },
39 16: { 47 16: {
40 QCoreApplication.translate( 48 QCoreApplication.translate("MqttReasonCodeNames", "No matching subscribers"): [
41 "MqttReasonCodeNames", "No matching subscribers" 49 PacketTypes.PUBACK,
42 ): [PacketTypes.PUBACK, PacketTypes.PUBREC]}, 50 PacketTypes.PUBREC,
51 ]
52 },
43 17: { 53 17: {
44 QCoreApplication.translate( 54 QCoreApplication.translate("MqttReasonCodeNames", "No subscription found"): [
45 "MqttReasonCodeNames", "No subscription found" 55 PacketTypes.UNSUBACK
46 ): [PacketTypes.UNSUBACK]}, 56 ]
57 },
47 24: { 58 24: {
48 QCoreApplication.translate( 59 QCoreApplication.translate("MqttReasonCodeNames", "Continue authentication"): [
49 "MqttReasonCodeNames", "Continue authentication" 60 PacketTypes.AUTH
50 ): [PacketTypes.AUTH]}, 61 ]
62 },
51 25: { 63 25: {
52 QCoreApplication.translate( 64 QCoreApplication.translate("MqttReasonCodeNames", "Re-authenticate"): [
53 "MqttReasonCodeNames", "Re-authenticate" 65 PacketTypes.AUTH
54 ): [PacketTypes.AUTH]}, 66 ]
67 },
55 128: { 68 128: {
56 QCoreApplication.translate( 69 QCoreApplication.translate("MqttReasonCodeNames", "Unspecified error"): [
57 "MqttReasonCodeNames", "Unspecified error" 70 PacketTypes.CONNACK,
58 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, 71 PacketTypes.PUBACK,
59 PacketTypes.PUBREC, PacketTypes.SUBACK, 72 PacketTypes.PUBREC,
60 PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]}, 73 PacketTypes.SUBACK,
74 PacketTypes.UNSUBACK,
75 PacketTypes.DISCONNECT,
76 ]
77 },
61 129: { 78 129: {
62 QCoreApplication.translate( 79 QCoreApplication.translate("MqttReasonCodeNames", "Malformed packet"): [
63 "MqttReasonCodeNames", "Malformed packet" 80 PacketTypes.CONNACK,
64 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 81 PacketTypes.DISCONNECT,
82 ]
83 },
65 130: { 84 130: {
66 QCoreApplication.translate( 85 QCoreApplication.translate("MqttReasonCodeNames", "Protocol error"): [
67 "MqttReasonCodeNames", "Protocol error" 86 PacketTypes.CONNACK,
68 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 87 PacketTypes.DISCONNECT,
88 ]
89 },
69 131: { 90 131: {
70 QCoreApplication.translate( 91 QCoreApplication.translate(
71 "MqttReasonCodeNames", "Implementation specific error" 92 "MqttReasonCodeNames", "Implementation specific error"
72 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, 93 ): [
73 PacketTypes.PUBREC, PacketTypes.SUBACK, 94 PacketTypes.CONNACK,
74 PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]}, 95 PacketTypes.PUBACK,
96 PacketTypes.PUBREC,
97 PacketTypes.SUBACK,
98 PacketTypes.UNSUBACK,
99 PacketTypes.DISCONNECT,
100 ]
101 },
75 132: { 102 132: {
76 QCoreApplication.translate( 103 QCoreApplication.translate(
77 "MqttReasonCodeNames", "Unsupported protocol version" 104 "MqttReasonCodeNames", "Unsupported protocol version"
78 ): [PacketTypes.CONNACK]}, 105 ): [PacketTypes.CONNACK]
106 },
79 133: { 107 133: {
80 QCoreApplication.translate( 108 QCoreApplication.translate(
81 "MqttReasonCodeNames", "Client identifier not valid" 109 "MqttReasonCodeNames", "Client identifier not valid"
82 ): [PacketTypes.CONNACK]}, 110 ): [PacketTypes.CONNACK]
111 },
83 134: { 112 134: {
84 QCoreApplication.translate( 113 QCoreApplication.translate(
85 "MqttReasonCodeNames", "Bad user name or password" 114 "MqttReasonCodeNames", "Bad user name or password"
86 ): [PacketTypes.CONNACK]}, 115 ): [PacketTypes.CONNACK]
116 },
87 135: { 117 135: {
88 QCoreApplication.translate( 118 QCoreApplication.translate("MqttReasonCodeNames", "Not authorized"): [
89 "MqttReasonCodeNames", "Not authorized" 119 PacketTypes.CONNACK,
90 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, 120 PacketTypes.PUBACK,
91 PacketTypes.PUBREC, PacketTypes.SUBACK, 121 PacketTypes.PUBREC,
92 PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]}, 122 PacketTypes.SUBACK,
123 PacketTypes.UNSUBACK,
124 PacketTypes.DISCONNECT,
125 ]
126 },
93 136: { 127 136: {
94 QCoreApplication.translate( 128 QCoreApplication.translate("MqttReasonCodeNames", "Server unavailable"): [
95 "MqttReasonCodeNames", "Server unavailable" 129 PacketTypes.CONNACK
96 ): [PacketTypes.CONNACK]}, 130 ]
131 },
97 137: { 132 137: {
98 QCoreApplication.translate( 133 QCoreApplication.translate("MqttReasonCodeNames", "Server busy"): [
99 "MqttReasonCodeNames", "Server busy" 134 PacketTypes.CONNACK,
100 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 135 PacketTypes.DISCONNECT,
136 ]
137 },
101 138: { 138 138: {
102 QCoreApplication.translate( 139 QCoreApplication.translate("MqttReasonCodeNames", "Banned"): [
103 "MqttReasonCodeNames", "Banned" 140 PacketTypes.CONNACK
104 ): [PacketTypes.CONNACK]}, 141 ]
142 },
105 139: { 143 139: {
106 QCoreApplication.translate( 144 QCoreApplication.translate("MqttReasonCodeNames", "Server shutting down"): [
107 "MqttReasonCodeNames", "Server shutting down" 145 PacketTypes.DISCONNECT
108 ): [PacketTypes.DISCONNECT]}, 146 ]
147 },
109 140: { 148 140: {
110 QCoreApplication.translate( 149 QCoreApplication.translate(
111 "MqttReasonCodeNames", "Bad authentication method" 150 "MqttReasonCodeNames", "Bad authentication method"
112 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 151 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]
152 },
113 141: { 153 141: {
114 QCoreApplication.translate( 154 QCoreApplication.translate("MqttReasonCodeNames", "Keep alive timeout"): [
115 "MqttReasonCodeNames", "Keep alive timeout" 155 PacketTypes.DISCONNECT
116 ): [PacketTypes.DISCONNECT]}, 156 ]
157 },
117 142: { 158 142: {
118 QCoreApplication.translate( 159 QCoreApplication.translate("MqttReasonCodeNames", "Session taken over"): [
119 "MqttReasonCodeNames", "Session taken over" 160 PacketTypes.DISCONNECT
120 ): [PacketTypes.DISCONNECT]}, 161 ]
162 },
121 143: { 163 143: {
122 QCoreApplication.translate( 164 QCoreApplication.translate("MqttReasonCodeNames", "Topic filter invalid"): [
123 "MqttReasonCodeNames", "Topic filter invalid" 165 PacketTypes.SUBACK,
124 ): [PacketTypes.SUBACK, PacketTypes.UNSUBACK, 166 PacketTypes.UNSUBACK,
125 PacketTypes.DISCONNECT]}, 167 PacketTypes.DISCONNECT,
168 ]
169 },
126 144: { 170 144: {
127 QCoreApplication.translate( 171 QCoreApplication.translate("MqttReasonCodeNames", "Topic name invalid"): [
128 "MqttReasonCodeNames", "Topic name invalid" 172 PacketTypes.CONNACK,
129 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, 173 PacketTypes.PUBACK,
130 PacketTypes.PUBREC, PacketTypes.DISCONNECT]}, 174 PacketTypes.PUBREC,
175 PacketTypes.DISCONNECT,
176 ]
177 },
131 145: { 178 145: {
132 QCoreApplication.translate( 179 QCoreApplication.translate("MqttReasonCodeNames", "Packet identifier in use"): [
133 "MqttReasonCodeNames", "Packet identifier in use" 180 PacketTypes.PUBACK,
134 ): [PacketTypes.PUBACK, PacketTypes.PUBREC, 181 PacketTypes.PUBREC,
135 PacketTypes.SUBACK, PacketTypes.UNSUBACK]}, 182 PacketTypes.SUBACK,
183 PacketTypes.UNSUBACK,
184 ]
185 },
136 146: { 186 146: {
137 QCoreApplication.translate( 187 QCoreApplication.translate(
138 "MqttReasonCodeNames", "Packet identifier not found" 188 "MqttReasonCodeNames", "Packet identifier not found"
139 ): [PacketTypes.PUBREL, PacketTypes.PUBCOMP]}, 189 ): [PacketTypes.PUBREL, PacketTypes.PUBCOMP]
190 },
140 147: { 191 147: {
141 QCoreApplication.translate( 192 QCoreApplication.translate("MqttReasonCodeNames", "Receive maximum exceeded"): [
142 "MqttReasonCodeNames", "Receive maximum exceeded" 193 PacketTypes.DISCONNECT
143 ): [PacketTypes.DISCONNECT]}, 194 ]
195 },
144 148: { 196 148: {
145 QCoreApplication.translate( 197 QCoreApplication.translate("MqttReasonCodeNames", "Topic alias invalid"): [
146 "MqttReasonCodeNames", "Topic alias invalid" 198 PacketTypes.DISCONNECT
147 ): [PacketTypes.DISCONNECT]}, 199 ]
200 },
148 149: { 201 149: {
149 QCoreApplication.translate( 202 QCoreApplication.translate("MqttReasonCodeNames", "Packet too large"): [
150 "MqttReasonCodeNames", "Packet too large" 203 PacketTypes.CONNACK,
151 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 204 PacketTypes.DISCONNECT,
205 ]
206 },
152 150: { 207 150: {
153 QCoreApplication.translate( 208 QCoreApplication.translate("MqttReasonCodeNames", "Message rate too high"): [
154 "MqttReasonCodeNames", "Message rate too high" 209 PacketTypes.DISCONNECT
155 ): [PacketTypes.DISCONNECT]}, 210 ]
211 },
156 151: { 212 151: {
157 QCoreApplication.translate( 213 QCoreApplication.translate("MqttReasonCodeNames", "Quota exceeded"): [
158 "MqttReasonCodeNames", "Quota exceeded" 214 PacketTypes.CONNACK,
159 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, 215 PacketTypes.PUBACK,
160 PacketTypes.PUBREC, PacketTypes.SUBACK, 216 PacketTypes.PUBREC,
161 PacketTypes.DISCONNECT], }, 217 PacketTypes.SUBACK,
218 PacketTypes.DISCONNECT,
219 ],
220 },
162 152: { 221 152: {
163 QCoreApplication.translate( 222 QCoreApplication.translate("MqttReasonCodeNames", "Administrative action"): [
164 "MqttReasonCodeNames", "Administrative action" 223 PacketTypes.DISCONNECT
165 ): [PacketTypes.DISCONNECT]}, 224 ]
225 },
166 153: { 226 153: {
167 QCoreApplication.translate( 227 QCoreApplication.translate("MqttReasonCodeNames", "Payload format invalid"): [
168 "MqttReasonCodeNames", "Payload format invalid" 228 PacketTypes.PUBACK,
169 ): [PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.DISCONNECT]}, 229 PacketTypes.PUBREC,
230 PacketTypes.DISCONNECT,
231 ]
232 },
170 154: { 233 154: {
171 QCoreApplication.translate( 234 QCoreApplication.translate("MqttReasonCodeNames", "Retain not supported"): [
172 "MqttReasonCodeNames", "Retain not supported" 235 PacketTypes.CONNACK,
173 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 236 PacketTypes.DISCONNECT,
237 ]
238 },
174 155: { 239 155: {
175 QCoreApplication.translate( 240 QCoreApplication.translate("MqttReasonCodeNames", "QoS not supported"): [
176 "MqttReasonCodeNames", "QoS not supported" 241 PacketTypes.CONNACK,
177 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 242 PacketTypes.DISCONNECT,
243 ]
244 },
178 156: { 245 156: {
179 QCoreApplication.translate( 246 QCoreApplication.translate("MqttReasonCodeNames", "Use another server"): [
180 "MqttReasonCodeNames", "Use another server" 247 PacketTypes.CONNACK,
181 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 248 PacketTypes.DISCONNECT,
249 ]
250 },
182 157: { 251 157: {
183 QCoreApplication.translate( 252 QCoreApplication.translate("MqttReasonCodeNames", "Server moved"): [
184 "MqttReasonCodeNames", "Server moved" 253 PacketTypes.CONNACK,
185 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 254 PacketTypes.DISCONNECT,
255 ]
256 },
186 158: { 257 158: {
187 QCoreApplication.translate( 258 QCoreApplication.translate(
188 "MqttReasonCodeNames", "Shared subscription not supported" 259 "MqttReasonCodeNames", "Shared subscription not supported"
189 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]}, 260 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]
261 },
190 159: { 262 159: {
191 QCoreApplication.translate( 263 QCoreApplication.translate("MqttReasonCodeNames", "Connection rate exceeded"): [
192 "MqttReasonCodeNames", "Connection rate exceeded" 264 PacketTypes.CONNACK,
193 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]}, 265 PacketTypes.DISCONNECT,
266 ]
267 },
194 160: { 268 160: {
195 QCoreApplication.translate( 269 QCoreApplication.translate("MqttReasonCodeNames", "Maximum connect time"): [
196 "MqttReasonCodeNames", "Maximum connect time" 270 PacketTypes.DISCONNECT
197 ): [PacketTypes.DISCONNECT]}, 271 ]
272 },
198 161: { 273 161: {
199 QCoreApplication.translate( 274 QCoreApplication.translate(
200 "MqttReasonCodeNames", "Subscription identifiers not supported" 275 "MqttReasonCodeNames", "Subscription identifiers not supported"
201 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]}, 276 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]
277 },
202 162: { 278 162: {
203 QCoreApplication.translate( 279 QCoreApplication.translate(
204 "MqttReasonCodeNames", "Wildcard subscription not supported" 280 "MqttReasonCodeNames", "Wildcard subscription not supported"
205 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]}, 281 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]
282 },
206 } 283 }
207 284
208 285
209 def mqttReasonCode(rc, packetType): 286 def mqttReasonCode(rc, packetType):
210 """ 287 """
211 Function to get the readable reason code string given the result code and 288 Function to get the readable reason code string given the result code and
212 the packet type. 289 the packet type.
213 290
214 @param rc result code 291 @param rc result code
215 @type int 292 @type int
216 @param packetType packet type 293 @param packetType packet type
217 @type PacketTypes (= int) 294 @type PacketTypes (= int)
218 @return message associated with the reason code and packet type 295 @return message associated with the reason code and packet type
219 @rtype str 296 @rtype str
220 """ 297 """
221 if rc not in MqttReasonCodeNames: 298 if rc not in MqttReasonCodeNames:
222 return QCoreApplication.translate( 299 return QCoreApplication.translate(
223 "MqttReasonCodeNames", "Unknown result code ({0})").format(rc) 300 "MqttReasonCodeNames", "Unknown result code ({0})"
224 301 ).format(rc)
302
225 messages = MqttReasonCodeNames[rc] 303 messages = MqttReasonCodeNames[rc]
226 messagesList = [message for message in messages.keys() 304 messagesList = [
227 if packetType in messages[message]] 305 message for message in messages.keys() if packetType in messages[message]
306 ]
228 if len(messagesList) == 0: 307 if len(messagesList) == 0:
229 return QCoreApplication.translate( 308 return QCoreApplication.translate(
230 "MqttReasonCodeNames", 309 "MqttReasonCodeNames", "Unknown result code ({0}) for packet type '{1}'"
231 "Unknown result code ({0}) for packet type '{1}'"
232 ).format(rc, packetType) 310 ).format(rc, packetType)
233 311
234 return messagesList[0] 312 return messagesList[0]

eric ide

mercurial