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

Revision:
27:9727cdb5fa65
Parent:
26:65808ea318a3
--- a/main.cpp	Fri Mar 04 09:14:23 2016 +0000
+++ b/main.cpp	Wed Mar 30 07:05:50 2016 +0000
@@ -6,7 +6,7 @@
  * and Eclipse Distribution License v1.0 which accompany this distribution.
  *
  * The Eclipse Public License is available at
- *    http://www.eclipse.org/legal/epl-v10.html
+ *   http://www.eclipse.org/legal/epl-v10.html
  * and the Eclipse Distribution License is available at
  *   http://www.eclipse.org/org/documents/edl-v10.php.
  *
@@ -21,8 +21,6 @@
  *
  *******************************************************************************/
 #include "mbed.h"
-#include "LM75B.h"
-#include "MMA7660.h"
 #include "MQTTClient.h"
 #include "MQTTEthernet.h"
 #include "C12832.h"
@@ -31,24 +29,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 */
 
 // 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 ORG "quickstart"             // For a registered connection, replace with your organisation id
+#define ID ""                        // For a registered connection, replace with your device id
+#define AUTH_TOKEN ""                // For a registered connection, replace with your device auth-token
+#define TYPE DEFAULT_TYPE_NAME       // For a registered connection, replace with your device type
 
 #define MQTT_PORT 1883
 #define MQTT_TLS_PORT 8883
 #define IBM_IOT_PORT MQTT_PORT
 
-#define MQTT_MAX_PACKET_SIZE 250
+#define MQTT_MAX_PACKET_SIZE 250 //max packet size that will be successfully sent using MQTT
 
 #if defined(TARGET_UBLOX_C027)
 #warning "Compiling for mbed C027"
@@ -373,6 +365,7 @@
         displayMessage("Connected");
         wait(1);
         displayMessage("Scroll with joystick");
+        xbee.puts("\nCON61xx\r");
     }
     else
         WARN("MQTT connect returned %d\n", rc);
@@ -488,8 +481,24 @@
           
           int msgLen = 0;
           for (int i=8;i<message.payloadlen-2;i++) { //reading only the command from the payload
-            xbee.putc((char)payload[i]);
-            pc.putc((char)payload[i]);
+
+            if(i != 12){
+              xbee.putc((char)payload[i]);
+              pc.putc((char)payload[i]);
+            }else{ //12th character cause we have deviceID 3bytes long and 4th byte is command
+              if((char)payload[i-1] == '4' || (char)payload[i-1] == '3'){
+                if(payload[i] == 126){
+                  xbee.putc(';');
+                  pc.putc(';');
+                }else{
+                  xbee.putc((char)(payload[i]-33));
+                  pc.putc((char)(payload[i]-33));
+                }  
+              }else{
+                xbee.putc((char)payload[i]);
+                pc.putc((char)payload[i]);
+              }
+            }
             msgLen++;
           }
           
@@ -506,10 +515,6 @@
 
 void callback() {
     // Note: you need to actually read from the serial to clear the RX interrupt
-    /*char c = xbee.getc();
-    pc.putc(c);
-    if(c == '?')
-    pc.printf("\r");*/
     
     if(index < SerialMessageLength){
         data[index] = xbee.getc();
@@ -523,9 +528,10 @@
           if(data[index] == '?'){
             data[index] = '\0';
             index = 0;
-            //if(data[index]>3)
-            //if(data[index--] == '}'  && data[index-2] == '}' )
             respond = true;
+          }else if(data[index] == '!'){
+            data[0] == ' ';
+            index=1;
           }else{
             index++;
           }
@@ -546,15 +552,17 @@
     
     led2 = LED2_OFF; // K64F: turn off the main board LED 
     
+    wait(2);
     xbee.baud(38400);
-    pc.baud(115200);
+    pc.baud(38400);
     xbee.puts("\nRDYxxxx\r");
-    wait(5);
+    wait(7);
     xbee.puts("\nRDYxxxx\r");
     pc.printf("i sent RDY to FireFly\r\n");
     
     displayMessage("Connecting");
     Thread yellow_thread(flashing_yellow);
+    xbee.puts("\nCON60xx\r");
     Thread menu_thread(menu_loop);    
     
     LOG("***** IBM IoT Client Ethernet Example *****\n");