Posts: 1
Joined: Tue Jan 09, 2018 1:01 am

triggering program on another machine

Tue Jan 09, 2018 1:09 am

Hi all,
newbie here...
I am trying to use a camera connected to my raspberry pi to detect certain events (this part i have already written and it works). But what i want to happen next is for the raspberry pi to call a program on another PC which is running windows. I was thinking of using a usb and writing an interrupt service routine etc. The code has to work real-time.
I have not done any low level system programming since i took an OS course in my undergrad a brazillion years ago, so if there are any suggestions please let me know.

In case i was not clear:
Program (1) runs on rp3 and it waits to detect some event X
program (2) runs on another pc running windows and gets triggered by the rp3 somehow, when the even X is observed
My question is regarding how to connect program (1) to program (2), i.e., how does (1) inform (2) in a real-time manner (dont want to go in the route of using server client mechanism via HTTP/Apache or other IP based approaches, the response has to be immediate)

Thank you so much!


Posts: 9
Joined: Tue Jan 17, 2017 1:46 am
Location: Switzerland
Contact: Website

Re: triggering program on another machine

Fri Jan 12, 2018 10:33 pm

Serial communication over USB ports.

Posts: 16545
Joined: Tue Jul 17, 2012 3:02 pm

Re: triggering program on another machine

Sat Jan 13, 2018 12:09 am

I think you will have to specify what you mean by "immediate".

Of course "immediate" is impossible. The speed of light, and hence speed of communications between machines, is only about 1 foot per nanosecond. The speed of electricity through wires somewhat less than that.

More importantly the limitation is the speed at which the operating system can schedule an output signal at the sending end and the speed of the OS to schedule a response at the receiving end. This can amount to multiple milliseconds.

I don't think you are going to get faster than what what can be done with an ethernet connection without considerable effort.
Memory in C++ is a leaky abstraction .

User avatar
Posts: 4661
Joined: Wed Aug 28, 2013 3:31 am

Re: triggering program on another machine

Sat Jan 13, 2018 1:07 am

I think Pikrellcam uses broadcast mode over the network.
By using a circular buffer you can get pre trigger events, but I don't think that is what you want.

If you use Linux then NC (netcat) works on Pi's, you don't need a full client/server app.
This could get as simple as a single line in shell script.

For faster response, some way to keep a socket open all the time?
Websockets etc

I have done simple modbus on TCP/IP.
Using lower levels like this and telnet means it is not as secure as higher HTTP etc which use SSH/SSL.
Not as secure generally means faster ;)
Latencies can be much lower than 100ms if you can figure out the Windows side of it, which may be the biggest issue.
Older version of Windows were less secure, ie easier to hack up things like this.

The simple ping test will give you an idea of possible speeds.
A version of ping that does something?
You don't even need 64 bytes but watch out for the "ping of death" ;)

Perhaps start with Netcat?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Posts: 138
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa
Contact: Website

Re: triggering program on another machine

Sun Jan 21, 2018 3:46 pm

I would look at socket programming in whatever language you prefer, C or python or php or for that matter bash. Never done bash on Windows but never the less socket programming is about as quick as you are going to get and either ethernet or wifi will do.

User avatar
Posts: 39841
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: triggering program on another machine

Sun Jan 21, 2018 8:09 pm

I would do it with an MQTT publisher on one machine and an MQTT subscriber on another.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Posts: 6
Joined: Sat Nov 11, 2017 8:40 am

Re: triggering program on another machine

Sat Sep 15, 2018 4:05 pm

So the OP will never see this, and this is a dead thread, BUT, since this is the first question I can answer:

the Sun Jan 21, 2018 7:46 am post suggests using sockets which I have done between RPi and Win PC using Python on both ends that pass UDP packets

Speed is fast (from my limited perspective), but what impressed me was how easy the coding was:


---> use these 2 lines on both client & host (server) <---
import socket
dgramSock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )

---> this line is only needed on the server (host - whatever!) <---
dgramSock.bind(('', port ))


dgramSock.sendto(variableContainingYourData, (address, port))


variableToPutDataInto, (address, port) = dgramSock.recvfrom(maximumNumberOfBytesYouWantToTakeOffTheBuffer)
---> (this time, address & port tell where the packet CAME FROM, not where it should go) <---

Having a server with a static IP made things super easy, and if the client sends the first packet then a dynamic IP is no problem since the client's IP is automatically sent with the packet

If both ends are on your local network (LAN) you should be good to go.
If using the Internet, all your typical security concerns apply (use at your own risk, although I never had an issue), and your routers need to use Port Forwarding on the port you specified

I'm sure it can get much more complicated that what I have here, but if you want simple, then this WILL work!
[if even 1 person reads this dead thread I'll be happy :+D ]

Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: triggering program on another machine

Fri Oct 05, 2018 3:34 pm

I haven't posted for a while.... and at the risk of starting a messaging war, I am still using zeromq
http://zeromq.org/ - while looking for alternatives to Python, (etc). I have been writing some code in go(lang) - tried Rust (it didn't suit me (or the other way round)) - I found golang fitted my experience.
However, I also found that it is a lot of work to move away from Python (on the Pi especially), so I wanted a way to get Go and Python working better together. Also, I believe, distributed is the future for many things....

So, using zeromq request/reply pattern, I have go calling python, python calling go, python where it works best, go for more speed. It is a bit mind boggling keeping track of which program runs where. but.... (I must draw a picture!)


This might give you some ideas

Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: triggering program on another machine

Thu Dec 06, 2018 10:29 pm

To update my previous post, I have continued working with Go. Currently using mangos v2 which is a fully go implementation of nanomsg (a later version similar to zeromq) as described in mangolink..
My stuff is on github :- https://github.com/richrarobi?tab=repositories

Particular things relevant to RasPi are mangolink, periblink, go_pca9865, pantilt....

periblink is for controlling Pimoroni Blinkt.
pantilt drives the Pimoroni pantilt hat.
mangolink is used to request/reply across a LAN
(mreqgui.go uses GTK3 to drive pantilt hat)

The driving of multiple pi's with different blinkt's or pantilt heads is easily possible.

Note that Go is supported quite adequately by Geany....
Install the latest go from here:

Posts: 1703
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: triggering program on another machine

Thu Dec 06, 2018 10:47 pm

perhaps test a few simple wifi/network methods before you rule them out? ;)

You could install and start a mqtt broker like mosquitto in 5-10 minutes after googeling the subject.https://www.instructables.com/id/Instal ... pberry-Pi/
and copy a couple of publish and subscribe scripts onto 2 machines and discover if its instantaneous enough within half an hour

http://www.steves-internet-guide.com/in ... on-client/

ok so it may take 1/2 to 1 hour with a coffee to read/absorb the above links too ;)
your probably looking at sub second responses tho so unless trying to snap pics of foxes running across your lawn on the remote pi it may work for you..

have fun..

Return to “General programming discussion”