haach
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!

H

jim2007
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.

Heater
Posts: 9726
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.

User avatar
Gavinmc42
Posts: 2099
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

stockton
Posts: 91
Joined: Mon Aug 24, 2015 6:06 am

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
DougieLawson
Posts: 33637
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Beavis
Posts: 3
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:


RUN THIS JUST ONCE AT THE TOP

---> 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 ))


THEN WHENEVER YOU WANT TO SEND DATA

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


AND TO GET DATA FROM THE INCOMING BUFFER

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 ]

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 6 guests