A simple program that uses the UARTService to transfer string data over GATT. Can be used with the nRF Toolbox app for rapid prototyping.

Dependencies:   BLE_API mbed nRF51822

Fork of UART_TEMPLATE by daniel veilleux

Files at this revision

API Documentation at this revision

Comitter:
VicenteFerrara
Date:
Wed Jun 21 01:33:50 2017 +0000
Parent:
0:442c7a6f1978
Commit message:
Leer caracter?stica y responder en base a ello

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 442c7a6f1978 -r 32c6991f7180 main.cpp
--- a/main.cpp	Mon Dec 15 21:05:18 2014 -0800
+++ b/main.cpp	Wed Jun 21 01:33:50 2017 +0000
@@ -23,16 +23,17 @@
 #define SENSOR_READ_INTERVAL_S  (0.5F) 
 #define ADV_INTERVAL_MS         (1000UL)
 #define UART_BAUD_RATE          (19200UL)
-#define DEVICE_NAME             ("DEMO SENSOR") // This can be read AFTER connecting to the device.
-#define SHORT_NAME              ("HACKDEMO")    // Keep this short: max 8 chars if a 128bit UUID is also advertised.
+#define DEVICE_NAME             ("EVA") // This can be read AFTER connecting to the device.
+#define SHORT_NAME              ("EVA")    // Keep this short: max 8 chars if a 128bit UUID is also advertised.
 
 #define DEBUG(...)              { m_serial_port.printf(__VA_ARGS__); }
 
+//static const char     DEVICE_NAME[]        = "EVA";
 
 BLEDevice   m_ble;
 Serial      m_serial_port(p9, p11);  // TX pin, RX pin
-DigitalOut  m_cmd_led(LED1);
-DigitalOut  m_error_led(LED2);
+Serial pc(USBTX, USBRX); // tx, rx
+DigitalOut led1(LED1);
 AnalogIn    m_analog_in(p1);
 uint16_t    m_analog_in_value;
 UARTService *m_uart_service_ptr;
@@ -68,17 +69,24 @@
     // Ensure that initialization is finished and the host has written to the TX characteristic.
     if ((m_uart_service_ptr != NULL) && (params->charHandle == m_uart_service_ptr->getTXCharacteristicHandle())) {
         uint8_t  buf[MAX_REPLY_LEN];
+        uint8_t buf2[3]= {0xFF, 0x01, 0x02};
         uint32_t len = 0;
-
+        
         if (1 == params->len) {
             switch (params->data[0]) {
             case '0':
-                m_cmd_led = 0;
                 len = snprintf((char*) buf, MAX_REPLY_LEN, "OK");
+                pc.printf("Si llego prro\n");
                 break;
-            case '1':
-                m_cmd_led = 1;
-                len = snprintf((char*) buf, MAX_REPLY_LEN, "OK");
+            case 1:
+             led1 = 1;
+                wait(1.0);
+                led1 = 0;
+                wait(1.0);
+                led1 = 1;
+                wait(1.0);
+                led1 = 0;
+                len = snprintf((char*) buf, MAX_REPLY_LEN, "prrow");
                 break;
             case 'a':
                 len = snprintf((char*) buf, MAX_REPLY_LEN, "%d", m_analog_in_value);
@@ -92,8 +100,8 @@
         {
             len = snprintf((char*) buf, MAX_REPLY_LEN, "ERROR: Invalid len");
         }
-
-        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        //m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf2, 3);
 
         DEBUG("%d bytes received from host\n\r", params->len);
     }
@@ -121,7 +129,7 @@
 
 void error(ble_error_t err, uint32_t line)
 {
-    m_error_led = 1;
+    //m_error_led = 1;
     DEBUG("Error %d on line number %d\n\r", err, line);
 }
 
@@ -135,8 +143,7 @@
 
     DEBUG("Initialising\n\r");
 
-    m_cmd_led      = 0;
-    m_error_led    = 0;
+    led1      = 0;
     m_analog_in_value    = 0;
 
     ticker.attach(periodicCallback, SENSOR_READ_INTERVAL_S);