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:
23:03835082a0de
Parent:
22:e6b69714b59a
--- a/main.cpp	Mon Nov 30 09:12:22 2015 +0000
+++ b/main.cpp	Tue Dec 15 09:37:25 2015 +0000
@@ -35,8 +35,8 @@
 #define __APP_SW_REVISION__ "18"
 
 // Configuration values needed to connect to IBM IoT Cloud
-#define ORG "jfzeoz"             // For a registered connection, replace with your org
-#define ID "mbedGateway"                        // For a registered connection, replace with your id
+#define ORG "gpr4zb"             // For a registered connection, replace with your org
+#define ID "FFgateway"                        // 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
 
@@ -92,6 +92,7 @@
 int16_t     deviceID = 0;
 const int BUFFER_SIZE = 30;
 const int DATA_LENGTH = 20;
+
 int indexBufWrite = 0;
 int indexBufRead = 0;
 char IoTbuffer[BUFFER_SIZE][DATA_LENGTH];
@@ -187,7 +188,7 @@
 
     
 
-    LOG("Slave here i am ready to punish me\r\n");
+    LOG("Slave thread initiated!\r\n");
     
 /*    
     while(1){
@@ -207,7 +208,10 @@
          DELETE++;
          /*if(i>0)
             LOG("i: %d\r\n",i);*/
-            
+        //TRY to reset i2c if there is no receive>0 for a longer period of time
+        //set slave to master sent stop signal and set it back to slave mode
+        //TRY ALSO set LPC as master and FRDM as slave and scan all addresses on LPC to see how many devices you can find
+        //if FRDM isnt on the spectre
          switch (i) 
          {
              case I2CSlave::ReadAddressed:
@@ -255,9 +259,9 @@
                  respond = 1;
                  //rh   = ((uint16_t)buf[4] << 8) | buf[5];
                  
-                 if(deviceID == 12){
+                 /*if(deviceID == 12){
                     respond = 0;
-                }
+                }*/
 
                  //LOG("Slave read 0x:%d\r\n", lux);
                  //LOG("Slave read 0x:%x%x%x%x\r\n", buf[0],buf[1],buf[2],buf[3]);
@@ -266,7 +270,8 @@
                  break;
                  
          } // switch .. 
-         //Thread::wait(1);   
+         //Thread::wait(1);
+         slave.write(IoTbuffer[0],20);
         
     }
 
@@ -617,7 +622,7 @@
             *pos = '\0';
             if ((pos = strchr(payload, ':')) != NULL)
             {
-                response = (pos+1);
+                response = (pos+2); // CHANGED +2 instead of +1 due to " at the start of the message
                 
                 strcpy(IoTbuffer[indexBufWrite], response);
                 //LOG("%d sporocilo v bufferju: %s size of IoTbuffer: %d \r\n", indexBufWrite, IoTbuffer[indexBufWrite], response);
@@ -679,13 +684,13 @@
     }
     
     blink_interval = 0;
-    int count = 0;
+    //int count = 0;
 
     pc.baud(115200);
     while (true)
     {
         if (respond>0)
-        {               // Publish a message every second
+        {               // Publish a message when you get data over i2c
             if (publish(&client, &ipstack) != 0) 
                 attemptConnect(&client, &ipstack);   // if we have lost the connection
             respond = 0;
@@ -698,44 +703,5 @@
             
         client.yield(10);  // allow the MQTT client to receive messages
     }
-
-
-/*
-    while(1){
-         static int i;
-         static char buf[20];
-         uint16_t lux;
-         
-         i = slave.receive();
-         
-         if(i>0)
-            LOG("i: %d\r\n",i);
-            
-         switch (i) 
-         {
-             case I2CSlave::ReadAddressed:
-                                      
-                 slave.write(buf,2);                 
-                 LOG("Slave send mesage0x%x\r\n",buf[0]);                              
-                 break;
-                 
-             case I2CSlave::WriteGeneral:
-             
-                 slave.read(buf, 10);
-                 LOG("Napacen case\r\n");
-                 break;
-                 
-             case I2CSlave::WriteAddressed:
-             
-                 slave.read(buf, 19);
-                 lux = ((uint16_t)buf[0] << 8) | buf[1];
-
-                 LOG("Slave read 0x:%d\r\n", lux);
-
-                 break;
-                 
-         } // switch ..    
-        
-    }
-*/    
+    
 }