質問編集履歴
3
HTPのUUIDを変更 進展の表記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
pythonでesp32をBLE通信 nRFToolBoxで表示されません
|
1
|
+
pythonでesp32をBLE通信 nRFToolBoxで体温計が表示されません
|
test
CHANGED
@@ -2,21 +2,17 @@
|
|
2
2
|
|
3
3
|
pythonでesp32を操作し、BLE通信を行いたいです。
|
4
4
|
|
5
|
+
nRFToolBoxでHealth Thermometer Moniterで体温を見れるようにしたいです。
|
6
|
+
|
5
7
|
|
6
8
|
|
7
9
|
###分からないところ
|
8
10
|
|
9
|
-
nRFToolBoxというアプリを用いてHealth Thermometerで温度を見れるようにしたいのですが、The device does not have required servicesと表示されます。
|
10
|
-
|
11
|
-
コードエラーは出ていません。
|
12
|
-
|
13
|
-
アドバイスをお願いします。
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
nRFConnectでは温度とデバイス情報を得ることができました。
|
18
|
-
|
19
|
-
n
|
11
|
+
Temperature measurementでの温度の表し方。
|
12
|
+
|
13
|
+
Client Characteristic Configurationの使い方。
|
14
|
+
|
15
|
+
それをどうやってgatts_writeに書き込むか
|
20
16
|
|
21
17
|
|
22
18
|
|
@@ -34,12 +30,16 @@
|
|
34
30
|
|
35
31
|
|
36
32
|
|
33
|
+
|
34
|
+
|
37
35
|
from machine import *
|
38
36
|
|
39
37
|
from micropython import const
|
40
38
|
|
41
39
|
|
42
40
|
|
41
|
+
|
42
|
+
|
43
43
|
_IRQ_CENTRAL_CONNECT = const(1)
|
44
44
|
|
45
45
|
_IRQ_CENTRAL_DISCONNECT = const(2)
|
@@ -48,29 +48,39 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
+
|
52
|
+
|
51
53
|
_HEALTH_THERM_UUID = bluetooth.UUID(0x1809)
|
52
54
|
|
53
55
|
_DEVICE_INFO_UUID = bluetooth.UUID(0x180A)
|
54
56
|
|
55
57
|
|
56
58
|
|
59
|
+
|
60
|
+
|
61
|
+
_TEM_CHAR = (bluetooth.UUID(0x2A1C), bluetooth.FLAG_INDICATE)
|
62
|
+
|
57
|
-
_
|
63
|
+
_CLI_CHAR = (bluetooth.UUID(0x2902), bluetooth.FLAG_READ|bluetooth.FLAG_WRITE)
|
58
|
-
|
64
|
+
|
65
|
+
|
66
|
+
|
59
|
-
_MAN_CHAR = (bluetooth.UUID(0x2A29), bluetooth.FLAG_READ
|
67
|
+
_MAN_CHAR = (bluetooth.UUID(0x2A29), bluetooth.FLAG_READ)
|
60
|
-
|
68
|
+
|
61
|
-
_MOD_CHAR = (bluetooth.UUID(0x2A24), bluetooth.FLAG_READ
|
69
|
+
_MOD_CHAR = (bluetooth.UUID(0x2A24), bluetooth.FLAG_READ)
|
62
|
-
|
70
|
+
|
63
|
-
_SYS_CHAR = (bluetooth.UUID(0x2A23), bluetooth.FLAG_READ
|
71
|
+
_SYS_CHAR = (bluetooth.UUID(0x2A23), bluetooth.FLAG_READ)
|
64
|
-
|
65
|
-
|
66
|
-
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
67
|
-
_HEALTH_THERM_SERVICE = (_HEALTH_THERM_UUID, (_TEMP_CHAR,)
|
77
|
+
_HEALTH_THERM_SERVICE = (_HEALTH_THERM_UUID, (_TEMP_CHAR, _CLI_CHAR))
|
68
|
-
|
78
|
+
|
69
|
-
_DEVICE_INFO_SERVICE = (_DEVICE_INFO_UUID, (_MAN_CHAR, _MOD_CHAR, _SYS_CHAR
|
79
|
+
_DEVICE_INFO_SERVICE = (_DEVICE_INFO_UUID, (_MAN_CHAR, _MOD_CHAR, _SYS_CHAR))
|
70
|
-
|
71
|
-
|
72
|
-
|
80
|
+
|
73
|
-
_SERVICES = (_HEALTH_THERM_SERVICE,_DEVICE_INFO_SERVICE
|
81
|
+
_SERVICES = (_HEALTH_THERM_SERVICE,_DEVICE_INFO_SERVICE)
|
82
|
+
|
83
|
+
|
74
84
|
|
75
85
|
|
76
86
|
|
@@ -84,90 +94,90 @@
|
|
84
94
|
|
85
95
|
def __init__(self, ble, name="health-therm"):
|
86
96
|
|
87
|
-
|
97
|
+
self._ble = ble
|
88
|
-
|
98
|
+
|
89
|
-
|
99
|
+
self._ble.active(True)
|
90
|
-
|
100
|
+
|
91
|
-
|
101
|
+
self._ble.irq(self._irq)
|
92
|
-
|
102
|
+
|
93
|
-
|
103
|
+
self._connections = set()
|
94
|
-
|
104
|
+
|
95
|
-
|
105
|
+
((self._Temp, self._Cli),(self._Man, self._Mod, self._Sys)) = self._ble.gatts_register_services(_SERVICES)
|
96
|
-
|
97
|
-
|
106
|
+
|
98
|
-
|
99
|
-
|
107
|
+
self._payload = advertising_payload(name=name, services=[_HEALTH_THERM_UUID], appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER)
|
108
|
+
|
109
|
+
self._advertise()
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
def _irq(self, event, data):
|
114
|
+
|
115
|
+
if event == _IRQ_CENTRAL_CONNECT:
|
116
|
+
|
117
|
+
conn_handle, addr_type, addr = data
|
118
|
+
|
119
|
+
self._connections.add(conn_handle)
|
120
|
+
|
121
|
+
elif event == _IRQ_CENTRAL_DISCONNECT:
|
122
|
+
|
123
|
+
conn_handle, addr_type, addr = data
|
124
|
+
|
125
|
+
self._connections.remove(conn_handle)
|
100
126
|
|
101
127
|
self._advertise()
|
102
128
|
|
103
|
-
|
104
|
-
|
105
|
-
def _irq(self, event, data):
|
106
|
-
|
107
|
-
if event == _IRQ_CENTRAL_CONNECT:
|
108
|
-
|
109
|
-
conn_handle, addr_type, addr = data
|
110
|
-
|
111
|
-
self._connections.add(conn_handle)
|
112
|
-
|
113
|
-
elif event == _IRQ_CENTRAL_DISCONNECT:
|
114
|
-
|
115
|
-
conn_handle, addr_type, addr = data
|
116
|
-
|
117
|
-
self._connections.remove(conn_handle)
|
118
|
-
|
119
|
-
|
129
|
+
elif event == _IRQ_GATTC_NOTIFY:
|
120
|
-
|
130
|
+
|
121
|
-
|
131
|
+
conn_handle, value_handle, notify_data = data
|
122
|
-
|
123
|
-
self._advertise()
|
124
132
|
|
125
133
|
|
126
134
|
|
127
135
|
def set_temperature(self, temp_deg_c, notify=False, indicate=False):
|
128
136
|
|
129
|
-
|
137
|
+
self._ble.gatts_write(self._Temp, struct.pack('<h', int(temp_deg_c * 100)))
|
130
|
-
|
138
|
+
|
131
|
-
|
139
|
+
if notify:
|
132
|
-
|
140
|
+
|
133
|
-
|
141
|
+
for conn_handle in self._connections:
|
142
|
+
|
134
|
-
|
143
|
+
print("notify!")
|
144
|
+
|
135
|
-
|
145
|
+
self._ble.gatts_notify(conn_handle, self._Temp)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
def set_device(self):
|
150
|
+
|
151
|
+
self._ble.gatts_write(self._Man, "TSMC", True)
|
152
|
+
|
153
|
+
self._ble.gatts_write(self._Mod, "ESP32-DOWDQ5 Rev 1", True)
|
154
|
+
|
155
|
+
self._ble.gatts_write(self._Sys, struct.pack('l',14227020), True)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
def _advertise(self, interval_us=500000):
|
160
|
+
|
161
|
+
self._ble.gap_advertise(interval_us, adv_data=self._payload)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
def demo():
|
166
|
+
|
167
|
+
ble = bluetooth.BLE()
|
168
|
+
|
169
|
+
temp = BLETemperature(ble)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
i = 0
|
136
174
|
|
137
175
|
|
138
176
|
|
139
|
-
|
177
|
+
temp.set_device()
|
140
|
-
|
141
|
-
self._ble.gatts_write(self._Man, "TSMC", True)
|
142
|
-
|
143
|
-
self._ble.gatts_write(self._Mod, "ESP32-DOWDQ5 Rev 1", True)
|
144
|
-
|
145
|
-
self._ble.gatts_write(self._Sys, struct.pack('l',14227020), True)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
def _advertise(self, interval_us=500000):
|
150
|
-
|
151
|
-
self._ble.gap_advertise(interval_us, adv_data=self._payload)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
def demo():
|
156
|
-
|
157
|
-
ble = bluetooth.BLE()
|
158
|
-
|
159
|
-
temp = BLETemperature(ble)
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
i = 0
|
164
178
|
|
165
179
|
|
166
180
|
|
167
|
-
temp.set_device()
|
168
|
-
|
169
|
-
|
170
|
-
|
171
181
|
adc = ADC(Pin(32))
|
172
182
|
|
173
183
|
adc.atten(ADC.ATTN_11DB)
|
@@ -180,27 +190,27 @@
|
|
180
190
|
|
181
191
|
while True:
|
182
192
|
|
183
|
-
|
193
|
+
adc.atten(ADC.ATTN_11DB)
|
184
|
-
|
194
|
+
|
185
|
-
|
195
|
+
val=adc.read_u16()
|
186
|
-
|
196
|
+
|
187
|
-
|
197
|
+
val=val/65535*3.6
|
188
|
-
|
198
|
+
|
189
|
-
|
199
|
+
val=((36000/val)-10000)/1000
|
190
|
-
|
200
|
+
|
191
|
-
|
201
|
+
val=-30.24*math.log(val)+95.664
|
192
|
-
|
193
|
-
|
194
|
-
|
202
|
+
|
203
|
+
|
204
|
+
|
195
|
-
|
205
|
+
print(val)
|
196
|
-
|
197
|
-
|
198
|
-
|
206
|
+
|
207
|
+
|
208
|
+
|
199
|
-
|
209
|
+
i = (i + 1) % 5
|
200
|
-
|
210
|
+
|
201
|
-
|
211
|
+
temp.set_temperature(val, notify=i==0, indicate=False)
|
202
|
-
|
212
|
+
|
203
|
-
|
213
|
+
time.sleep_ms(1000)
|
204
214
|
|
205
215
|
|
206
216
|
|
@@ -208,6 +218,32 @@
|
|
208
218
|
|
209
219
|
demo()
|
210
220
|
|
211
|
-
|
212
|
-
|
213
221
|
```
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
###進展
|
226
|
+
|
227
|
+
Health thermometer Serviceを見直した結果、UUIDとCharacteristicが間違っていたので直した結果、
|
228
|
+
|
229
|
+
The device does not have required services.
|
230
|
+
|
231
|
+
という注意は出なくなりました。
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
ですがnRFToolBoxではまだ温度が表示されず、nRFConnectでの温度表示も正しい値が出なくなりました。
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
怪しいと睨んでいるのは
|
240
|
+
|
241
|
+
__init__のadvertising_payloadのservicesの値
|
242
|
+
|
243
|
+
set_temperatureのgatts_writeの()の中身
|
244
|
+
|
245
|
+
の二つです。
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
どなたか使い方を教えてくれませんか?
|
2
import time や demo あたりを訂正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
###分からないところ
|
8
8
|
|
9
|
-
nRFToolBoxというアプリを用いてHealth Thermometerで温度を見れるようにしたいのですが、
|
9
|
+
nRFToolBoxというアプリを用いてHealth Thermometerで温度を見れるようにしたいのですが、The device does not have required servicesと表示されます。
|
10
10
|
|
11
11
|
コードエラーは出ていません。
|
12
12
|
|
@@ -16,6 +16,8 @@
|
|
16
16
|
|
17
17
|
nRFConnectでは温度とデバイス情報を得ることができました。
|
18
18
|
|
19
|
+
nRFToolBoxではデバイスが表示されるようになりました。
|
20
|
+
|
19
21
|
|
20
22
|
|
21
23
|
###コード
|
@@ -28,6 +30,8 @@
|
|
28
30
|
|
29
31
|
import math
|
30
32
|
|
33
|
+
import time
|
34
|
+
|
31
35
|
|
32
36
|
|
33
37
|
from machine import *
|
@@ -40,6 +44,8 @@
|
|
40
44
|
|
41
45
|
_IRQ_CENTRAL_DISCONNECT = const(2)
|
42
46
|
|
47
|
+
_IRQ_GATTC_NOTIFY = const(18)
|
48
|
+
|
43
49
|
|
44
50
|
|
45
51
|
_HEALTH_THERM_UUID = bluetooth.UUID(0x1809)
|
@@ -110,6 +116,12 @@
|
|
110
116
|
|
111
117
|
self._connections.remove(conn_handle)
|
112
118
|
|
119
|
+
elif event == _IRQ_GATTC_NOTIFY:
|
120
|
+
|
121
|
+
conn_handle, value_handle, notify_data = data
|
122
|
+
|
123
|
+
self._advertise()
|
124
|
+
|
113
125
|
|
114
126
|
|
115
127
|
def set_temperature(self, temp_deg_c, notify=False, indicate=False):
|
@@ -138,7 +150,9 @@
|
|
138
150
|
|
139
151
|
self._ble.gap_advertise(interval_us, adv_data=self._payload)
|
140
152
|
|
153
|
+
|
154
|
+
|
141
|
-
|
155
|
+
def demo():
|
142
156
|
|
143
157
|
ble = bluetooth.BLE()
|
144
158
|
|
@@ -188,4 +202,12 @@
|
|
188
202
|
|
189
203
|
time.sleep_ms(1000)
|
190
204
|
|
205
|
+
|
206
|
+
|
207
|
+
if __name__ == "__main__":
|
208
|
+
|
209
|
+
demo()
|
210
|
+
|
211
|
+
|
212
|
+
|
191
213
|
```
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,6 +19,8 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
###コード
|
22
|
+
|
23
|
+
```Python
|
22
24
|
|
23
25
|
import bluetooth
|
24
26
|
|
@@ -185,3 +187,5 @@
|
|
185
187
|
temp.set_temperature(val, notify=i == 0, indicate=False)
|
186
188
|
|
187
189
|
time.sleep_ms(1000)
|
190
|
+
|
191
|
+
```
|