Eddystone URL beacon working.
This commit is contained in:
parent
f1502f2d29
commit
448e56a9e0
59
BTLE.cpp
59
BTLE.cpp
@ -286,8 +286,7 @@ void BTLE::crc( uint8_t len, uint8_t* dst ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BTLE::encodeURL(uint8_t* encodedUrl, const char *rawUrl)
|
uint8_t BTLE::encodeURL(uint8_t* encodedUrl, const char *rawUrl) {
|
||||||
{
|
|
||||||
uint8_t urlDataLength = 0;
|
uint8_t urlDataLength = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -334,3 +333,59 @@ uint8_t BTLE::encodeURL(uint8_t* encodedUrl, const char *rawUrl)
|
|||||||
}
|
}
|
||||||
return urlDataLength;
|
return urlDataLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BTLE::eddystoneURL(const char *url){
|
||||||
|
uint8_t encurl[MAX_URL_DATA + 2];
|
||||||
|
uint8_t pls = 0;
|
||||||
|
uint8_t urllen = encodeURL(encurl, url);
|
||||||
|
|
||||||
|
if (0 == urllen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// insert pseudo-random MAC address
|
||||||
|
buffer.mac[0] = ((__TIME__[6]-0x30) << 4) | (__TIME__[7]-0x30);
|
||||||
|
buffer.mac[1] = ((__TIME__[3]-0x30) << 4) | (__TIME__[4]-0x30);
|
||||||
|
buffer.mac[2] = ((__TIME__[0]-0x30) << 4) | (__TIME__[1]-0x30);
|
||||||
|
buffer.mac[3] = ((__DATE__[4]-0x30) << 4) | (__DATE__[5]-0x30);
|
||||||
|
buffer.mac[4] = month(__DATE__);
|
||||||
|
buffer.mac[5] = ((__DATE__[9]-0x30) << 4) | (__DATE__[10]-0x30);
|
||||||
|
|
||||||
|
// add device descriptor chunk
|
||||||
|
chunk(buffer,pls)->size = 0x02; // chunk size: 2
|
||||||
|
chunk(buffer,pls)->type = 0x01; // chunk type: device flags
|
||||||
|
chunk(buffer,pls)->data[0]= 0x06; // flags: CSS v5, Part A, paragraph 1.3
|
||||||
|
pls += 3;
|
||||||
|
|
||||||
|
// add eddystone service + frame packet
|
||||||
|
chunk(buffer, pls)->size = 5 + urllen; // data length
|
||||||
|
chunk(buffer, pls)->type = 0x16; // data type "Service Data"
|
||||||
|
chunk(buffer, pls)->data[0] = 0xaa; // Eddystone Service UUID of 0xFEAA
|
||||||
|
chunk(buffer, pls)->data[1] = 0xfe; // Eddystone Service UUID of 0xFEAA
|
||||||
|
chunk(buffer, pls)->data[2] = 0x10; // Frame Type: Eddystone-URL
|
||||||
|
chunk(buffer, pls)->data[3] = 0x00; // TX Power
|
||||||
|
for (uint8_t i = 0; i < urllen; i++)
|
||||||
|
chunk(buffer, pls)->data[4 + i] = encurl[i];
|
||||||
|
pls += 6 + urllen;
|
||||||
|
|
||||||
|
// total payload size must be 21 bytes or less
|
||||||
|
if (pls > 21)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// assemble header
|
||||||
|
buffer.pdu_type = 0x42; // PDU type: ADV_NONCONN_IND, TX address is random
|
||||||
|
buffer.pl_size = pls+6; // set final payload size in header incl. MAC
|
||||||
|
|
||||||
|
// calculate CRC over header+MAC+payload, append after payload
|
||||||
|
uint8_t* outbuf = (uint8_t*)&buffer;
|
||||||
|
crc( pls+8, outbuf+pls+8);
|
||||||
|
|
||||||
|
// whiten header+MAC+payload+CRC, swap bit order
|
||||||
|
whiten( pls+11 );
|
||||||
|
swapbuf( pls+11 );
|
||||||
|
|
||||||
|
// flush buffers and send
|
||||||
|
radio->stopListening();
|
||||||
|
radio->write( outbuf, pls+11 );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
11
BTLE.h
11
BTLE.h
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Florian Echtler <floe@butterbrot.org>
|
* Copyright (C) 2013 Florian Echtler <floe@butterbrot.org>
|
||||||
|
* Eddystone part Copyright (c) 2018 Pavel Brychta <pablo@xpablo.cz>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@ -69,15 +70,18 @@ class BTLE {
|
|||||||
void hopChannel(); // hop to the next channel
|
void hopChannel(); // hop to the next channel
|
||||||
|
|
||||||
// Broadcast an advertisement packet with a specific data type
|
// Broadcast an advertisement packet with a specific data type
|
||||||
// Standardized data types can be seen here:
|
// Standardized data types can be seen here:
|
||||||
// https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
|
// https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
|
||||||
bool advertise( uint8_t data_type, void* buf, uint8_t len );
|
bool advertise( uint8_t data_type, void* buf, uint8_t len );
|
||||||
|
|
||||||
// Broadcast an advertisement packet with optional payload
|
// Broadcast an advertisement packet with optional payload
|
||||||
// Data type will be 0xFF (Manufacturer Specific Data)
|
// Data type will be 0xFF (Manufacturer Specific Data)
|
||||||
bool advertise( void* buf, uint8_t len );
|
bool advertise( void* buf, uint8_t len );
|
||||||
bool listen( int timeout = 100 ); // listen for advertisement packets (if true: result = buffer)
|
bool listen( int timeout = 100 ); // listen for advertisement packets (if true: result = buffer)
|
||||||
|
|
||||||
|
// Broadcast an Eddystone URL packet
|
||||||
|
bool eddystoneURL(const char *url);
|
||||||
|
|
||||||
btle_adv_pdu buffer; // buffer for received BTLE packet (also used for outgoing!)
|
btle_adv_pdu buffer; // buffer for received BTLE packet (also used for outgoing!)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -85,6 +89,7 @@ class BTLE {
|
|||||||
void whiten( uint8_t len );
|
void whiten( uint8_t len );
|
||||||
void swapbuf( uint8_t len );
|
void swapbuf( uint8_t len );
|
||||||
void crc( uint8_t len, uint8_t* dst );
|
void crc( uint8_t len, uint8_t* dst );
|
||||||
|
uint8_t encodeURL(uint8_t* encodedUrl, const char *rawUrl);
|
||||||
|
|
||||||
RF24* radio; // pointer to the RF24 object managing the radio
|
RF24* radio; // pointer to the RF24 object managing the radio
|
||||||
uint8_t current; // current channel index
|
uint8_t current; // current channel index
|
||||||
|
Loading…
Reference in New Issue
Block a user