Skip to content

Instantly share code, notes, and snippets.

@andrewjaykeller
Last active September 21, 2016 16:56
Show Gist options
  • Save andrewjaykeller/293a5fa47a034cdee126fddecccd43ff to your computer and use it in GitHub Desktop.
Save andrewjaykeller/293a5fa47a034cdee126fddecccd43ff to your computer and use it in GitHub Desktop.
/*
Demonstrates advanced raw access to the advertisement and scan response packets.
This example only applies if you have a specific need for raw access to the advertisement
packet. This is for advanced use only, as the Simblee will not advertise is the packet
is invalid.
*/
/*
* Copyright (c) 2015 RF Digital Corp. All Rights Reserved.
*
* The source code contained in this file and all intellectual property embodied in
* or covering the source code is the property of RF Digital Corp. or its licensors.
* Your right to use this source code and intellectual property is non-transferable,
* non-sub licensable, revocable, and subject to terms and conditions of the
* SIMBLEE SOFTWARE LICENSE AGREEMENT.
* http://www.simblee.com/licenses/SimbleeSoftwareLicenseAgreement.txt
*
* THE SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
*
* This heading must NOT be removed from this file.
*/
#include <SimbleeBLE.h>
// the advertisement packet is composed of a series of variable length blocks, that can appear in any order.
// each block starts with a length byte, followed by a type byte, followed by the data.
// the payload cannot exceed 31 bytes.
// Note: since the Simblee UUID is missing from the advertisement packet, the Simblee iPhone apps will not
// be able to see this advertisement.
uint8_t advdata[] =
{
14, // length // 0
0x09, // complete local name type // 1
0x47, // 'G' // 2
0x61, // 'a' // 3
0x6E, // 'n' // 4
0x67, // 'g' // 5
0x6C, // 'l' // 6
0x69, // 'i' // 7
0x6F, // 'o' // 8
0x6E, // 'n' // 9
0x2D, // '-' // 10
0x54, // 'T' // 11
0x41, // 'A' // 12
0x43, // 'C' // 13
0x4f, // 'O' // 14
};
// pin 3 on the RGB shield is the green led
int led = 3;
void setup() {
// led used to indicate that the Simblee is advertising
pinMode(led, OUTPUT);
makeUniqueId();
SimbleeBLE_advdata = advdata;
SimbleeBLE_advdata_len = sizeof(advdata);
// uncomment for nonconnectable advertising
// (nonconnectable forces a minimum 100ms advertisement_interval, >= 100ms intervals are okay)
// SimbleeBLE.connectable = false;
// start the BLE stack
SimbleeBLE.begin();
}
void loop() {
// switch to lower power mode
Simblee_ULPDelay(INFINITE);
}
void makeUniqueId() {
// uint64_t id = getDeviceId();
String stringy = String(getDeviceIdLow(), HEX);
advdata[11] = (uint8_t)stringy.charAt(0);
advdata[12] = (uint8_t)stringy.charAt(1);
advdata[13] = (uint8_t)stringy.charAt(2);
advdata[14] = (uint8_t)stringy.charAt(3);
}
void SimbleeBLE_onAdvertisement(bool start)
{
// turn the green led on if we start advertisement, and turn it
// off if we stop advertisement
if (start)
digitalWrite(led, HIGH);
else
digitalWrite(led, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment