jeelabs / esp-link

esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer
Other
2.82k stars 720 forks source link

How to send and receive data from a projector? #468

Open jschwalbe opened 4 years ago

jschwalbe commented 4 years ago

Hello. I'm excited about esp-link, but I'm not sure if it's what I need. Looking for some help!

I have a projector which communicates via RS232. I have a level shifter in place, attached to my ESP8266. I've loaded the esp-link firmware onto the ESP and lo and behold, from the console I can type a few commands to turn the projector on or off, and to query status of the projector.

I want this to be automatic. I've been searching the documentation (and other websites) and it seems possible, but I just cannot tell /how/. Any help?

Many thanks!

lbussy commented 4 years ago

To do this you'd either need to write an application/script to send the strings to the esp-link, or modify the esp-link source code and recompile. What you choose is dependant upon your capabilities and resources where this is being used.

Unfortunately, there's no easy answer - you'd likely be writing this yourself no matter which way you go.

jschwalbe commented 4 years ago

I'm fine writing a script of some sort, but I don't understand how to programatically interact with esp-link.

For example, how do I simply tell it to send "projector on?" thru the UART (and perhaps query it for the resulting answer).

Even if there was a way to use netcat, I could make that work, but that doesn't seem to function as expected.

uzi18 commented 4 years ago

Do you know what is protocol of communication with projector? If no you need to find it and test with direct connection. Next step could be find idea how to control it by wifi, we have here lots's of solutions, no need to recompile anything.

lbussy commented 4 years ago

pyserial comes to mind as the basis of a solution for this.

jschwalbe commented 4 years ago

Hi, I am able to send commands to the projector from the esp-link webpage. It works great. I just have to send it something like "* 001 LAMP" and it will turn on the lamp.

What I don't understand, and what I want to do is, how can I make this happen without going thru the console on the webpage? Thanks for all the suggestions otherwise.

yesyesuk commented 4 years ago

That's a good start. How do you want to do it? So far you have only explained how you don't want to do it. ;-) Do you want to click a button on the esp-link webpage? Do you want to do it from some home automation software?

jschwalbe commented 4 years ago

Thanks - Well.. honestly I am just trying to know what is the preferred way to interface with esp-link besides using the webpage. I am ultimately hoping to use HomeAssistant to monitor when it's on and to turn lights on/off depending on the projector state. So it needs to be automated; i.e. not from the esp-link webpage. (I will have HA query esp-link every 30 seconds or so - I don't require esp-link to "push" info, just respond to pulls.)

But so far, I've not been able to find any way to interface with esp-link that doesn't involve either the console webpage or telnet (neither of which are inherently scriptable).

Thanks!

lbussy commented 4 years ago

Have a look at pyserial - it allows you to script that "telnet-ish" interface (in python of course).

jschwalbe commented 4 years ago

er.. but.. pyserial won't run on an ESP. will it?

I need esp-link because I can't plug the projector into my computer, right now I have it wired up to an ESP8266. esp-link is acting as a wifi-bridge allowing me to send serial commands. I'm not sure I follow how pyserial would accomplish this feat running on my computer.

lbussy commented 4 years ago

You would need a place to run the script - yes. If you want something to work on the ESP you would need to dive into the C++ code.

yesyesuk commented 4 years ago

You will need some application running somewhere that connects to the ESP via TCP (port 23) and then sends the text commands in TCP packets. Esp-link will then forward these text commands to the serial port where your projector is connected. Anything the projector sends on the serial port will be forwarded to the same TCP connection.

jschwalbe commented 4 years ago

@lbussy i have plenty of servers that can run code, but i don't understand how esp-link interfaces with the outside world besides using the webpage

@yesyesuk ok now we're getting somewhere. thanks!

telnet (port 23) is the only way to communicate with esp-link besides the website? I can't use MQTT to send/receive commands?

yesyesuk commented 4 years ago

It also supports MQTT but I have never used that. I only use it as a WiFi/TCP to serial bridge. So I can't comment on that.

uzi18 commented 4 years ago

@jschwalbe so now it should be stright forward, if you can send commands with console subpage. no you can try actions like : http://esp-link-ip/console/send?text=xxx where xxx is your urlencoded command

for "* 001 LAMP" it will be: http://esp-link-ip/console/send?text=%2A%20001%20LAMP%0D%0A

remember to change esp-link-ip to your esp-link IP address

next if it work like you need, you can create html file (with buttons actions you need) and upload it to esp-link as userpage

jschwalbe commented 4 years ago

@uzi18 awesome. that's the secret sauce i was looking for. thanks so much :)

uzi18 commented 4 years ago

as you can see it looks like easy, so no additional software needed, waiting for your progress report ;)

Banjak88 commented 4 years ago

@uzi18 awesome. that's the secret sauce i was looking for. thanks so much :)

Does it works for you?

uzi18 commented 4 years ago

@Banjak88 it should, why not?

Banjak88 commented 4 years ago

May be I had messed something, as I test it with terminal and I got nothing. Any advice or procedure would be greatly helpful. Thanks

uzi18 commented 4 years ago

please explain with more details what is your problem exactly?

Banjak88 commented 4 years ago

Hello again, It works finallay (I had to connect tx to rx pin in esp hardware to test it with terminal) But when making webpage with href link, when click it, the commend sent, but it redirect me to empty page...! Any suggestions

uzi18 commented 4 years ago

please attach html source you want to use

Banjak88 commented 4 years ago

Here is #html: h1>The button formmethod attribute form action="/console/send" method="get" target="_blank"> input type="text" name="text" ="Hello123"> button>Send /form> /body> /html> Sorry i had to remove "<" from the beganning of lines to get real preview

uzi18 commented 4 years ago

use code markers 3times: ' as opening and same for close, you got it also above input box for post

i think you need to use JavaScript as action on button