Sending and receiving udp packets??

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WuffTheCoder
Posts: 35
Joined: 23 Aug 2017, 13:35

Sending and receiving udp packets??

Post by WuffTheCoder » 23 Sep 2019, 11:26

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/

ochetski
Posts: 1
Joined: 12 Jun 2021, 13:10
Contact:

Re: Sending and receiving udp packets??

Post by ochetski » 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?

takayo97
Posts: 63
Joined: 09 Jun 2018, 16:30

Re: Sending and receiving udp packets??

Post by takayo97 » 24 Nov 2023, 20:57

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 ?

Post Reply

Return to “Ask for Help (v1)”