Hello,i have some problem with bulb, what is wrong with this code and why it’s not work?
net.multicastJoin(wifi.sta.getip(), “239.255.255.250”)
local ssdp_search = “M-SEARCH * HTTP/1.1\r\n”…
“HOST: 239.255.255.250:1982\r\n”…
“MAN: “ssdp:discover”\r\n”…
“ST: wifi_bulb\r\n”
local function notify()
UPnP = net.createConnection(net.UDP)
--UPnP:connect(1982,"239.255.255.250")
UPnP:send(1982,"239.255.255.250",ssdp_search)
print("Searching")
UPnP:close()
UPnP = nil
notify = nil
collectgarbage()
end
tmr.alarm(3, 10000, 1, notify)
Screenshot from wireshark:
192.168.0.172 - my NodeMcu microcontroller, where this code is located
And this is your “Windows demo” from here
https://www.yeelight.com/en_US/developer
192.168.0.120 - my notebook
192.168.0.189 - Yeelight bulb
Thanks for help!
Hi,
Please try removing the trailing “\r\n”.
br,
I have the same problem, Do you have resolved this?
Most of the time my colour Yeelight bulb responds okay to SSDP requests. But every now and then it stops doing so. There doesn’t seem to be any pattern. I’ve tried sending requests every 5 seconds with a 2 second timeout for responses: the bulb will respond many times and then stop responding, starting again between one and 5 minutes later. I’ve been watching with tcpdump:
tcpdump -i wlan0 -s0 -vv udp -A
The code I am using is in Python from the Yeelight package by Stavros Korokithakis
import os
import socket
import struct
import json
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
def discover_bulbs(timeout=2, interface=False):
msg = "\r\n".join(["M-SEARCH * HTTP/1.1", "HOST: 239.255.255.250:1982", 'MAN: "ssdp:discover"', "ST: wifi_bulb"])
# Set up UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32)
if interface:
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF,
socket.inet_aton(get_ip_address(interface)))
s.settimeout(timeout)
s.sendto(msg.encode(), ("239.255.255.250", 1982))
bulbs = []
bulb_ips = set()
while True:
try:
data, addr = s.recvfrom(65507)
except socket.timeout:
print('Timeout')
break
capabilities = dict([x.strip("\r").split(": ") for x in data.decode().split("\n") if ":" in x])
parsed_url = urlparse(capabilities["Location"])
bulb_ip = (parsed_url.hostname, parsed_url.port)
if bulb_ip in bulb_ips:
continue
capabilities = {key: value for key, value in capabilities.items() if key.islower()}
bulbs.append({"ip": bulb_ip[0], "port": bulb_ip[1], "capabilities": capabilities})
bulb_ips.add(bulb_ip)
return bulbs
bulbs = discover_bulbs(timeout = 10)
print(str(bulbs))