質問編集履歴

4

誤記訂正

2020/02/01 10:45

投稿

DMC
DMC

スコア18

test CHANGED
File without changes
test CHANGED
@@ -172,7 +172,7 @@
172
172
 
173
173
 
174
174
 
175
- ```ここに言語を入力
175
+
176
176
 
177
177
  pi@DMC:~ $ sudo python3 "car_LED2.py"
178
178
 
@@ -180,36 +180,38 @@
180
180
 
181
181
  Attempt to connect...
182
182
 
183
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
183
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
184
184
 
185
185
  b'RSSI return value: 16\n'
186
186
 
187
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
187
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
188
188
 
189
189
  b'RSSI return value: 21\n'
190
190
 
191
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
191
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
192
192
 
193
193
  b'RSSI return value: 17\n'
194
194
 
195
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
195
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
196
196
 
197
197
  b'RSSI return value: 16\n'
198
198
 
199
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
199
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
200
200
 
201
201
  b'RSSI return value: 22\n'
202
202
 
203
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
203
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
204
204
 
205
205
  b'RSSI return value: 16\n'
206
206
 
207
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
207
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
208
208
 
209
209
  b'RSSI return value: 0\n'
210
210
 
211
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
211
+
212
-
212
+
213
- b'RSSI return value: 0\n'
213
+ 接続が切れるとエラーが発生しループも止まります。
214
-
214
+
215
+
216
+
215
- b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \
217
+ ```

3

接続時の状態を追記

2020/02/01 10:45

投稿

DMC
DMC

スコア18

test CHANGED
File without changes
test CHANGED
@@ -122,6 +122,8 @@
122
122
 
123
123
 
124
124
 
125
+ ```ここに言語を入力
126
+
125
127
  b'Connections:\n'
126
128
 
127
129
  Attempt to connect...
@@ -159,3 +161,55 @@
159
161
  except error:
160
162
 
161
163
  NameError: name 'error' is not defined
164
+
165
+ ```
166
+
167
+
168
+
169
+
170
+
171
+ ちなみに接続時は以下のように出力されます。
172
+
173
+
174
+
175
+ ```ここに言語を入力
176
+
177
+ pi@DMC:~ $ sudo python3 "car_LED2.py"
178
+
179
+ b'Connections:\n'
180
+
181
+ Attempt to connect...
182
+
183
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
184
+
185
+ b'RSSI return value: 16\n'
186
+
187
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
188
+
189
+ b'RSSI return value: 21\n'
190
+
191
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
192
+
193
+ b'RSSI return value: 17\n'
194
+
195
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
196
+
197
+ b'RSSI return value: 16\n'
198
+
199
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
200
+
201
+ b'RSSI return value: 22\n'
202
+
203
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
204
+
205
+ b'RSSI return value: 16\n'
206
+
207
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
208
+
209
+ b'RSSI return value: 0\n'
210
+
211
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \n'
212
+
213
+ b'RSSI return value: 0\n'
214
+
215
+ b'Connections:\n\t< ACL B4:8B:19:79:21:99 handle 12 state 1 lm SLAVE AUTH ENCRYPT \

2

コードに変更

2020/02/01 10:09

投稿

DMC
DMC

スコア18

test CHANGED
File without changes
test CHANGED
@@ -27,6 +27,8 @@
27
27
  以下コードです。
28
28
 
29
29
 
30
+
31
+ ```ここに言語を入力
30
32
 
31
33
  #coding: utf-8
32
34
 
@@ -64,7 +66,7 @@
64
66
 
65
67
  print(res)
66
68
 
67
- bd = 'B4:8B:19:79:21:99'
69
+ bd = 'B4:8B:11:11:11:11'
68
70
 
69
71
 
70
72
 
@@ -72,9 +74,9 @@
72
74
 
73
75
  if(bd in res.decode()):
74
76
 
75
- cmd = 'hcitool rssi B4:8B:19:79:21:99'
77
+ cmd = 'hcitool rssi B4:8B:11:11:11:11'
76
78
 
77
- **res = subprocess.check_output(cmd.split())**
79
+ res = subprocess.check_output(cmd.split())
78
80
 
79
81
  print(res)
80
82
 
@@ -108,13 +110,15 @@
108
110
 
109
111
 
110
112
 
