Created
December 31, 2023 00:21
-
-
Save a10y/bf29832d8904f2d3a6da40c579312b21 to your computer and use it in GitHub Desktop.
MQTT connection for DDOT CCTV Cameras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"github.com/eclipse/paho.mqtt.golang/packets" | |
) | |
func main() { | |
connectPkt := bytes.NewBuffer([]byte{ | |
0x10, // CONNECT packet, null flags | |
0x34, // 52 bytes | |
0x00, 0x04, // 4 byte | |
0x4d, 0x51, 0x54, 0x54, | |
0x04, | |
0xc2, | |
0x00, 0x0a, | |
0x00, 0x11, | |
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2d, 0x72, 0x32, 0x33, 0x64, 0x6e, 0x33, 0x62, 0x35, 0x35, 0x75, | |
0x00, 0x05, | |
0x64, 0x63, 0x64, 0x6f, 0x74, | |
0x00, 0x0e, | |
0x63, 0x63, 0x74, 0x76, 0x64, 0x64, 0x6f, 0x74, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, | |
}) | |
ctrl, err := packets.ReadPacket(connectPkt) | |
if err != nil { | |
panic(fmt.Errorf("failed to parse connect packet: %v", err)) | |
} | |
connect := ctrl.(*packets.ConnectPacket) | |
if connect == nil { | |
panic("failed to parse packet as CONNECT packet") | |
} | |
fmt.Printf("Connection password: %v\n", string(connect.Password)) | |
fmt.Printf("connect: %v\n", ctrl.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment