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:
Tue Dec 15 09:37:25 2015 +0000
Parent:
22:e6b69714b59a
Commit message:
potentially problematic code for i2c

Changed in this revision

K64F.h Show annotated file Show diff for this revision Revisions of this file
LPC1768.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/K64F.h	Mon Nov 30 09:12:22 2015 +0000
+++ b/K64F.h	Tue Dec 15 09:37:25 2015 +0000
@@ -31,6 +31,7 @@
 //Matjaz
 //I2C masterI2C(PTE25,PTE24);        //I2C (PinName sda, PinName scl) 
 I2CSlave slave(PTE25, PTE24);
+//I2CSlave slave(PTC16, PTC17);
 
 
 
--- a/LPC1768.h	Mon Nov 30 09:12:22 2015 +0000
+++ b/LPC1768.h	Tue Dec 15 09:37:25 2015 +0000
@@ -33,8 +33,8 @@
 AnalogIn ain1(p19);
 AnalogIn ain2(p20);
 //Matjaz
-//I2CSlave slave(p28, p27); //p9sda p10scl
-I2CSlave slave(p9, p10);
+I2CSlave slave(p28, p27); //p9sda p10scl
+//I2CSlave slave(p9, p10);
 
 #define LED2_OFF 0
 #define LED2_ON 1
@@ -47,5 +47,4 @@
 {
     return (lpc_mii_read_data() & 1);
 }
-
 #endif
\ No newline at end of file
--- 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 ..    
-        
-    }
-*/    
+    
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-src.lib	Tue Dec 15 09:37:25 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-src/#a11c0372f0ba
--- a/mbed.bld	Mon Nov 30 09:12:22 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5
\ No newline at end of file