Go Down

Topic: Send key stroke from ESP8266 to PC/Android via WIFI (Read 222 times) previous topic - next topic

kail85

As Arduino or ESP8266 can emulate USB keyboard, I'm wondering if there's a way to send key stroke to PC/Android via WIFI? So that I can build wifi based remote to control PC/Android.

pert

You'll need a program running on the PC/Android that receives the WiFi communication and then emulates the desired keystroke.

There's a nice free open source program for Windows that makes this sort of thing easy:
http://www.eventghost.net/
but there are many other options.

kail85

You'll need a program running on the PC/Android that receives the WiFi communication and then emulates the desired keystroke.
Thank you for the suggestion. Looks like EventGhost maps an event to a macro. But I'm not clear how to create an event triggered by a command sent via wifi?

Also is there similar app available on android? Thanks!



pert

EventGhost comes with the Broadcaster plugin for network communication via the UDP protocol, which you can use easily with Arduino. That's probably going to be the best option for your desired application but there are other 3rd party plugins available for other protocols such as MQTT.

You can really do a lot with EventGhost. It might be a little more than is necessary for a simple project but that really depends on what you want to control with the remote. The visual programming interface makes it very easy to get started but it runs on Python so you can always write some code when you need to do something more complex.

I have used a couple EventGhost Android apps. I haven't used them with UDP because I use an authenticated TCP communications protocol for my network communications (the one used by EventGhost's Network Event Receiver/Sender and TCPEvents plugins). I wrote an Arduino library for this protocol but it currently is limited to use with the Ethernet library. I am working towards making it work with any network interface but haven't had enough time to finish that project up yet. The apps I have used are:
https://play.google.com/store/apps/details?id=com.timhoeck.android.eventghost
http://play.google.com/store/apps/details?id=eu.rml.lab.egremote_lite
but I think they are restricted to the Network Event Receiver/Sender communication protocol.

I'm sure there are other apps that will be better suited to your needs. I just don't use Android hardly at all so I can't name one.

CCotton

You'll need a program running on the PC/Android that receives the WiFi communication and then emulates the desired keystroke.

There's a nice free open source program for Windows that makes this sort of thing easy:
http://www.eventghost.net/
but there are many other options.
Can EventGhost be used in the reverse application?  I need to be able to send a command via wifi to an Arduino for it to trigger a relay.  The "trigger" command could be sent to the Arduino by an Android or iPhone.

Thanks,
Chas.

pert

Yes, you can communicate both ways. There are many ways to generate events to trigger a macro to run. I use the OS Menu plugin as a GUI primarily and the "Desktop Remote" plugin as well. You can also generate events from the command line interface, and the various plugins. I am using the Keyboard plugin for keyboard shortcuts, Task Monitor and Process Watcher plugins for automatically generated events caused by other applications on the computer, SchedulGhost plugin for scheduled events ...

kail85

I'm trying to get a clear figure of what I gonna do, however, I get stuck again of how I can send data to PC via wifi?

The ESP8266 tutorial has an example of using UDP to receive data. But seems likeI cannot find related example of sending data from ESP8266. Also, someone said UDP is not encouraged in windows, so is it possible to use TCP/IP communication?

I would be greatly appreciated for an example if possible.


pert

is it possible to use TCP/IP communication?
The Network Event Sender/Receiver plugins use TCP/IP but they also have a specialized authentication protocol, which I've detailed here:
https://github.com/per1234/TCPEvents#authentication-process

The MD5 algorithm uses up a lot of resources on an AVR-based Arduino board but the ESP8266 is much more capable. The ESP8266 core for Arduino even comes with an MD5 library, MD5Builder.h.

If you don't need authentication you can use my version of the TCPEvents plugin:
https://github.com/per1234/TCPEvents
and leave the password field blank, which will remove the need for the use of the MD5 algorithm.

All the code you need receive using this protocol is available here:
https://github.com/per1234/EtherEvent/blob/master/EtherEvent.h#L57
The code for sending via this protocol here:
https://github.com/per1234/EtherEvent/blob/master/EtherEvent.h#L278

I've added support for the ESP8266 in this branch of the library:
https://github.com/per1234/EtherEvent/tree/development
but it's untested on ESP8266 and I don't remember exactly what state it's currently in. It's only online to run the Travis CI tests on it. Note that's still written for use with the Ethernet library, so it's expecting that you have a W5x00 Ethernet controller connected to your ESP8266, rather than actually using WiFi. However, the protocol handling code will be the same either way. It really won't take a lot of work to adapt it to any standard network interface. The main cause of the delay is doing so will require that the user interface be changed since they will need to add a little more code to the sketch, which is currently hidden away in the library. Since this will cause a major version bump and also makes the library a little less user friendly I want to put out a polished 1.0.0 release for people who only need the Ethernet functionality before moving forward with the breaking changes and the 2.0.0 release.

You might be able to find an EventGhost plugin that doesn't have any of the authentication code; I'm just not familiar with one. As I said, EventGhost is all Python under the hood so you can always write your own code using the "Python Script" action or even package it up in a plugin if you want.

The nice thing about TCP is it has a whole system of ensuring the packets get where they're going via ACKs. Of course that comes with some overhead. UDP is "fire and forget". There is nothing in the protocol to ensure the message actually made it where you sent it. Of course you can always add in your own ACK system on top of it if you like. I haven't ever heard anything about UDP not being encouraged in Windows but maybe the fire and forget nature is what they were talking about.

Go Up