[SOLVED!] TCP commands not working - not getting response

OK - I solved the issue…

It’s not Yeelight’s bulb fault and NEVER WAS - its simply how shell/bash and other basic apps ( from busybox ) works.
also, YES - using telnet directly ( w/o calling it from any shell script ) it works w/o any issue ( like in your photoes ).

when using:
echo -ne ‘{“id”:0,“method”:“toggle”,“params”:[]}\r\n’ | nc -w1 <bulb_IP> 55443
I found an explanation for that behavior:

“This is exactly how netcat is supposed to operate: once it has reached EOF on stdin, it (one-way) closes the connection /to/ the server and then waits for data coming from the server. When the latter closes the connection (the other way: server->client), then netcat stops”
Source

That source also recommend to use “cat<(echo command) | nc ip port” which I tested and indeed output response from the bulb - but you need to manually do CTRL+C to “finish” the command.
( that’s not so good for scripts / tasker )

As also stated as well in that source, there’s another option: adding a “-q1” instead that “cat<()”,and it solves that issue of mandatory manually CTRL+C - BUT, it will output the response as we wish - BUT WITH MIN OF 1 SECOND DELAY !
so that’s NOT perfect as well…

SO - very simply I found out that adding a small SLEEP AFTER the echo command - solves it.
it is best to keep that sleep/delay as low as possible (~1/4sec) but it could vary ( network/bulb connection is busy?)
anywho… the shell command for linux, that work out-of-the-box for android as well is:

( echo -ne ‘{“id”:0,“method”:“toggle”,“params”:[]}\r\n’; sleep 0.1 ) | nc -w1 IP 55443

  • please note the () encapsulation and added sleep after the echo.
  • if you get no response when issuing a command, raise the sleep delay (0.25/0.3/0.4/0.5 etc…)
  • IP is of course an IP address.
  • the sent command can be changed according to Yeelight Spec manual

NOW - anyone can enjoy scripting on any device :slight_smile:
thanks for all the help.

P.S - proof of concept:

1 个赞