Skip to content

Commit bf4d425

Browse files
committed
Merge branch 'publish_new_sensor_dev' into maidnl_dev
2 parents 29ecc07 + 20e1ac4 commit bf4d425

File tree

2 files changed

+243
-28
lines changed

2 files changed

+243
-28
lines changed

examples/ScienceJournal/ScienceJournal.ino

Lines changed: 124 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,56 @@ void setup(){
4747

4848
BLE.setLocalName(name.c_str());
4949
BLE.setDeviceName(name.c_str());
50-
BLE.setAdvertisedService(service);
5150

51+
52+
BLE.setAdvertisedService(service);
53+
/* ________________________________________________________________VERSION */
5254
service.addCharacteristic(versionCharacteristic);
55+
/* ________________________________________________________________CURRENT */
5356
service.addCharacteristic(currentCharacteristic);
57+
/* ________________________________________________________________VOLTAGE */
5458
service.addCharacteristic(voltageCharacteristic);
59+
/* ______________________________________________________________RESISTANCE */
5560
service.addCharacteristic(resistanceCharacteristic);
61+
/* _________________________________________________________________LIGHT */
5662
service.addCharacteristic(lightCharacteristic);
63+
/* _______________________________________________________________PROXIMITY */
5764
service.addCharacteristic(proximityCharacteristic);
65+
/* ____________________________________________________________ACCELERATION */
5866
service.addCharacteristic(accelerationCharacteristic);
67+
/* _______________________________________________________________GYROSCOPE */
5968
service.addCharacteristic(gyroscopeCharacteristic);
69+
/* ____________________________________________________________MAGNETOMETER */
6070
service.addCharacteristic(magnetometerCharacteristic);
71+
/* _____________________________________________________________TEMPERATURE */
6172
service.addCharacteristic(temperatureCharacteristic);
73+
/* ________________________________________________________________PRESSURE */
6274
service.addCharacteristic(pressureCharacteristic);
75+
/* ________________________________________________________________HUMIDITY */
6376
service.addCharacteristic(humidityCharacteristic);
77+
/* _____________________________________________________________AIR_QUALITY */
78+
service.addCharacteristic(airQualityCharacteristic);
79+
/* _________________________________________________________SOUND_INTENSITY */
6480
service.addCharacteristic(sndIntensityCharacteristic);
81+
/* ______!!! NOT AVAILABLE (should be delete?) !!!______________SOUND_PITCH */
6582
service.addCharacteristic(sndPitchCharacteristic);
83+
/* _________________________________________________________________INPUT_A */
6684
service.addCharacteristic(inputACharacteristic);
85+
/* _________________________________________________________________INPUT_B */
6786
service.addCharacteristic(inputBCharacteristic);
87+
/* ____________________________________________________EXTERNAL_TEMPERATURE */
88+
service.addCharacteristic(extTempCharacteristic);
89+
/* ____________________________________________________FUNCTION_GENERATOR_1 */
90+
service.addCharacteristic(funcGenOneCharacteristic);
91+
/* ____________________________________________________FUNCTION_GENERATOR_2 */
92+
service.addCharacteristic(funcGenTwoCharacteristic);
93+
/* ________________________________________________________________DISTANCE */
94+
service.addCharacteristic(distanceCharacteristic);
95+
/* ____________________________________________________________________PING */
96+
service.addCharacteristic(pingCharacteristic);
97+
6898

99+
/* ________________________________________________________________VERSION */
69100
versionCharacteristic.setValue(VERSION);
70101

71102
BLE.addService(service);
@@ -103,18 +134,25 @@ void loop(){
103134
}
104135

105136
void updateSubscribedCharacteristics(){
137+
/* ________________________________________________________________CURRENT */
106138
if(currentCharacteristic.subscribed()){
107139
currentCharacteristic.writeValue(science_kit.getCurrent());
108140
}
109141

142+
143+
/* ________________________________________________________________VOLTAGE */
110144
if(voltageCharacteristic.subscribed()){
111145
voltageCharacteristic.writeValue(science_kit.getVoltage());
112146
}
113-
147+
148+
149+
/* ______________________________________________________________RESISTANCE */
114150
if(resistanceCharacteristic.subscribed()){
115151
resistanceCharacteristic.writeValue(science_kit.getResistance());
116152
}
117-
153+
154+
155+
/* _________________________________________________________________LIGHT */
118156
if (lightCharacteristic.subscribed()){
119157
long light[4];
120158
light[0] = science_kit.getRed();
@@ -124,18 +162,25 @@ void updateSubscribedCharacteristics(){
124162
lightCharacteristic.writeValue((byte*)light, sizeof(light));
125163
}
126164

165+
166+
/* _______________________________________________________________PROXIMITY */
127167
if (proximityCharacteristic.subscribed()){ // need to be fixed
128-
/*
168+
129169
proximityCharacteristic.writeValue(science_kit.getProximity());
130-
*/
170+
171+
172+
/*
131173
if (science_kit.getUltrasonicIsConnected()){
132174
proximityCharacteristic.writeValue(science_kit.getDistance()*100.0);
133175
}
134176
else{
135177
proximityCharacteristic.writeValue(-1.0);
136178
}
179+
*/
137180
}
138-
181+
182+
183+
/* ____________________________________________________________ACCELERATION */
139184
if (accelerationCharacteristic.subscribed()){
140185
float acceleration[3];
141186
acceleration[0] = science_kit.getAccelerationX();
@@ -144,6 +189,7 @@ void updateSubscribedCharacteristics(){
144189
accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration));
145190
}
146191

192+
/* _______________________________________________________________GYROSCOPE */
147193
if (gyroscopeCharacteristic.subscribed()){
148194
float gyroscope[3];
149195
gyroscope[0] = science_kit.getAngularVelocityX();
@@ -152,6 +198,7 @@ void updateSubscribedCharacteristics(){
152198
gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope));
153199
}
154200

201+
/* ____________________________________________________________MAGNETOMETER */
155202
if (magnetometerCharacteristic.subscribed()){
156203
float magnetometer[3];
157204
magnetometer[0] = science_kit.getMagneticFieldX();
@@ -160,38 +207,105 @@ void updateSubscribedCharacteristics(){
160207
magnetometerCharacteristic.writeValue((byte*)magnetometer, sizeof(magnetometer));
161208
}
162209

210+
/*
211+
* BME688
212+
*/
213+
214+
/* _____________________________________________________________TEMPERATURE */
163215
if(temperatureCharacteristic.subscribed()){
164216
temperatureCharacteristic.writeValue(science_kit.getTemperature());
165217
}
166218

219+
/* ________________________________________________________________PRESSURE */
167220
if(pressureCharacteristic.subscribed()){
168221
pressureCharacteristic.writeValue(science_kit.getPressure());
169222
}
170223

224+
/* ________________________________________________________________HUMIDITY */
171225
if(humidityCharacteristic.subscribed()){
172226
humidityCharacteristic.writeValue(science_kit.getHumidity());
173227
}
228+
229+
/* _____________________________________________________________AIR_QUALITY */
230+
if(airQualityCharacteristic.subscribed()){
231+
airQualityCharacteristic.writeValue(science_kit.getAirQuality());
232+
}
174233

175-
// need to be fixed
234+
/*
235+
* MICROPHONE
236+
*/
237+
238+
/* _________________________________________________________SOUND_INTENSITY */
239+
/* NOTE: raw value - value not in Db */
176240
if(sndIntensityCharacteristic.subscribed()){
177241
sndIntensityCharacteristic.writeValue(science_kit.getMicrophoneRMS());
178242
}
179243

180-
// need to be fixed
244+
/* ______!!! NOT AVAILABLE (should be delete?) !!!______________SOUND_PITCH */
245+
/* NOTE: pith is frequency (not available because FFT cannot be performed) */
181246
if(sndPitchCharacteristic.subscribed()){
182247
sndPitchCharacteristic.writeValue(science_kit.getExternalTemperature());
183248
}
184249

250+
/* _________________________________________________________________INPUT_A */
185251
if (inputACharacteristic.subscribed()){
186-
/*
187252
inputACharacteristic.writeValue(science_kit.getInputA());
253+
254+
/* NOTE_ OLD CODE USED FOR DEBUG
255+
inputACharacteristic.writeValue(science_kit.getFrequency1());
188256
*/
189-
inputACharacteristic.writeValue(science_kit.getFrequency1());
190257
}
191258

259+
/* _________________________________________________________________INPUT_B */
192260
if (inputBCharacteristic.subscribed()){
193261
inputBCharacteristic.writeValue(science_kit.getInputB());
194262
}
263+
264+
/*_____________________________________________________EXTERNAL_TEMPERATURE */
265+
if(extTempCharacteristic.subscribed()){
266+
extTempCharacteristic.writeValue(science_kit.getExternalTemperature());
267+
}
268+
269+
270+
/* ____________________________________________________FUNCTION_GENERATOR_1 */
271+
if (funcGenOneCharacteristic.subscribed()){
272+
long f1[2];
273+
f1[0] = (science_kit.getFrequency1() * science_kit.getRange1());
274+
f1[1] = science_kit.getPhase1();
275+
funcGenOneCharacteristic.writeValue((byte*)f1, sizeof(f1));
276+
}
277+
278+
/* ____________________________________________________FUNCTION_GENERATOR_2 */
279+
if (funcGenTwoCharacteristic.subscribed()){
280+
long f2[2];
281+
f2[0] = (science_kit.getFrequency2() * science_kit.getRange2());
282+
f2[1] = science_kit.getPhase2();
283+
funcGenTwoCharacteristic.writeValue((byte*)f2, sizeof(f2));
284+
}
285+
286+
/* ________________________________________________________________DISTANCE */
287+
if (distanceCharacteristic.subscribed()){
288+
if (science_kit.getUltrasonicIsConnected()){
289+
/* NOTE: getDistance() calls getMeters()
290+
Requested value is in meters */
291+
distanceCharacteristic.writeValue(science_kit.getDistance());
292+
}
293+
else{
294+
distanceCharacteristic.writeValue(-1.0);
295+
}
296+
}
297+
298+
/* ____________________________________________________________________PING */
299+
if (pingCharacteristic.subscribed()){
300+
if (science_kit.getUltrasonicIsConnected()){
301+
/* NOTE: getTravelTime() returns micro seconds */
302+
/* Converted to milliseconds (agreed with RF 20230719) */
303+
pingCharacteristic.writeValue(science_kit.getTravelTime() * 1000.0 );
304+
}
305+
else{
306+
pingCharacteristic.writeValue(-1.0);
307+
}
308+
}
195309
}
196310

197311

examples/ScienceJournal/ble_config.h

Lines changed: 119 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,127 @@
2222

2323
#include <ArduinoBLE.h>
2424

25-
const int VERSION = 0x00000001;
25+
const int VERSION = 0x00000002;
26+
27+
#define BLE_CH_SERVICE "0000"
28+
#define BLE_CH_VERSION "0001"
29+
30+
#define BLE_CH_CURRENT "1001"
31+
#define BLE_CH_VOLTAGE "1002"
32+
#define BLE_CH_RESISTA "1003"
33+
#define BLE_CH___LIGHT "1004"
34+
#define BLE_CH_PROXIMI "1005"
35+
#define BLE_CH_ACCELER "1006"
36+
#define BLE_CH_GYROSCO "1007"
37+
#define BLE_CH_MAGNETO "1008"
38+
#define BLE_CH_TEMPERA "1009"
39+
#define BLE_CH_PRESSUR "1010"
40+
#define BLE_CH_HUMIDIT "1011"
41+
#define BLE_CH_SOUNDIN "1012"
42+
#define BLE_CH_SOUNDPI "1013"
43+
#define BLE_CH_FUNGEN1 "1014"
44+
#define BLE_CH_DISTANC "1015"
45+
#define BLE_CH_INPUT_A "1016"
46+
#define BLE_CH_INPUT_B "1017"
47+
#define BLE_CH_AIR_QUA "1018"
48+
#define BLE_CH_EXTTEMP "1019"
49+
#define BLE_CH____PING "1020"
50+
#define BLE_CH_FUNGEN2 "1021"
51+
2652

2753
#define SCIENCE_KIT_UUID(val) ("555a0003-" val "-467a-9538-01f0652c74e8")
28-
BLEService service (SCIENCE_KIT_UUID("0000"));
29-
BLEUnsignedIntCharacteristic versionCharacteristic (SCIENCE_KIT_UUID("0001"), BLERead);
30-
BLEFloatCharacteristic currentCharacteristic (SCIENCE_KIT_UUID("1001"), BLENotify);
31-
BLEFloatCharacteristic voltageCharacteristic (SCIENCE_KIT_UUID("1002"), BLENotify);
32-
BLEFloatCharacteristic resistanceCharacteristic (SCIENCE_KIT_UUID("1003"), BLENotify);
33-
BLECharacteristic lightCharacteristic (SCIENCE_KIT_UUID("1004"), BLENotify, 4 * sizeof(long));
34-
BLEUnsignedIntCharacteristic proximityCharacteristic (SCIENCE_KIT_UUID("1005"), BLENotify);
35-
BLECharacteristic accelerationCharacteristic (SCIENCE_KIT_UUID("1006"), BLENotify, 3 * sizeof(float));
36-
BLECharacteristic gyroscopeCharacteristic (SCIENCE_KIT_UUID("1007"), BLENotify, 3 * sizeof(float));
37-
BLECharacteristic magnetometerCharacteristic (SCIENCE_KIT_UUID("1008"), BLENotify, 3 * sizeof(float));
38-
BLEFloatCharacteristic temperatureCharacteristic (SCIENCE_KIT_UUID("1009"), BLENotify);
39-
BLEFloatCharacteristic pressureCharacteristic (SCIENCE_KIT_UUID("1010"), BLENotify);
40-
BLEFloatCharacteristic humidityCharacteristic (SCIENCE_KIT_UUID("1011"), BLENotify);
41-
BLEUnsignedIntCharacteristic sndIntensityCharacteristic (SCIENCE_KIT_UUID("1012"), BLENotify);
42-
BLEUnsignedIntCharacteristic sndPitchCharacteristic (SCIENCE_KIT_UUID("1013"), BLENotify);
43-
BLEUnsignedIntCharacteristic inputACharacteristic (SCIENCE_KIT_UUID("1016"), BLENotify);
44-
BLEUnsignedIntCharacteristic inputBCharacteristic (SCIENCE_KIT_UUID("1017"), BLENotify);
54+
55+
/*
56+
* SERVICE, VERSION
57+
*/
58+
59+
/* __________________________________________________________________SERVICE */
60+
BLEService service (SCIENCE_KIT_UUID(BLE_CH_SERVICE));
61+
/* __________________________________________________________________VERSION */
62+
BLEUnsignedIntCharacteristic versionCharacteristic (SCIENCE_KIT_UUID(BLE_CH_VERSION), BLERead);
63+
64+
/*
65+
* CURRENT, VOLTAGE, RESISTANCE
66+
*/
67+
68+
/* __________________________________________________________________CURRENT */
69+
BLEFloatCharacteristic currentCharacteristic (SCIENCE_KIT_UUID(BLE_CH_CURRENT), BLENotify);
70+
/* __________________________________________________________________VOLTAGE */
71+
BLEFloatCharacteristic voltageCharacteristic (SCIENCE_KIT_UUID(BLE_CH_VOLTAGE), BLENotify);
72+
/* ________________________________________________________________RESISTANCE */
73+
BLEFloatCharacteristic resistanceCharacteristic (SCIENCE_KIT_UUID(BLE_CH_RESISTA), BLENotify);
74+
/* ___________________________________________________________________LIGHT */
75+
BLECharacteristic lightCharacteristic (SCIENCE_KIT_UUID(BLE_CH___LIGHT), BLENotify, 4 * sizeof(long));
76+
/* _________________________________________________________________PROXIMITY */
77+
BLEUnsignedIntCharacteristic proximityCharacteristic (SCIENCE_KIT_UUID(BLE_CH_PROXIMI), BLENotify);
78+
79+
/*
80+
* BMI270 & BMM150, 9dof imu, acceleration, gyroscope and magnetometer
81+
*/
82+
83+
/* ______________________________________________________________ACCELERATION */
84+
BLECharacteristic accelerationCharacteristic (SCIENCE_KIT_UUID(BLE_CH_ACCELER), BLENotify, 3 * sizeof(float));
85+
/* _________________________________________________________________GYROSCOPE */
86+
BLECharacteristic gyroscopeCharacteristic (SCIENCE_KIT_UUID(BLE_CH_GYROSCO), BLENotify, 3 * sizeof(float));
87+
/* ______________________________________________________________MAGNETOMETER */
88+
BLECharacteristic magnetometerCharacteristic (SCIENCE_KIT_UUID(BLE_CH_MAGNETO), BLENotify, 3 * sizeof(float));
89+
90+
/*
91+
* BME688
92+
*/
93+
94+
/* _______________________________________________________________TEMPERATURE */
95+
BLEFloatCharacteristic temperatureCharacteristic (SCIENCE_KIT_UUID(BLE_CH_TEMPERA), BLENotify);
96+
/* __________________________________________________________________PRESSURE */
97+
BLEFloatCharacteristic pressureCharacteristic (SCIENCE_KIT_UUID(BLE_CH_PRESSUR), BLENotify);
98+
/* __________________________________________________________________HUMIDITY */
99+
BLEFloatCharacteristic humidityCharacteristic (SCIENCE_KIT_UUID(BLE_CH_HUMIDIT), BLENotify);
100+
/* _______________________________________________________________AIR_QUALITY */
101+
BLEFloatCharacteristic airQualityCharacteristic (SCIENCE_KIT_UUID(BLE_CH_AIR_QUA), BLENotify); // ***
102+
103+
/*
104+
* MICROPHONE
105+
*/
106+
107+
/* ___________________________________________________________SOUND_INTENSITY */
108+
BLEUnsignedIntCharacteristic sndIntensityCharacteristic (SCIENCE_KIT_UUID(BLE_CH_SOUNDIN), BLENotify); // *** !
109+
/* ______!!! NOT AVAILABLE (should be delete?) !!!________________SOUND_PITCH */
110+
BLEUnsignedIntCharacteristic sndPitchCharacteristic (SCIENCE_KIT_UUID(BLE_CH_SOUNDPI), BLENotify);
111+
112+
/*
113+
* INPUT A,B
114+
*/
115+
116+
/* ___________________________________________________________________INPUT_A */
117+
BLEUnsignedIntCharacteristic inputACharacteristic (SCIENCE_KIT_UUID(BLE_CH_INPUT_A), BLENotify);
118+
/* ___________________________________________________________________INPUT_B */
119+
BLEUnsignedIntCharacteristic inputBCharacteristic (SCIENCE_KIT_UUID(BLE_CH_INPUT_B), BLENotify);
120+
121+
/*
122+
* EXTERNAL TEMPERATURE
123+
*/
124+
125+
/* ______________________________________________________EXTERNAL_TEMPERATURE */
126+
BLEFloatCharacteristic extTempCharacteristic (SCIENCE_KIT_UUID(BLE_CH_EXTTEMP), BLENotify); // ***
127+
128+
/*
129+
* FUNCTION GENERATOR 1,2
130+
*/
131+
132+
/* ______________________________________________________FUNCTION_GENERATOR_1 */
133+
BLECharacteristic funcGenOneCharacteristic (SCIENCE_KIT_UUID(BLE_CH_FUNGEN1), BLENotify, 2 * sizeof(long));
134+
/* ______________________________________________________FUNCTION_GENERATOR_2 */
135+
BLECharacteristic funcGenTwoCharacteristic (SCIENCE_KIT_UUID(BLE_CH_FUNGEN2), BLENotify, 2 * sizeof(long));
136+
137+
/*
138+
* DISTANCE, PING
139+
*/
140+
141+
/* __________________________________________________________________DISTANCE */
142+
BLEFloatCharacteristic distanceCharacteristic (SCIENCE_KIT_UUID(BLE_CH_DISTANC), BLENotify); // ***
143+
/* ______________________________________________________________________PING */
144+
BLEFloatCharacteristic pingCharacteristic (SCIENCE_KIT_UUID(BLE_CH____PING), BLENotify); // ***
145+
45146

46147
#endif
47148

0 commit comments

Comments
 (0)