0

This is sort of a basic question, there's just one piece of the puzzle that I'm missing somewhere. I'm trying to write a batch script to change my smart home light bulbs to a specific color using netcat and UDP commands. If I open command prompt, type this:

ncat -u 192.168.1.3 38899

A connection is established successfully to my smart light bulb, and then I can type this:

{"id":1,"method":"setPilot","params":{"r":0,"g":0,"b":255,"dimming":100}}

Which sends the UDP message to the bulb, and successfully changes it to blue. The problem is I can't seem to get this process down to one line of code for use in a batch script, for example if I send this in a command line window:

ncat -u 192.168.1.3 38899 {"id":1,"method":"setPilot","params":{"r":0,"g":0,"b":255,"dimming":100}}

I get an error that I'm trying to specify more than one port. If called from a batch script, the connection will establish, then pause, and I can then send the UDP command by typing it into the open cmd window, but that defeats the purpose. I'm sure this is a simple solution that I'm just not aware of, would someone be able to help me out? Thanks.

1 Answer 1

2

I found a solution! If I type

echo {"id":1,"method":"setPilot","params":{"r":0,"g":0,"b":255,"dimming":100}} | ncat -u -w 1 192.168.1.95 38899

It works! Basically, echoing my command, without quotes, then a pipe | then my ncat connection. Hope this helps anyone else trying to do the same thing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.