hey
ik heb een python script,
deze zorgt ervoor dat ik de uitgangen van een raspberry pi kan schakelen via een app. op me iphone
het script werkt perfect, alleen waneer ik de app. op me iphone sluit stopt het script ook, en is het niet mogelijk om nog iets te schakelen
kan iemand mijn vertellen wat er fout staat in het script,
ik wil ook graag dat het script start waneer ik de raspberry pi opstart nu moet ik elke keer het commando sudo python testsocket.py ingeven
mvg
ik heb een python script,
deze zorgt ervoor dat ik de uitgangen van een raspberry pi kan schakelen via een app. op me iphone
het script werkt perfect, alleen waneer ik de app. op me iphone sluit stopt het script ook, en is het niet mogelijk om nog iets te schakelen
kan iemand mijn vertellen wat er fout staat in het script,
ik wil ook graag dat het script start waneer ik de raspberry pi opstart nu moet ik elke keer het commando sudo python testsocket.py ingeven
mvg
Python:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
| #! /usr/bin/python # Echo server program import socket import RPi.GPIO as GPIO ##################################################################### #### SETUP IOs ###################################################### ##################################################################### # to use Raspberry Pi board pin numbers GPIO.setmode(GPIO.BCM) # For LED1 we use pin 4 according BCM pin count # (see https://projects.drogon.net/raspberry-pi/wiringpi/pins/) LED1 = 4 LED2 = 17 LED3 = 2 LED4 = 22 LED5 = 10 LED6 = 9 LED7 = 11 LED8 = 18 # For Switch input we use pin 17 according BCM pin count SWITCH1 = 25 # set up GPIO output channel GPIO.setup(LED1, GPIO.OUT) GPIO.setup(LED2, GPIO.OUT) GPIO.setup(LED3, GPIO.OUT) GPIO.setup(LED4, GPIO.OUT) GPIO.setup(LED5, GPIO.OUT) GPIO.setup(LED6, GPIO.OUT) GPIO.setup(LED7, GPIO.OUT) GPIO.setup(LED8, GPIO.OUT) # set up GPIO input with pull-up control # (pull_up_down be PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF) GPIO.setup(SWITCH1, GPIO.IN, pull_up_down=GPIO.PUD_UP) ##################################################################### #### SETUP SOCKET INTERFASE ######################################### ##################################################################### HOST = '' # Symbolic name meaning the local host PORT = 54321 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr ##################################################################### #### Continous loop, that waits for new data and acts depending #### #### on data content on it #### ##################################################################### while 1: data = conn.recv(1024) print 'New Receive', data if not data: break print 'Received Data:', data if data == 'LED1 on\n': conn.send('on') GPIO.output(LED1, GPIO.HIGH) print 'On empfangen' if data == 'LED2 on\n': conn.send('on') GPIO.output(LED2, GPIO.HIGH) print 'On empfangen' if data == 'LED3 on\n': conn.send('on') GPIO.output(LED3, GPIO.HIGH) print 'On empfangen' if data == 'LED4 on\n': conn.send('on') GPIO.output(LED4, GPIO.HIGH) print 'On empfangen' if data == 'LED5 on\n': conn.send('on') GPIO.output(LED5, GPIO.HIGH) print 'On empfangen' if data == 'LED6 on\n': conn.send('on') GPIO.output(LED6, GPIO.HIGH) print 'On empfangen' if data == 'LED7 on\n': conn.send('on') GPIO.output(LED7, GPIO.HIGH) print 'On empfangen' if data == 'LED8 on\n': conn.send('on') GPIO.output(LED8, GPIO.HIGH) print 'On empfangen' elif data == 'LED1 off\n': conn.send('off') GPIO.output(LED1, GPIO.LOW) print 'Off empfangen' elif data == 'LED2 off\n': conn.send('off') GPIO.output(LED2, GPIO.LOW) print 'Off empfangen' elif data == 'LED3 off\n': conn.send('off') GPIO.output(LED3, GPIO.LOW) print 'Off empfangen' elif data == 'LED4 off\n': conn.send('off') GPIO.output(LED4, GPIO.LOW) print 'Off empfangen' elif data == 'LED5 off\n': conn.send('off') GPIO.output(LED5, GPIO.LOW) print 'Off empfangen' elif data == 'LED6 off\n': conn.send('off') GPIO.output(LED6, GPIO.LOW) print 'Off empfangen' elif data == 'LED7 off\n': conn.send('off') GPIO.output(LED7, GPIO.LOW) print 'Off empfangen' elif data == 'LED8 off\n': conn.send('off') GPIO.output(LED8, GPIO.LOW) print 'Off empfangen' elif data == 'get status\n': print 'Input Status:', GPIO.input(SWITCH1) if GPIO.input(SWITCH1): conn.send('off') # inverted logic here: pullup force to true with open switch print 'Read GIOP 0 result On' else: conn.send('on') # inverted logic here: Switch switchs to ground -> false print 'Read GIOP 0 result Off' # ende if else: conn.send('unknown command') print 'Unknown command:', data # continue with while 1 conn.close() |