Example GetService(2)

Hi there, I’m currently developing mobile application using kotlin android studio. I’m still new with how can receive device information locally. Is there anyone that can kindly help me to understand more?

Hello Adam and welcome. I am not familiar with android studio so I can’t help there but understanding the LAN protocol was a struggle for me in the beginning. I program in Python3 to communicate with my devices on a linux computer. What I can tell you is I had to read the section on how to construct a packet bit by bit and I had to go back and re-read it over and over before I grasped how to put it all together and make my first packet. Basically, you open a socket and broadcast a UDP packet onto the subnet with the devices. You’ll also have to listen back for messages from the devices (port 56700).
an example packet would be size=2400, protocol=0034, source=02000000, target=0000000000000000, reserved_1=000000000000, reserved_2=00, Sequence=00, reserved_3=0000000000000000, message_type=0200, reserved_4=0000. Now concatenate all of those hex numbers together, convert to bytes and broadcast that packet out onto the network for a basic GetService(2) request.
I’m no expert by any means but maybe this will help you get started. Also, wireshark can help you view packets.

1 Like

Hi Rasstace, thank you for the respond. It’s quite helpful with the example that you given, it does help me to more little bit more how the messages can be set. Btw, what’s Wireshark? sorry I’m quite newbie with UDP method.

Hi Adam

Wireshark is a network packet inspector. It allows you to inspect every single packet, UDP/TCP crossing your network. It is especially useful for watching how certain protocols communicate with others, and seeing the packets you send out from your local box.

In Kotlin, you will want to pull in the DatagramSocket classes from Java and make an abstraction layer above them where you will write your communication protocol. First you will need to do device discovery and retrieve the network addresses for your various light devices. I save these locally in memory, and then loop through them to send out desired packets (on/off, change hue, etc).

1 Like