I have an arduino with an ethernet shield that is controlling a relay, which control the lights. I usually just use the phone to send a http get request from a widget in tasker, but I would like to be able to just type "light on" or "light_on" in the command line/terminal, and it would turn it on. I found that I could use wget to send the request wget, but that is listening for an output afterwards. But the arduino doesn't output anything, it just listens for the get.

So in conclusion, I need to be able to make a custom command, and need a command to customize, to send an http GET request. Don't have to use wget, just seemed easiest since it was already installed.

Oh, and my OS is Ubuntu 12. 04 LTS.

  • What do you mean by "listening for output"? What happens when you run wget Does the light turn on? – terdon Feb 28 '14 at 17:17
  • Yes, the lights do turn on. But in the terminal i have to ctrl+c in order to execute another command after. I belive that wget is waiting for the arduino to output some html. Googled, nothing i tried worked. I want it to send the get request and then stop. – Robin Sandström Mar 1 '14 at 0:35

You can use netcat for that task; for example, using Nmap's ncat incarnation:

$ echo -e "GET /?s=1 HTTP/1.0\r\nHost:\r\n\r\n" | ncat

That is, assuming your Arduino is listening on port 80; otherwise you'll need to specify that after the IP address in ncat's invocation

Afterwards, if that works fine for you, you can make an alias with that entire command, such as appending this to your ~/.bashrc, ~/.bash_aliases or whatever you find convenient:

alias light_on='echo -e "GET /?s=1 HTTP/1.0\r\nHost:\r\n\r\n" | ncat'

  • i installed nmap, but the request just times out. echo -e "GET /?s=1 HTTP/1.0\nHost:\r\n\r\n" | ncat and echo -e "GET /?s=1 HTTP/1.0\nHost:\r\n\r\n" | ncat my ip = arduino ip = – Robin Sandström Mar 1 '14 at 0:40
  • You're missing one \r character in your command, right after HTTP/1.0, check that out. – asamarin Mar 1 '14 at 15:57
  • still doesn't work echo -e "GET /?s=0 HTTP/1.0\r\nHost:\r\n\r\n" | ncat – Robin Sandström Mar 2 '14 at 21:56
  • Why did you change the parameter s=1 to s=0? I don't know if that's relevant for your listening program, but it seems so. – asamarin Mar 3 '14 at 5:08
  • s=1 turns the lamp on, and s=0 turns it off. i tried both, i guess i copied the 2nd line. s = state, 0 = off, 1 = on. – Robin Sandström Mar 3 '14 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.