SNode.C
Loading...
Searching...
No Matches
Connect.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef IOT_MQTTFAST_PACKETS_CONNECT_H
21#define IOT_MQTTFAST_PACKETS_CONNECT_H
22
23#include "iot/mqtt-fast/ControlPacket.h"
24
25namespace iot::mqtt_fast {
27}
28
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30
31#include <cstdint>
32#include <string>
33
34#endif // DOXYGEN_SHOULD_SKIP_THIS
35
36#define MQTT_CONNECT 0x01
37
38#define MQTT_VERSION_3_1_1 0x04
39
40namespace iot::mqtt_fast::packets {
41
42 class Connect : public iot::mqtt_fast::ControlPacket {
43 public:
44 explicit Connect(const std::string& clientId,
45 const std::string& protocol = "MQTT",
46 uint8_t version = 4,
47 uint8_t flags = 0,
48 uint16_t keepAlive = 0x003C);
49 explicit Connect(iot::mqtt_fast::ControlPacketFactory& controlPacketFactory);
50
51 std::string getProtocol() const;
52 uint8_t getLevel() const;
53 uint8_t getFlags() const;
54 uint16_t getKeepAlive() const;
55
56 const std::string& getClientId() const;
57
58 bool getUsernameFlag() const;
59 bool getPasswordFlag() const;
60 bool getWillRetain() const;
61 uint8_t getWillQoS() const;
62 bool getWillFlag() const;
63 bool getCleanSession() const;
64
65 const std::string& getWillTopic() const;
66 const std::string& getWillMessage() const;
67 const std::string& getUsername() const;
68 const std::string& getPassword() const;
69
70 private:
71 std::string protocol;
72 uint8_t level = 0;
73 uint8_t flags = 0;
74 uint16_t keepAlive = 0;
75
76 std::string clientId;
77 std::string willTopic;
78 std::string willMessage;
79 std::string username;
80 std::string password;
81
82 bool usernameFlag = false;
83 bool passwordFlag = false;
84 bool willRetain = false;
85 uint8_t willQoS = 0;
86 bool willFlag = false;
87 bool cleanSession = false;
88 bool reserved = false;
89 };
90
91} // namespace iot::mqtt_fast::packets
92
93/*
94
95V5
96 VARIABLE HEADER
97 2022-09-19 17:37:53 0000000012: 1. - 0x00 Length MSB
98 2022-09-19 17:37:53 0000000012: 2. - 0x04 Length LSB
99 2022-09-19 17:37:53 0000000012: 3. M - 0x4d Protocol
100 2022-09-19 17:37:53 0000000012: 4. Q - 0x51
101 2022-09-19 17:37:53 0000000012: 5. T - 0x54
102 2022-09-19 17:37:53 0000000012: 6. T - 0x54
103
104 2022-09-19 17:37:53 0000000012: 7. - 0x05 Version
105 2022-09-19 17:37:53 0000000012: 8. - 0x02 Flags
106
107 2022-09-19 17:37:53 0000000012: 9. - 0x00 Keep Aliva MSB 0x003c = 60sec
108 2022-09-19 17:37:53 0000000012: 10. < - 0x3c Keep Alive LSB
109
110 2022-09-19 17:37:53 0000000012: 11. - 0x03 Properties Length
111
112 2022-09-19 17:37:53 0000000012: 12. ! - 0x21 Property: Receive Maximum (2Byte)
113 2022-09-19 17:37:53 0000000012: 13. - 0x00 Receive Maximum MSB
114 2022-09-19 17:37:53 0000000012: 14. - 0x14 Receive Maximum LSB
115
116 PAYLOAD
117 2022-09-19 17:37:53 0000000012: 15. - 0x00 ID Length MSB
118 2022-09-19 17:37:53 0000000012: 16. - 0x02 ID Length LSB
119 2022-09-19 17:37:53 0000000012: 17. d - 0x64 ID-Byte 1
120 2022-09-19 17:37:53 0000000012: 18. f - 0x66 ID-Byte 2
121
122 WILL Properties (optional)
123 WILL Topic (optional)
124 User Name
125 Password
126
127 */
128
129#endif // IOT_MQTTFAST_PACKETS_CONNECT_H
ControlPacket(iot::mqtt_fast::ControlPacketFactory &controlPacketFactory)
void putInt16(uint16_t value)
void putString(const std::string &value)
ControlPacket(uint8_t type, uint8_t reserved=0)
const std::string & getWillTopic() const
Definition Connect.cpp:126
Connect(const std::string &clientId, const std::string &protocol="MQTT", uint8_t version=4, uint8_t flags=0, uint16_t keepAlive=0x003C)
Definition Connect.cpp:28
uint16_t getKeepAlive() const
Definition Connect.cpp:94
std::string getProtocol() const
Definition Connect.cpp:82
const std::string & getUsername() const
Definition Connect.cpp:134
const std::string & getWillMessage() const
Definition Connect.cpp:130
const std::string & getClientId() const
Definition Connect.cpp:98
const std::string & getPassword() const
Definition Connect.cpp:138
Connect(iot::mqtt_fast::ControlPacketFactory &controlPacketFactory)
Definition Connect.cpp:45
#define MQTT_CONNECT
Definition Connect.h:36