113
+ ```
114
+
111
115
  ===============================
112
116
 
113
117
  エラー内容
114
118
 
115
119
 
116
120
 
117
- line25は上記の太文字列res~です。
121
+ line25は上記のhcitool rssiの下行のres~です。
118
122
 
119
123
 
120
124
 

1

インデント エラー内容追加

2020/02/01 03:44

投稿

DMC
DMC

スコア18

test CHANGED
File without changes
test CHANGED
@@ -24,44 +24,134 @@
24
24
 
25
25
 
26
26
 
27
-
28
-
29
- 以下コードは見やい様にインデント無くして左に詰めてます実際は多箇所にインデントが入ってデコボコしてます。
27
+ 以下コードです。
30
28
 
31
29
 
32
30
 
31
+ #coding: utf-8
32
+
33
+ import subprocess
34
+
35
+ import csv
36
+
37
+ import datetime
38
+
39
+ from time import sleep
40
+
41
+
42
+
43
+ record_file_name = 'blt_detect.csv'
44
+
45
+ bltcount = 0
46
+
47
+
48
+
49
+ try:
50
+
33
- while true:
51
+ while True:
52
+
53
+
54
+
55
+ record_datetime = datetime.datetime.now()
56
+
57
+ record_time = record_datetime.strftime('%Y%m%d-%X')
58
+
59
+
60
+
61
+ cmd = 'hcitool con'
62
+
63
+ res = subprocess.check_output(cmd.split())
64
+
65
+ print(res)
66
+
67
+ bd = 'B4:8B:19:79:21:99'
68
+
69
+
70
+
71
+
72
+
73
+ if(bd in res.decode()):
74
+
75
+ cmd = 'hcitool rssi B4:8B:19:79:21:99'
76
+
77
+ **res = subprocess.check_output(cmd.split())**
78
+
79
+ print(res)
80
+
81
+
82
+
83
+
84
+
85
+ else:
86
+
87
+ p1 = subprocess.Popen(["echo","connect",bd], stdout=subprocess.PIPE)
88
+
89
+ p2 = subprocess.Popen(["bluetoothctl"], stdin=p1.stdout, stdout=subprocess.PIPE)
90
+
91
+ p1.stdout.close()
92
+
93
+ outs,errs = p2.communicate()
94
+
95
+ print('Attempt to connect...')
96
+
97
+ bltcount =0
98
+
99
+
100
+
101
+ sleep(5)
102
+
103
+
104
+
105
+ except error:
106
+
107
+ pass
34
108
 
35
109
 
36
110
 
37
- cmd = 'hcitool con'
111
+ ===============================
38
112
 
39
- res = subprocess.check_output(cmd.split())
40
-
41
- print(res)
113
+ エラー内容
42
-
43
-
44
-
45
- bd = '00:11:22:33:44:55'
46
114
 
47
115
 
48
116
 
49
- if(bd in res.decode()):
117
+ line25は上記の太文字列res~です。
50
-
51
- cmd = ‘hcitool rssi 00:11:22:33:44:55
52
-
53
- res=subprocess.check_output(cmd.split())
54
-
55
- print(res)   
56
118
 
57
119
 
58
120
 
59
- else:
121
+ b'Connections:\n'
60
122
 
61
- p1 =subprocess.Popen(["echo","connect",bd], stdout=subprocess.PIPE)
123
+ Attempt to connect...
62
124
 
63
- p2 = subprocess.Popen(["bluetoothctl"], stdin=p1.stdout, stdout=subprocess.PIPE)
125
+ b'Connections:\n\t< ACL B4:8B:11:11:11:11 handle 0 state 5 lm MASTER \n'
64
126
 
65
- p1.stdout.close()outs,errs = p2.communicate()
127
+ Read RSSI failed: Input/output error
66
128
 
129
+ Traceback (most recent call last):
130
+
131
+ File "car_LED2.py", line 25, in <module>
132
+
133
+ res = subprocess.check_output(cmd.split())
134
+
135
+ File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
136
+
137
+ **kwargs).stdout
138
+
139
+ File "/usr/lib/python3.7/subprocess.py", line 487, in run
140
+
141
+ output=stdout, stderr=stderr)
142
+
143
+ subprocess.CalledProcessError: Command '['hcitool', 'rssi', 'B4:8B:11:11:11:11']' returned non-zero exit status 1.
144
+
145
+
146
+
147
+ During handling of the above exception, another exception occurred:
148
+
149
+
150
+
151
+ Traceback (most recent call last):
152
+
153
+ File "car_LED2.py", line 44, in <module>
154
+
155
+ except error:
156
+
67
- print('Attempt to connect...')
157
+ NameError: name 'error' is not defined