A library for easier setup and prototyping of IoT devices (pucks), by collecting everything that is common for all pucks in one place.

Dependencies:   BLE_API nRF51822

Dependents:   ir-puck display-puck ir-puck2 BLE_ScoringDevice ... more

/media/uploads/stiaje/header.jpg

Introduction

Raspberry Pi took the maker community by storm when it launched in 2012. With its internet access it allowed small projects to be internet-of-things enabled. We have created a platform to take this one step further.

Our platform, called the Puck platform, is an internet of things platform for mbed. mbed makes it easy to program embedded hardware for people new to embedded systems. Our platform is built upon the first mbed chip with Bluetooth, the nRF51822 created by Nordic Semiconductor. We hope to create a community around these BLE devices where people contribute to the project, and share their designs with each other. Everything is open-source, of course, with lots of supporting materials.

We make it easy to rapidly prototype and develop Bluetooth LE enabled devices - get up and running in under 10 lines of code.

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

Pucks

We've developed a handful of awesome examples to demonstrate the platform. These examples are named 'Pucks'. By talking to the internet through your smartphone, the barrier to creating your own Internet of Things device is lower than ever.

Revision:
15:bfc682889c15
Parent:
14:9eda2d99fc1d
Child:
18:4c95a470d778
--- a/Puck.h	Mon Feb 23 15:25:22 2015 +0000
+++ b/Puck.h	Fri Feb 27 17:31:47 2015 +0000
@@ -32,7 +32,7 @@
 
 const UUID stringToUUID(const char* str);
 
-typedef void (*CharacteristicWriteCallback)(uint8_t* value);
+typedef void (*CharacteristicWriteCallback)(const uint8_t* value, uint8_t length);
  
  typedef struct {
      const UUID* uuid;
@@ -53,7 +53,8 @@
         std::vector<GattCharacteristic*> characteristics;
         std::vector<CharacteristicWriteCallbacks*> writeCallbacks;
         std::vector<CharacteristicWriteCallback> pendingCallbackStack;
-        std::vector<uint8_t*> pendingCallbackParameterStack;
+        std::vector<const uint8_t*> pendingCallbackParameterDataStack;
+        std::vector<uint8_t> pendingCallbackParameterLengthStack;
         
         GattCharacteristic **previousCharacteristics;
         
@@ -69,7 +70,7 @@
         void disconnect();
         bool drive();
         int countFreeMemory();
-        void onDataWritten(uint16_t handle);
+        void onDataWritten(GattAttribute::Handle_t handle, const uint8_t* data, const uint8_t length);
         void addCharacteristic(const UUID serviceUuid, const UUID characteristicUuid, int bytes, int properties = 0xA);
 
         void onCharacteristicWrite(const UUID* uuid, CharacteristicWriteCallback callback);
@@ -97,7 +98,7 @@
 }
 
 void onDataWrittenCallback(const GattCharacteristicWriteCBParams *context) {
-    Puck::getPuck().onDataWritten(context->charHandle);
+    Puck::getPuck().onDataWritten(context->charHandle, context->data, context->len);
 }
 
 bool isEqualUUID(const UUID* uuidA, const UUID uuidB) {
@@ -300,9 +301,10 @@
     ble.waitForEvent();
 
     while(pendingCallbackStack.size() > 0) {
-        pendingCallbackStack.back()(pendingCallbackParameterStack.back());
+        pendingCallbackStack.back()(pendingCallbackParameterDataStack.back(), pendingCallbackParameterLengthStack.back());
         pendingCallbackStack.pop_back();
-        pendingCallbackParameterStack.pop_back();
+        pendingCallbackParameterDataStack.pop_back();
+        pendingCallbackParameterLengthStack.pop_back();
     }
     return true;
 }
@@ -343,7 +345,7 @@
 }
 
 
-void Puck::onDataWritten(uint16_t handle) {
+void Puck::onDataWritten(GattAttribute::Handle_t handle, const uint8_t* data, uint8_t length) {
     for (int i = 0; i < characteristics.size(); i++) {
         GattCharacteristic* characteristic = characteristics[i];
         
@@ -356,7 +358,9 @@
                 if(isEqualUUID(characteristicWriteCallbacks->uuid, gattAttribute.getUUID())) {
                     for(int k = 0; k < characteristicWriteCallbacks->callbacks->size(); k++) {
                         pendingCallbackStack.push_back(characteristicWriteCallbacks->callbacks->at(k));
-                        pendingCallbackParameterStack.push_back(gattAttribute.getValuePtr());
+                        
+                        pendingCallbackParameterDataStack.push_back(data);
+                        pendingCallbackParameterLengthStack.push_back(length);
                     }
                     return;
                 }