Page 1 of 1

Sending and receiving udp packets??

Posted: 23 Sep 2019, 11:26
by WuffTheCoder
First of all is it even possible with ahk? and if it is heres my example of what it should look like

Code: Select all

port = 1982
ip = 192.168.1.109
data = (
M-SEARCH * HTTP/1.1`r
HOST: 239.255.255.250:1982`r
MAN: "ssdp:discover"`r
ST: wifi_bulb`r
)
udpSend(port=%port%, ip=%ip%, data=%data%)
any help is appreciated !
if you didnt get it by now im trying to control a yeelight via autohotkey...
one good source i found: https://autohotkey.com/board/topic/117030-simple-udp-client-upnp-discover/

Re: Sending and receiving udp packets??

Posted: 12 Jun 2021, 13:21
by ochetski
Sorry I took so long to reply. But I was not here at the time.

I would say it is possible. I managed to change light colors and modes already. But with forced IPs by MAC address (router config)

This example should turn lights on and off pressing "/" key on number pad if numLock is active and set it blue if inactive.

Code: Select all

#Include, lib/Socket.ahk

action_blue={"id":1,"method":"set_rgb","params":[255,"smooth",500]}`r`n
action_white={"id":1,"method":"set_ct_abx","params":[5000,"smooth",500]}`r`n
action_toggle={"id":1,"method":"toggle","params":[]}`r`n

lights := Array({"ip": "10.0.0.101"})

NumpadDiv::
	TCP := new SocketTCP()
	try {
		TCP.Connect([lights[1].ip, yeelightPort])
		if (GetKeyState("NumLock", "T")) {
			TCP.SendText(action_toggle)
		} else {
			TCP.SendText(action_blue)
		}
		;info := TCP.RecvText()
		TCP.Disconnect()
		;MsgBox, % info
	}
return
The Socket library is the one here: https://autohotkey.com/boards/viewtopic.php?t=35120 and I placed it inside a lib folder.

I did not code a discovery function yet. but I do plan to do so.

Better late than never, right?

Re: Sending and receiving udp packets??

Posted: 24 Nov 2023, 20:57
by takayo97
ochetski wrote:
12 Jun 2021, 13:21
Sorry I took so long to reply. But I was not here at the time.

I would say it is possible. I managed to change light colors and modes already. But with forced IPs by MAC address (router config)

This example should turn lights on and off pressing "/" key on number pad if numLock is active and set it blue if inactive.

Code: Select all

#Include, lib/Socket.ahk

action_blue={"id":1,"method":"set_rgb","params":[255,"smooth",500]}`r`n
action_white={"id":1,"method":"set_ct_abx","params":[5000,"smooth",500]}`r`n
action_toggle={"id":1,"method":"toggle","params":[]}`r`n

lights := Array({"ip": "10.0.0.101"})

NumpadDiv::
	TCP := new SocketTCP()
	try {
		TCP.Connect([lights[1].ip, yeelightPort])
		if (GetKeyState("NumLock", "T")) {
			TCP.SendText(action_toggle)
		} else {
			TCP.SendText(action_blue)
		}
		;info := TCP.RecvText()
		TCP.Disconnect()
		;MsgBox, % info
	}
return
The Socket library is the one here: https://autohotkey.com/boards/viewtopic.php?t=35120 and I placed it inside a lib folder.

I did not code a discovery function yet. but I do plan to do so.

Better late than never, right?

where is the value of yeelightPort came from ?