Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
neOCampus-arduino
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GIS-neOCampus
neOSensor
neOCampus-arduino
Commits
321f5106
Commit
321f5106
authored
1 year ago
by
Marie Bureau
Browse files
Options
Downloads
Patches
Plain Diff
ThermoPro get temp/humidity
parent
be50a74c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/BLE_ThermoPro/BLE_ThermoPro.ino
+96
-0
96 additions, 0 deletions
tests/BLE_ThermoPro/BLE_ThermoPro.ino
with
96 additions
and
0 deletions
tests/BLE_ThermoPro/BLE_ThermoPro.ino
0 → 100644
+
96
−
0
View file @
321f5106
/*******************************/
/*********** INCLUDES***********/
/*******************************/
#include
<Arduino.h>
#include
<BLEDevice.h>
#include
<BLEUtils.h>
#include
<BLEScan.h>
#include
<BLEAdvertisedDevice.h>
/*******************************/
/********* DEFINITIONS *********/
/*******************************/
#define SCAN_TIME 5 // scan period in second
bool
BLEScanActivated
=
false
;
/*****************************/
/********* FONCTIONS *********/
/*****************************/
// ***** set up Serial Port *****
void
setupSerial
()
{
#ifdef SERIAL_BAUDRATE
delay
(
3000
);
// time for USB serial link to come up anew
Serial
.
begin
(
SERIAL_BAUDRATE
);
// Start serial for output
Serial
.
setDebugOutput
(
true
);
#endif
}
class
Advertised
:
public
BLEAdvertisedDeviceCallbacks
{
public:
void
onResult
(
BLEAdvertisedDevice
device
)
{
printBLE
(
device
);
return
;
}
private
:
// ***** print BLE device info *****
void
printBLE
(
BLEAdvertisedDevice
device
)
{
if
(
device
.
getName
()
==
"TP358 (5551)"
){
Serial
.
printf
(
"Device:%s
\n
"
,
device
.
toString
().
c_str
()
);
Serial
.
printf
(
"Température:%f°C , Humidité:%d
\n
"
,
getTemperature
(
device
),
getHumidity
(
device
));
}
}
// ***** getTemperature *****
float
getTemperature
(
BLEAdvertisedDevice
device
)
{
uint8_t
*
pTemp
=
(
uint8_t
*
)
&
device
.
getManufacturerData
().
c_str
()[
1
];
return
((
float
)
*
pTemp
)
/
10
;
}
// ***** getHumidity *****
uint8_t
getHumidity
(
BLEAdvertisedDevice
device
)
{
const
uint8_t
*
pHum
=
(
const
uint8_t
*
)
&
device
.
getManufacturerData
()
.
c_str
()[
3
];
return
*
pHum
;
}
};
void
setup
()
{
//init serial port
setupSerial
();
//init BLE
BLEDevice
::
init
(
""
);
Serial
.
printf
(
"Starting
\n
"
);
}
// ***** start BLE scan *****
void
startScanBLE
()
{
BLEScan
*
pBLEScan
=
BLEDevice
::
getScan
();
// start scanning
pBLEScan
->
setAdvertisedDeviceCallbacks
(
new
Advertised
(),
true
);
pBLEScan
->
setActiveScan
(
true
);
pBLEScan
->
start
(
SCAN_TIME
,
scanCompleteCB
);
BLEScanActivated
=
true
;
}
// ***** scan Complete Call Back *****
static
void
scanCompleteCB
(
BLEScanResults
scanResults
)
{
// Callback invoked when scanning has completed
BLEScanActivated
=
false
;
}
// ***** manage BLE scan *****
void
manageBLEscan
()
{
if
(
!
BLEScanActivated
)
startScanBLE
();
// start scanning
}
void
loop
()
{
manageBLEscan
();
delay
(
1000
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment