Skip to content

Commit 9f522f4

Browse files
committed
Updated TLM
1 parent 5e5d572 commit 9f522f4

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

libraries/BLE/examples/EddystoneTLM_Beacon/EddystoneTLM_Beacon.ino

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "esp_sleep.h"
2929

3030
#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up
31+
#define BEACON_POWER ESP_PWR_LVL_N12
3132
RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory
3233
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory
3334

@@ -46,19 +47,17 @@ time_t lastTenth;
4647
// for the temperature value. It is a 8.8 fixed-point notation
4748
void setBeacon()
4849
{
49-
char beacon_data[25];
50-
uint16_t beconUUID = 0xFEAA;
51-
uint16_t volt = random(2800, 3700); // 3300mV = 3.3V
52-
float tempFloat = random(-3000, 3000) / 100.0f;
53-
Serial.printf("Random temperature is %.2f°C\n", tempFloat);
54-
int temp = (int)(tempFloat * 256);
55-
Serial.printf("Converted to 8.8 format %0X%0X\n", (temp >> 8) & 0xFF, (temp & 0xFF));
50+
BLEEddystoneTLM EddystoneTLM;
51+
EddystoneTLM.setVolt((uint16_t)random(2800, 3700)); // 3300mV = 3.3V
52+
EddystoneTLM.setTemp(random(-3000, 3000) / 100.0f); // 3000 = 30.00 ˚C
53+
Serial.printf("Random Battery voltage is %d mV = 0x%04X\n", EddystoneTLM.getVolt(), EddystoneTLM.getVolt());
54+
Serial.printf("Random temperature is %.2f°C\n", EddystoneTLM.getTemp());
55+
Serial.printf("Converted to 8.8 format: 0x%04X\n", EddystoneTLM.getRawTemp());
5656

5757
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
5858
BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
59+
oScanResponseData.setServiceData(BLEUUID((uint16_t)0xFEAA), std::string(EddystoneTLM.getData().c_str(), EddystoneTLM.getData().length()));
5960

60-
oScanResponseData.setCompleteServices(BLEUUID(beconUUID));
61-
oScanResponseData.setServiceData(BLEUUID(beconUUID), std::string(beacon_data, 14));
6261
oAdvertisementData.setName("ESP32 TLM Beacon");
6362
pAdvertising->setAdvertisementData(oAdvertisementData);
6463
pAdvertising->setScanResponseData(oScanResponseData);
@@ -78,7 +77,7 @@ void setup()
7877
// Create the BLE Device
7978
BLEDevice::init("TLMBeacon");
8079

81-
BLEDevice::setPower(ESP_PWR_LVL_N12);
80+
BLEDevice::setPower(BEACON_POWER);
8281

8382
pAdvertising = BLEDevice::getAdvertising();
8483

libraries/BLE/src/BLEEddystoneTLM.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
static const char LOG_TAG[] = "BLEEddystoneTLM";
2323

2424
BLEEddystoneTLM::BLEEddystoneTLM() {
25-
beaconUUID = 0xFEAA;
2625
m_eddystoneData.frameType = EDDYSTONE_TLM_FRAME_TYPE;
2726
m_eddystoneData.version = 0;
2827
m_eddystoneData.volt = 3300; // 3300mV = 3.3V
@@ -42,12 +41,12 @@ BLEEddystoneTLM::BLEEddystoneTLM(BLEAdvertisedDevice *advertisedDevice){
4241
}
4342
}
4443

45-
std::string BLEEddystoneTLM::getData() {
46-
return std::string((char*) &m_eddystoneData, sizeof(m_eddystoneData));
44+
String BLEEddystoneTLM::getData() {
45+
return String((char*) &m_eddystoneData, sizeof(m_eddystoneData));
4746
} // getData
4847

4948
BLEUUID BLEEddystoneTLM::getUUID() {
50-
return BLEUUID(beaconUUID);
49+
return beaconUUID;
5150
} // getUUID
5251

5352
uint8_t BLEEddystoneTLM::getVersion() {
@@ -74,8 +73,8 @@ uint32_t BLEEddystoneTLM::getTime() {
7473
return (ENDIAN_CHANGE_U32(m_eddystoneData.tmil)) / 10;
7574
} // getTime
7675

77-
std::string BLEEddystoneTLM::toString() {
78-
std::string out = "";
76+
String BLEEddystoneTLM::toString() {
77+
String out = "";
7978
uint32_t rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil);
8079
char val[12];
8180

@@ -152,15 +151,16 @@ void BLEEddystoneTLM::setData(std::string data) {
152151
} // setData
153152

154153
void BLEEddystoneTLM::setUUID(BLEUUID l_uuid) {
155-
beaconUUID = l_uuid.getNative()->uuid.uuid16;
154+
beaconUUID = l_uuid;
156155
} // setUUID
157156

158157
void BLEEddystoneTLM::setVersion(uint8_t version) {
159158
m_eddystoneData.version = version;
160159
} // setVersion
161160

161+
// Set voltage in ESP32 native Big endian and convert it to little endian used for BLE Frame
162162
void BLEEddystoneTLM::setVolt(uint16_t volt) {
163-
m_eddystoneData.volt = volt;
163+
m_eddystoneData.volt = ENDIAN_CHANGE_U16(volt);
164164
} // setVolt
165165

166166
void BLEEddystoneTLM::setTemp(float temp) {
@@ -175,5 +175,5 @@ void BLEEddystoneTLM::setTime(uint32_t tmil) {
175175
m_eddystoneData.tmil = tmil;
176176
} // setTime
177177

178-
#endif
178+
#endif /* CONFIG_BLUEDROID_ENABLED */
179179
#endif /* SOC_BLE_SUPPORTED */

libraries/BLE/src/BLEEddystoneTLM.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "BLEUUID.h"
1414
#include <BLEAdvertisedDevice.h>
15+
#include <Arduino.h>
1516

1617
#define EDDYSTONE_TLM_FRAME_TYPE 0x20
1718
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8))
@@ -28,15 +29,15 @@ class BLEEddystoneTLM {
2829
public:
2930
BLEEddystoneTLM();
3031
BLEEddystoneTLM(BLEAdvertisedDevice *advertisedDevice);
31-
std::string getData();
32+
String getData();
3233
BLEUUID getUUID();
3334
uint8_t getVersion();
3435
uint16_t getVolt();
3536
float getTemp();
3637
uint16_t getRawTemp();
3738
uint32_t getCount();
3839
uint32_t getTime();
39-
std::string toString();
40+
String toString();
4041
void setData(std::string data);
4142
void setUUID(BLEUUID l_uuid);
4243
void setVersion(uint8_t version);
@@ -46,7 +47,7 @@ class BLEEddystoneTLM {
4647
void setTime(uint32_t tmil);
4748

4849
private:
49-
uint16_t beaconUUID;
50+
BLEUUID beaconUUID;
5051
struct {
5152
uint8_t frameType;
5253
uint8_t version;
@@ -55,7 +56,6 @@ class BLEEddystoneTLM {
5556
uint32_t advCount;
5657
uint32_t tmil;
5758
} __attribute__((packed)) m_eddystoneData;
58-
5959
}; // BLEEddystoneTLM
6060

6161
#endif /* SOC_BLE_SUPPORTED */

libraries/BLE/src/BLEEddystoneURL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ void BLEEddystoneURL::setPower(int8_t advertisedTxPower) {
207207
// | Length | 1 B | 0 - 17 B |
208208
// | Example | 0x02 | 0x676F6F676C65 0x07 |
209209
// | Decoded | http:// | g o o g l e .com |
210-
// Example: 0x00676F6F676C6507
211210
void BLEEddystoneURL::setURL(std::string url) {
212211
if (url.length() > sizeof(m_eddystoneData.url)) {
213212
log_e("Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url));
@@ -288,7 +287,7 @@ void BLEEddystoneURL::_initHeadder(){
288287
BLEHeadder[8] = 0x16; // Type Service Data
289288
BLEHeadder[9] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB
290289
BLEHeadder[10] = 0xFE; // Eddystone UUID 1 MSB
291-
BLEHeadder[11] = 0x10; // Eddystone Frame Type
290+
BLEHeadder[11] = 0x10; // Eddystone Frame Type - URL
292291
}
293292

294293
#endif

0 commit comments

Comments
 (0)