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:
14:9eda2d99fc1d
Parent:
13:93d3574e9e36
Child:
15:bfc682889c15
--- a/Puck.h	Mon Aug 11 09:42:01 2014 +0000
+++ b/Puck.h	Mon Feb 23 15:25:22 2015 +0000
@@ -19,8 +19,9 @@
 #define __PUCK_HPP__
  
 #include "BLEDevice.h"
+#include "mbed.h"
+#include "Log.h"
 #include <vector>
-#include "Log.h"
 
 enum PuckState {
     CONNECTING,
@@ -82,18 +83,21 @@
     return _puckSingletonInstance;
 }
 
-void onDisconnection(Gap::Handle_t handle) {
+void onDisconnection(Gap::Handle_t handle, Gap::DisconnectionReason_t disconnectReason) {
     LOG_INFO("Disconnected.\n");
     Puck::getPuck().setState(DISCONNECTED);
 }
 
-void onConnection(Gap::Handle_t handle) {
+void onConnection(Gap::Handle_t handle,
+        Gap::addr_type_t peerAddrType,
+        const Gap::address_t peerAddr,
+        const Gap::ConnectionParams_t * connectionParams) {
     LOG_INFO("Connected.\n");
     Puck::getPuck().setState(CONNECTED);
 }
 
-void onDataWrittenCallback(uint16_t handle) {
-    Puck::getPuck().onDataWritten(handle);
+void onDataWrittenCallback(const GattCharacteristicWriteCBParams *context) {
+    Puck::getPuck().onDataWritten(context->charHandle);
 }
 
 bool isEqualUUID(const UUID* uuidA, const UUID uuidB) {
@@ -120,7 +124,7 @@
 }
 
 void Puck::disconnect() {
-    ble.disconnect();    
+    ble.disconnect(Gap::LOCAL_HOST_TERMINATED_CONNECTION);    
 }
 
 int Puck::countFreeMemory() {
@@ -271,17 +275,17 @@
     LOG_DEBUG("Added characteristic.\n");
 }
 
-
 void Puck::updateCharacteristicValue(const UUID uuid, uint8_t* value, int length) {
     GattCharacteristic* characteristic = NULL;
-    for( int i = 0; i < characteristics.size(); i++) {
-        if(isEqualUUID(&characteristics[i]->getUUID(), uuid)) {
+    for(int i = 0; i < characteristics.size(); i++) {
+        GattAttribute &gattAttribute = characteristics[i]->getValueAttribute();
+        if(isEqualUUID(&gattAttribute.getUUID(), uuid)) {
             characteristic = characteristics[i];
-            break;    
-        }    
+            break;
+        }
     }
     if(characteristic != NULL) {
-        ble.updateCharacteristicValue(characteristic->getHandle(), value, length);
+        ble.updateCharacteristicValue(characteristic->getValueHandle(), value, length);
         LOG_VERBOSE("Updated characteristic value.\n");
     } else {
         LOG_WARN("Tried to update an unkown characteristic!\n");    
@@ -289,10 +293,12 @@
 }
 
 bool Puck::drive() {
+    if(state == DISCONNECTED) {
+        startAdvertising();
+    }
+
     ble.waitForEvent();
-    if(state == DISCONNECTED) {
-        startAdvertising();    
-    }
+
     while(pendingCallbackStack.size() > 0) {
         pendingCallbackStack.back()(pendingCallbackParameterStack.back());
         pendingCallbackStack.pop_back();
@@ -327,9 +333,9 @@
 uint8_t* Puck::getCharacteristicValue(const UUID uuid) {
     LOG_VERBOSE("Reading characteristic value for UUID %x\n", uuid);
     for(int i = 0; i < characteristics.size(); i++) {
-        GattCharacteristic* characteristic = characteristics[i];
-        if(isEqualUUID(&characteristic->getUUID(), uuid)) {
-            return characteristic->getValuePtr();
+        GattAttribute &gattAttribute = characteristics[i]->getValueAttribute();
+        if(isEqualUUID(&gattAttribute.getUUID(), uuid)) {
+            return gattAttribute.getValuePtr();
         }
     }
     LOG_WARN("Tried to read an unknown characteristic!");
@@ -340,15 +346,17 @@
 void Puck::onDataWritten(uint16_t handle) {
     for (int i = 0; i < characteristics.size(); i++) {
         GattCharacteristic* characteristic = characteristics[i];
-        if (characteristic->getHandle() == handle) {
-            uint16_t maxLength = characteristic->getMaxLength();
-            ble.readCharacteristicValue(handle, characteristic->getValuePtr(), &maxLength);
+        
+        if (characteristic->getValueHandle() == handle) {
+            GattAttribute &gattAttribute = characteristic->getValueAttribute();
+
             for(int j = 0; j < writeCallbacks.size(); j++) {    
                 CharacteristicWriteCallbacks* characteristicWriteCallbacks = writeCallbacks[j];
-                if(isEqualUUID(characteristicWriteCallbacks->uuid, characteristic->getUUID())) {
+
+                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(characteristic->getValuePtr());
+                        pendingCallbackParameterStack.push_back(gattAttribute.getValuePtr());
                     }
                     return;
                 }
@@ -358,5 +366,4 @@
 }
 
 
-
  #endif // __PUCK_HPP__
\ No newline at end of file