The Location Puck gives your smartphone context about its location. Built on the Puck IOT platform.

Dependencies:   Puck mbed

The location puck will give your smartphone context about the phone’s location. You can later set up rules for what should happen at different locations in the smartphone companion application (Puck Central).

A tutorial for the Location Puck is available on GitHub.

Tutorials and in-depth documentation for the Puck platform is available at the project's GitHub page

Committer:
cristea
Date:
Thu Jun 19 11:17:30 2014 +0200
Revision:
3:4cb285fb29e7
Parent:
2:67d603617000
Child:
4:4324d5acd5d8
Add advertising for bluetooth

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cristea 0:f4fbeaabdff5 1 #include <mbed.h>
cristea 3:4cb285fb29e7 2 #include <nRF51822.h>
cristea 0:f4fbeaabdff5 3
cristea 3:4cb285fb29e7 4 #define DEBUG 1
cristea 0:f4fbeaabdff5 5
cristea 3:4cb285fb29e7 6 #ifdef DEBUG
cristea 3:4cb285fb29e7 7 #define LOG(args...) pc.printf(args)
cristea 3:4cb285fb29e7 8 #else
cristea 3:4cb285fb29e7 9 #define LOG(args...)
cristea 3:4cb285fb29e7 10 #endif
cristea 0:f4fbeaabdff5 11
cristea 3:4cb285fb29e7 12 nRF51822n nrf;
cristea 3:4cb285fb29e7 13 DigitalOut led1(p1);
cristea 3:4cb285fb29e7 14 DigitalOut advertisiingStateLed(p30);
cristea 2:67d603617000 15
cristea 3:4cb285fb29e7 16 GapAdvertisingData advData;
cristea 3:4cb285fb29e7 17 GapAdvertisingData scanResponse;
cristea 3:4cb285fb29e7 18 GapAdvertisingParams advParams(GapAdvertisingOParams::ADV_CONNECTABLE_UNDIRECTED);
cristea 0:f4fbeaabdff5 19
cristea 3:4cb285fb29e7 20 class GapEventHandler : public GapEvents {
cristea 3:4cb285fb29e7 21 virtual void onConnected(void) {
cristea 3:4cb285fb29e7 22 advertisingStateLed = 0;
cristea 3:4cb285fb29e7 23 LOG("Connected!\n\r");
cristea 3:4cb285fb29e7 24 }
cristea 2:67d603617000 25
cristea 3:4cb285fb29e7 26 virtual void onDisconnected(void) {
cristea 3:4cb285fb29e7 27 nrf.getGap().startAdvertising(advParams);
cristea 3:4cb285fb29e7 28 advertisingStateLed = 1;
cristea 3:4cb285fb29e7 29 LOG("Disconnected!\n\r");
cristea 3:4cb285fb29e7 30 LOG("Restarting the advertising process\n\r");
cristea 3:4cb285fb29e7 31 }
cristea 0:f4fbeaabdff5 32 }
cristea 0:f4fbeaabdff5 33
cristea 0:f4fbeaabdff5 34 int main() {
cristea 3:4cb285fb29e7 35 nrf.getGap().setEventHandler(new GapEventHandler());
cristea 3:4cb285fb29e7 36
cristea 3:4cb285fb29e7 37 nrf.init();
cristea 3:4cb285fb29e7 38 nrf.reset();
cristea 3:4cb285fb29e7 39
cristea 3:4cb285fb29e7 40 advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
cristea 3:4cb285fb29e7 41 advData.addData(GapAdvertisingData::SHORTENED_LOCAL_NAME,
cristea 3:4cb285fb29e7 42 (uint8_t*)"phlemz", sizeof("phlemz") - 1);
cristea 3:4cb285fb29e7 43 advData.addAppearance(GapAdvertisingData::UNKNOWN);
cristea 3:4cb285fb29e7 44 nrf.getGap().setAdvertisingData(advData. scanResponse);
cristea 3:4cb285fb29e7 45
cristea 3:4cb285fb29e7 46 nrf.getGap().startAdvertising(advParams);
cristea 3:4cb285fb29e7 47
cristea 3:4cb285fb29e7 48 for(;;) {
cristea 3:4cb285fb29e7 49 led1 = !led1;
cristea 3:4cb285fb29e7 50 wait(1);
cristea 0:f4fbeaabdff5 51 }
cristea 1:345039810771 52 }