Hello,
How can I use windows to talk to the raspberry pi with python?
I want to write a program that will send a simple command from
a windows computer to the Pi to execute a script on the pi
Thanks,
DM123
-
- Posts: 119
- Joined: Fri Dec 12, 2014 2:21 am
-
- Posts: 119
- Joined: Fri Dec 12, 2014 2:21 am
Re: Windows to Pi with python
UPDATE:
ive managed to make a connection using this code:
server.py
client.py
Now i just need to figure out how to send a command to execute a script
ive managed to make a connection using this code:
server.py
Code: Select all
import socket
s=socket.socket()
host=socket.gethostname()
port=12345
s.bind((host, port))
s.listen(5)
while True:
c, addr = s.accept()
print 'got connection from',addr
c.send('Thank you for connecting')
c.close()
Code: Select all
import socket
s = socket.socket()
host = '192.168.0.3'# ip of raspberry pi
port = 12345
s.connect((host, port))
print s.recv(1024)
s.close()
-
- Posts: 2247
- Joined: Thu Feb 05, 2015 11:25 pm
Re: Windows to Pi with python
Google for Python subprocess to see how to execute a script from within Python
Come back if you get stuck
Come back if you get stuck

-
- Posts: 119
- Joined: Fri Dec 12, 2014 2:21 am
Re: Windows to Pi with python
Thanks Matt for the reply.
I am somewhat familiar with subprocess
I added this line to the server script to run my bluetooth connection script:
this method seems to work!
2 questions:
how do i work around Pulseaudio not being able to run with escalated privileges?
Why is the port still in use after I close the script?
here is bluetooth2.py for reference
I am somewhat familiar with subprocess
I added this line to the server script to run my bluetooth connection script:
Code: Select all
subprocess.call("python bluetooth2.py",shell=True)
2 questions:
how do i work around Pulseaudio not being able to run with escalated privileges?
Why is the port still in use after I close the script?
here is bluetooth2.py for reference
Code: Select all
import pexpect
from sh import bluetoothctl
import subprocess
mac = "C8:84:47:26:E6:3C"
#sh.bluetoothctl("pair", mac)
print ("stuck here")
#bluetoothctl("connect", mac)
child = pexpect.spawn('bluetoothctl')
child.sendline('power on')
child.sendline('agent on')
child.sendline('default-agent')
child.sendline('pair C8:84:47:26:E6:3C')
child.sendline('trust C8:84:47:26:E6:3C')
child.sendline('connect C8:84:47:26:E6:3C')
subprocess.call("pulseaudio --start",shell=True)
subprocess.call("pacmd set-default-sink bluez_sink.C8_84_47_26_E6_3C",shell=Tru$
subprocess.call("aplay /home/pi/bleep_01.wav", shell=True)
-
- Posts: 2247
- Joined: Thu Feb 05, 2015 11:25 pm
Re: Windows to Pi with python
I'd ask that on a new threadhow do i work around Pulseaudio not being able to run with escalated privileges?
port closures do not work in the manner we muggle want them too. There is dark arts stuff going on that won't allow port re-use until timeouts (that us muggles can't change despite documentation saying we can)
I'd ask this question on a new thread as well but don't expect the answers to work!
-
- Posts: 119
- Joined: Fri Dec 12, 2014 2:21 am
Re: Windows to Pi with python
Id hope there are enough wizards on this board to answer the question!mattmiller wrote:I'd ask that on a new threadhow do i work around Pulseaudio not being able to run with escalated privileges?
port closures do not work in the manner we muggle want them too. There is dark arts stuff going on that won't allow port re-use until timeouts (that us muggles can't change despite documentation saying we can)
I'd ask this question on a new thread as well but don't expect the answers to work!
