This is a program that turns your mbed device into a FireFly gateway, that publishes data from FireFly BLE modules to the IBM Watson IoT Platform.

Dependencies:   C12832 EthernetInterface MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Files at this revision

API Documentation at this revision

Comitter:
skoda
Date:
Fri Mar 04 09:14:23 2016 +0000
Parent:
25:93368e752d2d
Child:
27:9727cdb5fa65
Commit message:
final version before release

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 04 07:22:09 2016 +0000
+++ b/main.cpp	Fri Mar 04 09:14:23 2016 +0000
@@ -31,12 +31,18 @@
 
 // Update this to the next number *before* a commit
 #define __APP_SW_REVISION__ "18"
-
+/*
 // Configuration values needed to connect to IBM IoT Cloud
 #define ORG "gpr4zb"             // For a registered connection, replace with your org
 #define ID "FFtesting"                        // For a registered connection, replace with your id
 #define AUTH_TOKEN "123456789"                // For a registered connection, replace with your auth-token
-#define TYPE "FireFly"       // For a registered connection, replace with your type
+#define TYPE "FireFly"       // For a registered connection, replace with your type */
+
+// Configuration values needed to connect to IBM IoT Cloud
+#define ORG "quickstart"             // For a registered connection, replace with your org
+#define ID ""                        // For a registered connection, replace with your id
+#define AUTH_TOKEN ""                // For a registered connection, replace with your auth-token
+#define TYPE DEFAULT_TYPE_NAME       // For a registered connection, replace with your type
 
 #define MQTT_PORT 1883
 #define MQTT_TLS_PORT 8883
@@ -93,6 +99,8 @@
 int indexBufWrite = 0;
 int indexBufRead = 0;
 char IoTbuffer[BUFFER_SIZE][DATA_LENGTH];
+
+int index = 0;
 const int SerialMessageLength = 170;
 char data[SerialMessageLength];
 
@@ -423,10 +431,10 @@
     message.qos = MQTT::QOS0; // set the quality of service you want for outgoing messages
     message.retained = false;
     message.dup = false;
-    message.payload = (void*)buf;
-    message.payloadlen = strlen(buf);
+    message.payload = (void*)data;
+    message.payloadlen = strlen(data);
     
-    LOG("Publishing %s\n", buf);
+    LOG("Publishing %s\n", data);
     return client->publish(pubTopic, message);
 }
 
@@ -498,10 +506,33 @@
 
 void callback() {
     // Note: you need to actually read from the serial to clear the RX interrupt
-    char c = xbee.getc();
+    /*char c = xbee.getc();
     pc.putc(c);
     if(c == '?')
-    pc.printf("\r");
+    pc.printf("\r");*/
+    
+    if(index < SerialMessageLength){
+        data[index] = xbee.getc();
+        //pc.print(data[index]);
+        if(index == 0){
+          if(data[index] == '!'){
+            data[index] = ' ';
+            index++;
+          }
+        }else{
+          if(data[index] == '?'){
+            data[index] = '\0';
+            index = 0;
+            //if(data[index]>3)
+            //if(data[index--] == '}'  && data[index-2] == '}' )
+            respond = true;
+          }else{
+            index++;
+          }
+        }
+    }else{
+        index = 0;
+    }
 
 }