
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
Revision 27:9727cdb5fa65, committed 2016-03-30
- Comitter:
- skoda
- Date:
- Wed Mar 30 07:05:50 2016 +0000
- Parent:
- 26:65808ea318a3
- Child:
- 28:4dfb80ba55f7
- Commit message:
- FireFly mbed first release v1.0
Changed in this revision
--- a/C027.h Fri Mar 04 09:14:23 2016 +0000 +++ b/C027.h Wed Mar 30 07:05:50 2016 +0000 @@ -22,10 +22,9 @@ PwmOut g(D9); PwmOut b(D8); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); -MMA7660 MMA(D14, D15); -LM75B sensor(D14,D15); DigitalIn Up(A2); DigitalIn Down(A3); DigitalIn Left(A4); DigitalIn Right(A5); DigitalIn Click(D4); AnalogIn ain1 (A0); AnalogIn ain2 (A1); + RawSerial pc(USBTX, USBRX); RawSerial xbee(P4_28,P4_29);
--- a/K64F.h Fri Mar 04 09:14:23 2016 +0000 +++ b/K64F.h Wed Mar 30 07:05:50 2016 +0000 @@ -23,20 +23,12 @@ BusOut r (D5); BusOut g (D9); BusOut b (D8); -//MMA7660 MMA(PTE25, PTE24); //matjaz: ne uporablam !!! -//LM75B sensor(PTE25, PTE24); DigitalIn Up(A2); DigitalIn Down(A3); DigitalIn Right(A4); DigitalIn Left(A5); DigitalIn Click(D4); AnalogIn ain1(A0); AnalogIn ain2(A1); -//Matjaz -//I2C masterI2C(PTE25,PTE24); //I2C (PinName sda, PinName scl) -//I2CSlave slave(PTE25, PTE24); RawSerial pc(USBTX, USBRX); RawSerial xbee(PTC17,PTC16); - - - #define LED2_OFF 1 #define LED2_ON 0
--- a/LM75B.lib Fri Mar 04 09:14:23 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac
--- a/LPC1768.h Fri Mar 04 09:14:23 2016 +0000 +++ b/LPC1768.h Wed Mar 30 07:05:50 2016 +0000 @@ -23,8 +23,6 @@ PwmOut r(p23); PwmOut g(p24); PwmOut b(p25); -//MMA7660 MMA(p28, p27); -//LM75B sensor(p28, p27); DigitalIn Down(p12); DigitalIn Left(p13); DigitalIn Click(p14); @@ -32,12 +30,9 @@ DigitalIn Right(p16); AnalogIn ain1(p19); AnalogIn ain2(p20); -//Matjaz -//I2CSlave slave(p28, p27); //p9sda p10scl -//I2CSlave slave(p9, p10); + RawSerial pc(USBTX, USBRX); RawSerial xbee(p9,p10); -//Serial xbee(p13,p14); #define LED2_OFF 0 #define LED2_ON 1
--- a/MMA7660.lib Fri Mar 04 09:14:23 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/Sissors/code/MMA7660/#36a163511e34
--- 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");
--- a/mbed.bld Fri Mar 04 09:14:23 2016 +0000 +++ b/mbed.bld Wed Mar 30 07:05:50 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/c0f6e94411f5 \ No newline at end of file