Skip to content
Snippets Groups Projects
Commit 049b84be authored by Marie Bureau's avatar Marie Bureau
Browse files

get temperature update

parent 48e9f506
Branches
No related tags found
No related merge requests found
/*******************************/ /*******************************/
/*********** INCLUDES***********/ /*********** INCLUDES***********/
/*******************************/ /*******************************/
#include <M5StickCPlus.h>
#include <Arduino.h> #include <Arduino.h>
#include <BLEDevice.h> #include <BLEDevice.h>
#include <BLEUtils.h> #include <BLEUtils.h>
...@@ -13,7 +14,7 @@ ...@@ -13,7 +14,7 @@
#define SCAN_TIME 5 // scan period in second #define SCAN_TIME 5 // scan period in second
bool BLEScanActivated = false; bool BLEScanActivated = false;
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))
/*****************************/ /*****************************/
/********* FONCTIONS *********/ /********* FONCTIONS *********/
/*****************************/ /*****************************/
...@@ -45,14 +46,18 @@ class Advertised : public BLEAdvertisedDeviceCallbacks { ...@@ -45,14 +46,18 @@ class Advertised : public BLEAdvertisedDeviceCallbacks {
// ***** getTemperature ***** // ***** getTemperature *****
float getTemperature(BLEAdvertisedDevice device) { float getTemperature(BLEAdvertisedDevice device) {
uint8_t *pTemp = (uint8_t *)&device.getManufacturerData().c_str()[1];
return ((float)*pTemp) /10; uint8_t temp_lb = (uint8_t) device.getManufacturerData().c_str()[1]; // temperature lower byte
uint8_t temp_hb = (uint8_t)(device.getManufacturerData().c_str()[2]); // temperature higher byte
int16_t temperature = (int16_t)((uint16_t)(temp_hb)<<8) + (uint16_t)temp_lb;
return ((float)(temperature)/10);
return ((float)(temperature));
} }
// ***** getHumidity ***** // ***** getHumidity *****
uint8_t getHumidity(BLEAdvertisedDevice device) { uint8_t getHumidity(BLEAdvertisedDevice device) {
const uint8_t *pHum = (const uint8_t *)&device.getManufacturerData() const uint8_t *pHum = (const uint8_t *)&device.getManufacturerData().c_str()[3];
.c_str()[3];
return *pHum; return *pHum;
} }
}; };
...@@ -60,7 +65,7 @@ class Advertised : public BLEAdvertisedDeviceCallbacks { ...@@ -60,7 +65,7 @@ class Advertised : public BLEAdvertisedDeviceCallbacks {
void setup() { void setup() {
//init serial port //init serial port
setupSerial(); setupSerial();
M5.begin();
//init BLE //init BLE
BLEDevice::init(""); BLEDevice::init("");
Serial.printf("Starting \n"); Serial.printf("Starting \n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment