Demo starter application to connect WiGo to NSP and expose on-board sensors

Dependencies:   NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed nsdl_lib TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger

This is the mbed project for the IoT World Hackathon event, June 17th and 18th in Palo Also.

The setup instructions for participants are at the Setup page of this wiki:

http://mbed.org/teams/MBED_DEMOS/code/IoT_World_Hackathon_WiGo_NSP_Demo/wiki/Setup-Guide-for-the-IoT-World-Hackathon

Files at this revision

API Documentation at this revision

Comitter:
michaeljkoster
Date:
Fri Jun 13 18:00:38 2014 +0000
Child:
1:8f4625466fbd
Commit message:
Initial files

Changed in this revision

I2C_busreset/I2C_busreset.cpp Show annotated file Show diff for this revision Revisions of this file
I2C_busreset/I2C_busreset.h Show annotated file Show diff for this revision Revisions of this file
NVIC_set_all_priorities.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/MAG3110/MAG3110.cpp Show annotated file Show diff for this revision Revisions of this file
Sensors/MAG3110/MAG3110.h Show annotated file Show diff for this revision Revisions of this file
Sensors/MMA8451Q/MMA8451Q.cpp Show annotated file Show diff for this revision Revisions of this file
Sensors/MMA8451Q/MMA8451Q.h Show annotated file Show diff for this revision Revisions of this file
Sensors/MPL3115A2/MPL3115A2.cpp Show annotated file Show diff for this revision Revisions of this file
Sensors/MPL3115A2/MPL3115A2.h Show annotated file Show diff for this revision Revisions of this file
Sensors/TEMT6200.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/TSI.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/Wi-Go_eCompass_Lib_V3.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/WiGo_BattCharger.lib Show annotated file Show diff for this revision Revisions of this file
Utilities/strlib.cpp Show annotated file Show diff for this revision Revisions of this file
Utilities/strlib.h Show annotated file Show diff for this revision Revisions of this file
Webserver/AvnetHTML.h Show annotated file Show diff for this revision Revisions of this file
Webserver/demo.cpp Show annotated file Show diff for this revision Revisions of this file
Webserver/demo.h Show annotated file Show diff for this revision Revisions of this file
Webserver/doTCPIP.cpp Show annotated file Show diff for this revision Revisions of this file
Webserver/doTCPIP.h Show annotated file Show diff for this revision Revisions of this file
Webserver/run_exosite.cpp Show annotated file Show diff for this revision Revisions of this file
Webserver/run_exosite.h Show annotated file Show diff for this revision Revisions of this file
cc3000_hostdriver_mbedsocket.lib Show annotated file Show diff for this revision Revisions of this file
dbg.h Show annotated file Show diff for this revision Revisions of this file
defLED.h Show annotated file Show diff for this revision Revisions of this file
init.cpp 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
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nanoservice_client_1_12.lib Show annotated file Show diff for this revision Revisions of this file
nsdl_run.cpp Show annotated file Show diff for this revision Revisions of this file
nsdl_support.cpp Show annotated file Show diff for this revision Revisions of this file
nsdl_support.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2C_busreset/I2C_busreset.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,58 @@
+/**************************************************************************************************
+ *****                                                                                        *****
+ *****  Name: KL25Z I2C_busreset.cpp                                                          *****
+ *****  Date: 24/11/2013                                                                      *****
+ *****  Auth: Frank Vannieuwkerke                                                             *****
+ *****  Func: library for unblocking I2C bus on KL25Z board                                   *****
+ *****  Info: MPL3115A2-AN4481                                                                *****
+ **************************************************************************************************/
+
+#include "I2C_busreset.h"
+
+void I2C_busreset(void)
+{
+    I2C0->C1 &= 0x7f;                 // Disable I2C0 bus
+    I2C1->C1 &= 0x7f;                 // Disable I2C1 bus
+    PORTE->PCR[1] = PORT_PCR_MUX(1);  // PTE1 Alt1 (pin)
+    PORTE->PCR[0] = PORT_PCR_MUX(1);  // PTE0 Alt1 (pin)
+    PORTE->PCR[24] = PORT_PCR_MUX(1); // PTE24 Alt1 (pin)
+    PORTE->PCR[25] = PORT_PCR_MUX(1); // PTE25 Alt1 (pin)
+    if((PTE->PDIR & 0x3) != 3)        // When PTE0 / PTE1 are not 1 : I2C1 bus lock-up
+    {
+        PTE->PDDR |= 0x2;             // Set PTE1 as a GPIO output so we can bit bang it
+        PTE->PDOR |= 0x2;             // Set PTE1 (SCL) pin high;
+        wait_ms(1);
+        while(!(PTE->PDIR & 0x1))     // bit bang SCL until the offending device releases the bus
+        {   
+            PTE->PDOR &= 0xfffffffd;  // Set PTE1 (SCL) pin low;
+            wait_ms(1);
+            PTE->PDOR |= 0x2;         // Set PTE1 (SCL) pin high;
+            wait_ms(1);
+        }
+    }
+    if((PTE->PDIR & 0x03000000) != 0x03000000)  // When PTE24 / PTE25 are not 1 : I2C0 bus lock-up
+    {
+        PTE->PDDR |= 0x01000000;      // Set PTE24 as a GPIO output so we can bit bang it
+        PTE->PDOR |= 0x01000000;      // Set PTE24 (SCL) pin high;
+        wait_ms(1);
+        while(!(PTE->PDIR & 0x1))     // bit bang SCL until the offending device releases the bus
+        {   
+            PTE->PDOR &= 0xfeffffff;  // Set PTE24 (SCL) pin low;
+            wait_ms(1);
+            PTE->PDOR |= 0x01000000;  // Set PTE24 (SCL) pin high;
+            wait_ms(1);
+        }
+    }
+    // Reinstate I2C bus pins
+    PORTE->PCR[1] = PORT_PCR_MUX(6);  // PTE1 Alt6 (SCL)
+    PORTE->PCR[0] = PORT_PCR_MUX(6);  // PTE0 Alt6 (SDA)
+    PORTE->PCR[24] = PORT_PCR_MUX(5); // PTE24 Alt6 (SCL)
+    PORTE->PCR[25] = PORT_PCR_MUX(5); // PTE25 Alt6 (SDA)
+    I2C0->C1 |= 0x80;                 // Enable I2C0 bus
+    I2C1->C1 |= 0x80;                 // Enable I2C1 bus
+}
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2C_busreset/I2C_busreset.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,17 @@
+/**************************************************************************************************
+ *****                                                                                        *****
+ *****  Name: KL25Z I2C_busreset.h                                                            *****
+ *****  Date: 24/11/2013                                                                      *****
+ *****  Auth: Frank Vannieuwkerke                                                             *****
+ *****  Func: library for unblocking I2C bus on KL25Z board                                   *****
+ *****  Info: MPL3115A2-AN4481                                                                *****
+ **************************************************************************************************/
+
+#include "mbed.h"
+
+#ifndef KL25Z_I2C_RES_H
+#define KL25Z_I2C_RES_H
+ 
+void I2C_busreset(void);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NVIC_set_all_priorities.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#01504ecd2025
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/MAG3110/MAG3110.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,61 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "MAG3110.h"
+
+/******************************************************************************
+ * Constructors
+ ******************************************************************************/
+
+MAG3110::MAG3110(PinName sda, PinName scl, int addr): m_i2c(sda, scl),  m_addr(addr)
+{
+    m_i2c.frequency(375000);
+    unsigned char data[2] = {MAG_CTRL_REG2, MAG_3110_AUTO_MRST_EN};
+    writeRegs(data, 2);
+    data[0] = MAG_CTRL_REG1;
+    data[1] = MAG_3110_ACTIVE;
+    writeRegs(data, 2);
+}
+
+uint8_t MAG3110::isDataAvailable(void)
+{
+    uint8_t status;
+    status = readReg(MAG_DR_STATUS);
+    return (status & 0x07);
+}
+
+void MAG3110::readXYZ(uint8_t * data)
+{
+    char t[1] = {MAG_OUT_X_MSB};
+    m_i2c.write(m_addr, t, 1, true);
+    m_i2c.read(m_addr, (char *)data, 6);
+}
+
+uint8_t MAG3110::readReg(uint8_t addr) {
+    char t[1] = {addr};
+    m_i2c.write(m_addr, t, 1, true);
+    m_i2c.read(m_addr, t, 1);
+    return t[0];
+}
+
+void MAG3110::writeRegs(uint8_t * data, int len) {
+    m_i2c.write(m_addr, (char *)data, len);
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/MAG3110/MAG3110.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,105 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+ 
+#ifndef MAG3110_H
+#define MAG3110_H
+
+#include "mbed.h"
+
+// define registers
+#define MAG_DR_STATUS 0x00
+#define MAG_OUT_X_MSB 0x01
+#define MAG_OUT_X_LSB 0x02
+#define MAG_OUT_Y_MSB 0x03
+#define MAG_OUT_Y_LSB 0x04
+#define MAG_OUT_Z_MSB 0x05
+#define MAG_OUT_Z_LSB 0x06
+#define MAG_WHO_AM_I  0x07
+#define MAG_SYSMOD    0x08
+#define MAG_OFF_X_MSB 0x09
+#define MAG_OFF_X_LSB 0x0A
+#define MAG_OFF_Y_MSB 0x0B
+#define MAG_OFF_Y_LSB 0x0C
+#define MAG_OFF_Z_MSB 0x0D
+#define MAG_OFF_Z_LSB 0x0E
+#define MAG_DIE_TEMP  0x0F
+#define MAG_CTRL_REG1 0x10
+#define MAG_CTRL_REG2 0x11
+
+// Fields in registers
+// CTRL_REG1: dr2,dr1,dr0  os1,os0  fr tm ac
+
+// Sampling rate from 80Hz down to 0.625Hz
+#define MAG_3110_SAMPLE80 0
+#define MAG_3110_SAMPLE40 0x20
+#define MAG_3110_SAMPLE20 0x40
+#define MAG_3110_SAMPLE10 0x60
+#define MAG_3110_SAMPLE5 0x80
+#define MAG_3110_SAMPLE2_5 0xA0
+#define MAG_3110_SAMPLE1_25 0xC0
+#define MAG_3110_SAMPLE0_625 0xE0
+
+// How many samples to average (lowers data rate)
+#define MAG_3110_OVERSAMPLE1 0
+#define MAG_3110_OVERSAMPLE2 0x08
+#define MAG_3110_OVERSAMPLE3 0x10
+#define MAG_3110_OVERSAMPLE4 0x18
+
+// read only 1 byte per axis
+#define MAG_3110_FASTREAD 0x04
+// do one measurement (even if in standby mode)
+#define MAG_3110_TRIGGER 0x02
+// put in active mode
+#define MAG_3110_ACTIVE 0x01
+
+// CTRL_REG2: AUTO_MRST_EN  _ RAW MAG_RST _ _ _ _ _
+// reset sensor after each reading
+#define MAG_3110_AUTO_MRST_EN 0x80
+// don't subtract user offsets
+#define MAG_3110_RAW 0x20
+// reset magnetic sensor after too-large field
+#define MAG_3110_MAG_RST 0x10
+
+// DR_STATUS Register ZYXOW ZOW YOW XOW ZYXDR ZDR YDR XDR
+#define MAG_3110_ZYXDR  0x08
+
+/**
+ * MAG3110 Class to read X/Y/Z data from the magnetometer
+ *
+ */
+class MAG3110
+{
+public:
+    /**
+     * Main constructor
+     * @param sda SDA pin
+     * @param sdl SCL pin
+     * @param addr addr of the I2C peripheral
+     */
+    MAG3110(PinName sda, PinName scl, int addr);
+
+    uint8_t isDataAvailable(void);
+    void readXYZ(uint8_t * data);
+    uint8_t readReg(uint8_t addr);
+    void writeRegs(uint8_t * data, int len);
+
+private:
+    I2C m_i2c;
+    int m_addr;
+};
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/MMA8451Q/MMA8451Q.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,57 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+ 
+#include "MMA8451Q.h"
+ 
+#define REG_STATUS        0x00
+#define REG_CTRL_REG_1    0x2A
+#define REG_OUT_X_MSB     0x01
+#define REG_OUT_Y_MSB     0x03
+#define REG_OUT_Z_MSB     0x05
+ 
+MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+    // activate the peripheral
+    m_i2c.frequency(375000);
+    unsigned char t;
+    t = readReg(REG_CTRL_REG_1);
+    unsigned char data[2] = {REG_CTRL_REG_1, t|0x01};
+    writeRegs(data, 2);
+}
+ 
+uint8_t MMA8451Q::isDataAvailable(void)
+{
+    uint8_t status;
+    status = readReg( REG_STATUS);
+    return (status & 0xf);
+}
+
+uint8_t MMA8451Q::readReg(uint8_t addr) {
+    char t[1] = {addr};
+    m_i2c.write(m_addr, t, 1, true);
+    m_i2c.read(m_addr, t, 1);
+    return t[0];
+}
+
+void MMA8451Q::writeRegs(uint8_t * data, int len) {
+    m_i2c.write(m_addr, (char *)data, len);
+}
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/MMA8451Q/MMA8451Q.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,45 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+ 
+#ifndef MMA8451Q_H
+#define MMA8451Q_H
+ 
+#include "mbed.h"
+ 
+class MMA8451Q
+{
+public:
+    /**
+    * MMA8451Q constructor
+    *
+    * @param sda SDA pin
+    * @param sdl SCL pin
+    * @param addr addr of the I2C peripheral
+    */
+    MMA8451Q(PinName sda, PinName scl, int addr);
+ 
+    uint8_t isDataAvailable( void);
+    uint8_t readReg(uint8_t addr);
+    void writeRegs(uint8_t * data, int len);
+
+private:
+    I2C m_i2c;
+    int m_addr;
+};
+ 
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/MPL3115A2/MPL3115A2.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,89 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+ 
+#include "MPL3115A2.h"
+
+#define REG_WHO_AM_I        0x0C        // return 0xC4 by default
+#define REG_STATUS          0x00
+#define REG_CTRL_REG_1      0x26
+#define REG_CTRL_REG_3      0x28
+#define REG_CTRL_REG_4      0x29
+#define REG_CTRL_REG_5      0x2A
+#define REG_PRESSURE_MSB    0x01        // 3 byte pressure data
+#define REG_ALTIMETER_MSB   0x01        // 3 byte altimeter data
+#define REG_TEMP_MSB        0x04        // 2 byte temperature data
+#define REG_PT_DATA_CFG     0x13
+#define REG_P_TGT_MSB       0x16
+#define REG_P_WND_MSB       0x19
+
+// Status flag for data ready.
+#define PTDR_STATUS       0x03        // Pressure Altitude and Temperature ready
+#define PDR_STATUS        0x02        // Pressure and Altitude data ready
+#define TDR_STATUS        0x01        // Temperature data ready
+
+MPL3115A2::MPL3115A2(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+    unsigned char data[2] = {REG_CTRL_REG_1, 0xB8};
+    m_i2c.frequency(375000);
+    writeRegs(data, 2);
+    data[0] = REG_PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);
+    data[0] = REG_CTRL_REG_1;
+    data[1] = 0xB9;
+    writeRegs(data, 2);
+}
+
+uint8_t MPL3115A2::isDataAvailable( void)
+{
+    unsigned char status;
+    readRegs( REG_STATUS, &status, 1);
+    return ((status>>1) & 0x07);
+    
+}
+
+uint8_t MPL3115A2::getAltimeterRaw( unsigned char *dt)
+{
+    if ( isDataAvailable() & PDR_STATUS)
+    {
+        readRegs( REG_ALTIMETER_MSB, &dt[0], 2);
+        return 1;    
+    }
+    else
+        return 0;
+}
+
+uint8_t MPL3115A2::getTemperatureRaw( unsigned char *dt)
+{
+    if ( isDataAvailable() & TDR_STATUS)
+    {
+        readRegs( REG_TEMP_MSB, &dt[0], 1);
+        return 1;
+    }
+    else
+        return 0;
+}
+
+void MPL3115A2::readRegs(int addr, uint8_t * data, int len) {
+    char t[1] = {addr};
+    m_i2c.write(m_addr, t, 1, true);
+    m_i2c.read(m_addr, (char *)data, len);
+}
+
+void MPL3115A2::writeRegs(uint8_t * data, int len) {
+    m_i2c.write(m_addr, (char *)data, len);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/MPL3115A2/MPL3115A2.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,81 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+ 
+#ifndef MPL3115A2_H
+#define MPL3115A2_H
+
+#include "mbed.h"
+
+// Oversampling value and minimum time between sample
+#define OVERSAMPLE_RATIO_1      0       // 6 ms
+#define OVERSAMPLE_RATIO_2      1       // 10 ms
+#define OVERSAMPLE_RATIO_4      2       // 18 ms
+#define OVERSAMPLE_RATIO_8      3       // 34 ms
+#define OVERSAMPLE_RATIO_16     4       // 66 ms
+#define OVERSAMPLE_RATIO_32     5       // 130 ms
+#define OVERSAMPLE_RATIO_64     6       // 258 ms
+#define OVERSAMPLE_RATIO_128    7       // 512 ms
+
+/* Mode */
+#define ALTIMETER_MODE      1
+#define BAROMETRIC_MODE     2
+
+class MPL3115A2
+{
+public:
+    /**
+    * MPL3115A2 constructor
+    *
+    * @param sda SDA pin
+    * @param sdl SCL pin
+    * @param addr addr of the I2C peripheral
+    */
+    MPL3115A2(PinName sda, PinName scl, int addr);
+    
+    /**
+    * Get the altimeter value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns 1 if data are available, 0 if not.
+    */
+    uint8_t getAltimeterRaw( unsigned char *dt);
+
+    /**
+    * Get the temperature value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns 1 if data are available, 0 if not.
+    */
+    uint8_t getTemperatureRaw( unsigned char *dt);
+    
+    /** 
+    * Return if there are date available
+    * 
+    * @return 0 for no data available, bit0 set for Temp data available, bit1 set for Press/Alti data available
+    *         bit2 set for both Temp and Press/Alti data available
+    */
+    uint8_t isDataAvailable( void);
+
+private:
+    I2C m_i2c;
+    int m_addr;
+    void readRegs(int addr, uint8_t * data, int len);
+    void writeRegs(uint8_t * data, int len);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/TEMT6200.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/TEMT6200/#5d1118cb5702
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/TSI.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/Wi-Go_eCompass_Lib_V3.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/Wi-Go_eCompass_Lib_V3/#c37fee2125c6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/WiGo_BattCharger.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/WiGo_BattCharger/#fb966ae74766
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utilities/strlib.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,193 @@
+/*****************************************************************************
+*
+*  strlib.c - String Library functions implementation
+*  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+*
+*  Redistribution and use in source and binary forms, with or without
+*  modification, are permitted provided that the following conditions
+*  are met:
+*
+*    Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+*
+*    Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the   
+*    distribution.
+*
+*    Neither the name of Texas Instruments Incorporated nor the names of
+*    its contributors may be used to endorse or promote products derived
+*    from this software without specific prior written permission.
+*
+*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*****************************************************************************/
+
+/*#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>*/
+#include "mbed.h"
+#include "strlib.h"
+
+//*****************************************************************************
+//
+//! \brief   Integer to ASCII
+//!
+//! \param  n is the number to be converted to ASCII
+//! \param s is a pointer to an array where the ASCII string will be placed
+//! \param b is the base (10 for decimal)
+//!
+//! \return none
+//
+//*****************************************************************************
+char *itoa(int n, char *s, int b)
+{
+    const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+    unsigned int i = 0;
+    int sign;
+    
+    if ((sign = n) < 0)
+        n = -n;
+
+    do {
+        s[i++] = digits[n % b];
+    } while ((n /= b) > 0);
+
+    if (sign < 0)
+        s[i++] = '-';
+    s[i] = '\0';
+
+    return strrev(s);
+}
+
+//*****************************************************************************
+//
+//! \brief   Reverses a string
+//!
+//! \param  str is a pointer to the string to be reversed
+//!
+//! \return none
+//
+//*****************************************************************************
+char *strrev(char *str)
+{
+    char *p1, *p2;
+
+    if (!str || !*str)
+        return str;
+
+    for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) {
+        *p1 ^= *p2;
+        *p2 ^= *p1;
+        *p1 ^= *p2;
+    }
+
+    return str;
+}
+
+//*****************************************************************************
+//
+//! atoc
+//!
+//! \param  none
+//!
+//! \return none
+//!
+//! \brief  Convert nibble to hexdecimal from ASCII
+//
+//*****************************************************************************
+unsigned char
+atoc(char data)
+{
+    unsigned char ucRes = 0;
+
+    if ((data >= 0x30) && (data <= 0x39))
+    {
+        ucRes = data - 0x30;
+    }
+    else
+    {
+        if (data == 'a')
+        {
+            ucRes = 0x0a;;
+        }
+        else if (data == 'b')
+        {
+            ucRes = 0x0b;
+        }
+        else if (data == 'c')
+        {
+            ucRes = 0x0c;
+        }
+        else if (data == 'd')
+        {
+            ucRes = 0x0d;
+        }
+        else if (data == 'e')
+        {
+            ucRes = 0x0e;
+        }
+        else if (data == 'f')
+        {
+            ucRes = 0x0f;
+        }
+    }
+
+
+    return ucRes;
+}
+
+
+//*****************************************************************************
+//
+//! atoshort
+//!
+//! \param  none
+//!
+//! \return none
+//!
+//! \brief  Convert 2 nibbles in ASCII into a short number
+//
+//*****************************************************************************
+
+unsigned short
+atoshort(char b1, char b2)
+{
+    unsigned short usRes;
+
+    usRes = (atoc(b1)) * 16 | atoc(b2);
+
+    return usRes;
+}
+
+//*****************************************************************************
+//
+//! ascii_to_char
+//!
+//! \param  none
+//!
+//! \return none
+//!
+//! \brief  Convert 2 bytes in ASCII into one character
+//
+//*****************************************************************************
+
+unsigned char
+ascii_to_char(char b1, char b2)
+{
+    unsigned char ucRes;
+
+    ucRes = (atoc(b1)) << 4 | (atoc(b2));
+
+    return ucRes;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utilities/strlib.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,55 @@
+/*****************************************************************************
+*
+*  strlib.h - String Library functions definitions
+*
+*  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+*
+*  Redistribution and use in source and binary forms, with or without
+*  modification, are permitted provided that the following conditions
+*  are met:
+*
+*    Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+*
+*    Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the   
+*    distribution.
+*
+*    Neither the name of Texas Instruments Incorporated nor the names of
+*    its contributors may be used to endorse or promote products derived
+*    from this software without specific prior written permission.
+*
+*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*****************************************************************************/
+
+#ifndef STRLIB_H
+#define STRLIB_H
+
+#ifdef    __cplusplus
+extern "C" {
+#endif
+
+char *itoa(int n, char *s, int b);
+char *strrev(char *str);
+unsigned char atoc(char data);
+unsigned short atoshort(char b1, char b2);
+unsigned char ascii_to_char(char b1, char b2);
+
+#ifdef    __cplusplus
+}
+#endif // __cplusplus
+
+#endif // STRLIB_H
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/AvnetHTML.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,113 @@
+#ifndef AVNET_HTML_H
+#define AVNET_HTML_H
+
+#ifdef    __cplusplus
+extern "C" {
+#endif
+
+// ---------- HTML Webpage Content is defined here ----------
+// Caution! Field labels and spaces in the HTML should not be edited without making corresponding changes in the C-code!
+char index[] = {
+"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html lang=\"en-US\">"
+"<head>"
+"<META content=\"text/html;charset=ISO-8859-1\" http-equiv=\"content-type\">"
+"<title>Wi-Go WebServer</title>"
+"<META HTTP-EQUIV=\"refresh\" content=\"2\">"   // Uncomment for auto-refresh every 2 seconds
+"</head>"
+
+"<body><div style=\"text-align: left\"><font size=\"6\" color=\"Red\" face=\"Tahoma\">"
+"<b>Avnet Wi-Go Webserver</b></font>"
+"<hr size=3 width=600 align=left>"
+"<font size=\"5\" color=\"Red\" face=\"Tahoma\"><b>LED RGB color select...</b></font>"
+
+//"<font size=\"5\" color=\"Black\" face=\"monospace\"></font>" 
+"<form method=\"get\" action=\"index.html\" name=\"server\">"
+"<input name=\"ledCon\" type=\"submit\" value=\"-Red-\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+"<input name=\"ledCon\" type=\"submit\" value=\"Green\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+"<input name=\"ledCon\" type=\"submit\" value=\"Blue-\">"
+"</form></div>" 
+
+"<hr size=3 width=600 align=left>"
+"<div style=\"text-align: left\"><font size=\"5\" color=\"Red\" face=\"Tahoma\">"
+"<b>Navigation Sensors</b></font></div>"
+
+"<div style=\"text-align:left\"><font size=\"4\" color=\"Black\" face=\"monospace\"><b>"
+"Acceleration(G)..                                       <br>"
+"Magnetometer(uT).                                       <br>"
+"eCompass.........                                         <br>"
+"Altitude.........                <br></b></font></div>"
+
+"<hr size=3 width=600 align=left>"
+"<div style=\"text-align: left\"><font size=\"5\" color=\"Red\" face=\"Tahoma\">"
+"<b>Status and Control</b></font></div>"
+
+"<div style=\"text-align:left\"><font size=\"4\" color=\"Black\" face=\"monospace\"><b>"
+"Battery Voltage..       <br>"
+"Ambient Light....       <br>"
+"Temperature......          <br>"
+"Slider Position..          <br>"
+"Page Views.......        </b></font>"
+"<hr size=3 width=600 align=left>"
+"</body></html>"};  // delete this line if adding the SVG code below...
+
+// Optional section 1: Full SVG graphic example: Uncomment this section to display the standard Wi-Fi logo in lower area of webpage
+// Browsers supporting SVG: Chrome and FireFox (all versions), Android (3.0 onwards), Safari (5.0 onwards), IE (9.0 onwards?)
+/*
+"<!--[if !IE]><!-->"  // This prevents SVG content being sent to Internet Explorer
+"<svg>" 
+"xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"175.49\" width=\"400\""
+"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
+"xmlns:cc=\"http://creativecommons.org/ns#\""
+"xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
+"<defs></defs>"
+"<metadata>"
+"<rdf:RDF>"
+"<cc:Work rdf:about=\"\">"
+"<dc:format>image/svg+xml</dc:format>"
+"<dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>"
+"<dc:title/>"
+"</cc:Work>"
+"</rdf:RDF>"
+"</metadata>"
+"<g transform=\"translate(-309.85919,-343.20843)\">"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,576.05074,474.82936)\">"
+"<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0c4.977,0,9.049,4.077,9.049,9.049v5.389c0,4.973-4.072,9.048-9.049,9.048h-35.433c-4.973,0-9.049-4.075-9.049-9.048v-5.389c0-4.972,4.076-9.049,9.049-9.049\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,514.3818,441.01715)\">"
+"<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0,0,5.389c0,4.072,3.314,7.32,7.32,7.32h9.187c4.007,0,7.253-3.248,7.253-7.32v-5.389c0-4.005-3.246-7.32-7.253-7.32h-20.239c2.281,1.656,3.732,4.284,3.732,7.32\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,469.99257,451.60916)\">"
+"<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0-3.043,0-0.55,2.56c-0.345,1.794-0.692,4.005-0.761,4.833-0.069-0.828-0.416-3.039-0.825-4.833l-0.555-2.56h-2.968l-2.767,11.748h3.317l0.343-2.004c0.276-1.66,0.556-3.659,0.695-5.044,0.136,1.385,0.481,3.384,0.896,5.044l0.412,2.004h2.972l0.413-2.004c0.348-1.66,0.693-3.659,0.833-5.044,0.136,1.385,0.482,3.384,0.757,5.044l0.278,2.004h3.313\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,491.40819,416.23898)\">"
+"<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0c-0.968,0-1.727,0.553-1.727,1.451,0,0.899,0.759,1.45,1.727,1.45,1.036,0,1.796-0.551,1.796-1.45,0-0.898-0.76-1.451-1.796-1.451m-1.521-0.968,3.0401,0,0-8.4984-3.0401,0,0,8.4984z\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,541.9845,418.05849)\">"
+"<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0,0-2.618,6.22,0,0-2.767-6.22,0,0-3.593-3.247,0,0,11.748,10.156,0,0-2.77\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,580.44446,416.23898)\">"
+"<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0c-0.97,0-1.727,0.553-1.727,1.451,0,0.899,0.757,1.45,1.727,1.45,1.035,0,1.797-0.551,1.797-1.45,0-0.898-0.762-1.451-1.797-1.451m-1.521-0.968,3.0371,0,0-8.4984-3.0371,0,0,8.4984z\"/>"
+"</g>"
+"</g>"
+"</svg>"
+"<!--<![endif]-->"  
+*/                // end of conditional inclusion of SVG graphic (excludes Internet Explorer browser)
+// ---- End of Wi-Fi logo SVG image definition ----
+
+// Optional section 2: Simple SVG graphic example: Uncomment this section to generate a filled circle  in lower area of webpage
+// eg. Could use to indicate RGB LED color (with addition of applicable C-code to dynamically update specified "fill=" color)
+/*
+"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"
+"<circle cx=\"155\" cy=\"22\" r=\"20\" stroke=\"DimGrey\" stroke-width=\"2\" fill=\"Red\"/>"
+"</svg>"
+"</body></html>"};
+*/
+
+#ifdef    __cplusplus
+}
+#endif // __cplusplus
+#endif // AVNET_HTML_H
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/demo.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,575 @@
+
+/*****************************************************************************
+* Dynamic HTML string handlers: 
+* Nine dynamic HTML fields are updated on browser refresh or button press: 
+*     Acceleration
+*     Magnetometer                  
+*     eCompass      
+*     Altitude
+*     Battery Voltage
+*     Ambient Light
+*     Temperature                   
+*     Slider Position       
+*     Page Views
+*
+* CGI HTML forms: 
+* Three CGI form inputs are used to submit data from browser to the Server: 
+* On screen buttons: -Red-, Green, Blue (for control of RGB LED output color) 
+*
+* myindex[] contains the HTML string that defines the webpage that is served
+* Use an online HTML validator to verify HTML code before running it on the MCU
+* eg. 
+* www.w3schools.com/tags/tryit.asp?filename=tryhtml_div_test
+* www.onlinewebcheck.com/check.php?adv=1
+* Note: Before checking the HTML in one of these validators, 
+* strip-out all “\” backslash characters (using search & replace)
+*
+* Webserver code is based on TI's CC3000 Simple HTTP Webserver:  
+* http://processors.wiki.ti.com/index.php/CC3000_Wi-Fi_for_MCU
+* 
+* More detail on implementation of this Webserver App is available here:
+* http://processors.wiki.ti.com/index.php/CC3000_HTTP_Server_Demo_Session
+*
+* A more advanced Webserver and Client App is also available from TI for the CC3000:
+* http://processors.wiki.ti.com/index.php/CC3000_Web_Server_Client_Application
+* (at this time not yet ported to Kinetis-L as the host processor)
+* 
+******************************************************************************
+*
+*  demo.c - CC3000 Main Demo Application
+*  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+*
+*  Redistribution and use in source and binary forms, with or without
+*  modification, are permitted provided that the following conditions
+*  are met:
+*
+*    Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+*
+*    Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the
+*    distribution.
+*
+*    Neither the name of Texas Instruments Incorporated nor the names of
+*    its contributors may be used to endorse or promote products derived
+*    from this software without specific prior written permission.
+*
+*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*****************************************************************************/
+
+#include "mbed.h"
+#include "defLED.h"
+#include "demo.h"
+#include "AvnetHTML.h"
+#include "TSISensor.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+
+extern DigitalOut ledr;
+extern DigitalOut ledg;
+extern DigitalOut ledb;
+extern DigitalOut led1;
+extern DigitalOut led2;
+extern DigitalOut led3;
+extern TSISensor tsi;
+
+// Setup the functions to handle our CGI parameters
+cgi_handler pHandlers;
+dyn_html_handler htmlHandlers;
+
+extern tNetappIpconfigRetArgs ipinfo2;
+
+extern axis6_t axis6;
+extern int server_running;
+extern unsigned char newData;
+extern unsigned short adc_sample3;
+
+/** \brief Pointer to the index HTML page */
+char * indexPage;
+
+/** \brief Pointer to CGI handler structure */
+cgi_handler * chList;
+
+/** \brief Pointer to Dynamic HTML handler structure */
+dyn_html_handler * htmlList;
+
+/** \brief Page view counter */
+int viewCounter = 1;
+#define REQ_BUFFER_SIZE     400
+#define HTTP_TX_BLOCK_SIZE  256
+//#define HTTP_TX_BLOCK_SIZE  1024
+//#define HTTP_TX_BLOCK_SIZE  512
+
+
+// Setup the functions to handle our CGI parameters
+char requestBuffer[REQ_BUFFER_SIZE];
+
+
+
+
+
+/*
+// ---------- HTML Webpage Content is defined here ----------
+// Caution! Field labels and spaces in the HTML should not be edited without making corresponding changes in the C-code!
+char index[] = {
+"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html lang=\"en-US\">"
+"<head>"
+"<META content=\"text/html;charset=ISO-8859-1\" http-equiv=\"content-type\">"
+"<title>Wi-Go WebServer</title>"
+//"<META HTTP-EQUIV=\"refresh\" content=\"2\">"   // Uncomment for auto-refresh every 2 seconds
+"</head>"
+
+"<body><div style=\"text-align: left\"><font size=\"6\" color=\"Red\" face=\"Tahoma\">"
+"<b>Avnet Wi-Go Webserver</b></font>"
+"<hr size=3 width=600 align=left>"
+"<font size=\"5\" color=\"Red\" face=\"Tahoma\"><b>LED RGB color select...</b></font>"
+
+//"<font size=\"5\" color=\"Black\" face=\"monospace\"></font>" 
+"<form method=\"get\" action=\"index.html\" name=\"server\">"
+"<input name=\"ledCon\" type=\"submit\" value=\"-Red-\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+"<input name=\"ledCon\" type=\"submit\" value=\"Green\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+"<input name=\"ledCon\" type=\"submit\" value=\"Blue-\">"
+"</form></div>" 
+
+"<hr size=3 width=600 align=left>"
+"<div style=\"text-align: left\"><font size=\"5\" color=\"Red\" face=\"Tahoma\">"
+"<b>Navigation Sensors</b></font></div>"
+
+"<div style=\"text-align:left\"><font size=\"4\" color=\"Black\" face=\"monospace\"><b>"
+"Acceleration(G)..                                       <br>"
+"Magnetometer(uT).                                       <br>"
+"eCompass.........                                         <br>"
+"Altitude.........                <br></b></font></div>"
+
+"<hr size=3 width=600 align=left>"
+"<div style=\"text-align: left\"><font size=\"5\" color=\"Red\" face=\"Tahoma\">"
+"<b>Status and Control</b></font></div>"
+
+"<div style=\"text-align:left\"><font size=\"4\" color=\"Black\" face=\"monospace\"><b>"
+"Battery Voltage..       <br>"
+"Ambient Light....       <br>"
+"Temperature......          <br>"
+"Slider Position..          <br>"
+"Page Views.......        </b></font>"
+"<hr size=3 width=600 align=left>"
+"</body></html>"};  // delete this line if adding the SVG code below...
+*/
+// Optional section 1: Full SVG graphic example: Uncomment this section to display the standard Wi-Fi logo in lower area of webpage
+// Browsers supporting SVG: Chrome and FireFox (all versions), Android (3.0 onwards), Safari (5.0 onwards), IE (9.0 onwards?)
+/*
+"<!--[if !IE]><!-->"  // This prevents SVG content being sent to Internet Explorer
+"<svg>" 
+"xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"175.49\" width=\"400\""
+"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
+"xmlns:cc=\"http://creativecommons.org/ns#\""
+"xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
+"<defs></defs>"
+"<metadata>"
+"<rdf:RDF>"
+"<cc:Work rdf:about=\"\">"
+"<dc:format>image/svg+xml</dc:format>"
+"<dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>"
+"<dc:title/>"
+"</cc:Work>"
+"</rdf:RDF>"
+"</metadata>"
+"<g transform=\"translate(-309.85919,-343.20843)\">"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,576.05074,474.82936)\">"
+"<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0c4.977,0,9.049,4.077,9.049,9.049v5.389c0,4.973-4.072,9.048-9.049,9.048h-35.433c-4.973,0-9.049-4.075-9.049-9.048v-5.389c0-4.972,4.076-9.049,9.049-9.049\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,514.3818,441.01715)\">"
+"<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0,0,5.389c0,4.072,3.314,7.32,7.32,7.32h9.187c4.007,0,7.253-3.248,7.253-7.32v-5.389c0-4.005-3.246-7.32-7.253-7.32h-20.239c2.281,1.656,3.732,4.284,3.732,7.32\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,469.99257,451.60916)\">"
+"<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0-3.043,0-0.55,2.56c-0.345,1.794-0.692,4.005-0.761,4.833-0.069-0.828-0.416-3.039-0.825-4.833l-0.555-2.56h-2.968l-2.767,11.748h3.317l0.343-2.004c0.276-1.66,0.556-3.659,0.695-5.044,0.136,1.385,0.481,3.384,0.896,5.044l0.412,2.004h2.972l0.413-2.004c0.348-1.66,0.693-3.659,0.833-5.044,0.136,1.385,0.482,3.384,0.757,5.044l0.278,2.004h3.313\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,491.40819,416.23898)\">"
+"<path fill-rule=\"nonzero\" fill=\"#FFF\" d=\"m0,0c-0.968,0-1.727,0.553-1.727,1.451,0,0.899,0.759,1.45,1.727,1.45,1.036,0,1.796-0.551,1.796-1.45,0-0.898-0.76-1.451-1.796-1.451m-1.521-0.968,3.0401,0,0-8.4984-3.0401,0,0,8.4984z\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,541.9845,418.05849)\">"
+"<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0,0-2.618,6.22,0,0-2.767-6.22,0,0-3.593-3.247,0,0,11.748,10.156,0,0-2.77\"/>"
+"</g>"
+"<g transform=\"matrix(3.7361528,0,0,-3.7361528,580.44446,416.23898)\">"
+"<path fill-rule=\"nonzero\" fill=\"#231f20\" d=\"m0,0c-0.97,0-1.727,0.553-1.727,1.451,0,0.899,0.757,1.45,1.727,1.45,1.035,0,1.797-0.551,1.797-1.45,0-0.898-0.762-1.451-1.797-1.451m-1.521-0.968,3.0371,0,0-8.4984-3.0371,0,0,8.4984z\"/>"
+"</g>"
+"</g>"
+"</svg>"
+"<!--<![endif]-->"  
+*/                // end of conditional inclusion of SVG graphic (excludes Internet Explorer browser)
+// ---- End of Wi-Fi logo SVG image definition ----
+
+// Optional section 2: Simple SVG graphic example: Uncomment this section to generate a filled circle  in lower area of webpage
+// eg. Could use to indicate RGB LED color (with addition of applicable C-code to dynamically update specified "fill=" color)
+/*
+"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"
+"<circle cx=\"155\" cy=\"22\" r=\"20\" stroke=\"DimGrey\" stroke-width=\"2\" fill=\"Red\"/>"
+"</svg>"
+"</body></html>"};
+*/
+
+// ----------------------------------------------------------
+
+//char ssid_name[] = SSID;
+char testString[20];
+//int vcc = 0;
+//*****************************************************************************
+//
+//!  demo_wi-fi_main
+//!
+//!  \param  None
+//!
+//!  \return none
+//!
+//!  \brief   The main loop is executed here
+//
+//*****************************************************************************
+
+int demo_wifi_main(void)
+{
+    server_running = 1;
+    while(1)
+    {
+      /* Configure dynamic HTML string handlers
+         0 : Acceleration
+         1 : Magnetometer                   
+         2 : eCompass       
+         3 : Altitude
+         ------------------- 
+         4 : Battery Voltage
+         5 : Ambient Light
+         6 : Temperature                    
+         7 : Slider Position        
+         8 : Page Views
+      */                    
+        (htmlHandlers.dynHtmlFunc[0]) = getAccelXYZ_Str; 
+        memcpy(htmlHandlers.dynHtmlParamName[0],"Acceleration(G).. ",strlen("Acceleration(G).. "));
+        htmlHandlers.dynHtmlParamName[0][strlen("Acceleration(G).. ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[1]) = getM3110Str; 
+        memcpy(htmlHandlers.dynHtmlParamName[1],"Magnetometer(uT). ",strlen("Magnetometer(uT). "));
+        htmlHandlers.dynHtmlParamName[1][strlen("Magnetometer(uT). ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[2]) = getCompassStr;
+        memcpy(htmlHandlers.dynHtmlParamName[2],"eCompass......... ",strlen("eCompass......... "));
+        htmlHandlers.dynHtmlParamName[2][strlen("eCompass......... ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[3]) = getAltitudeStr; 
+        memcpy(htmlHandlers.dynHtmlParamName[3],"Altitude......... ",strlen("Altitude......... "));
+        htmlHandlers.dynHtmlParamName[3][strlen("Altitude......... ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[4]) = getBatteryVoltageStr;
+        memcpy(htmlHandlers.dynHtmlParamName[4],"Battery Voltage.. ",strlen("Battery Voltage.. "));
+        htmlHandlers.dynHtmlParamName[4][strlen("Battery Voltage.. ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[5]) = getLightVoltageStr;
+        memcpy(htmlHandlers.dynHtmlParamName[5],"Ambient Light.... ",strlen("Ambient Light.... "));
+        htmlHandlers.dynHtmlParamName[5][strlen("Ambient Light.... ")] ='\0';
+            
+        (htmlHandlers.dynHtmlFunc[6]) = getTemperatureStr; 
+        memcpy(htmlHandlers.dynHtmlParamName[6],"Temperature...... ",strlen("Temperature...... "));
+        htmlHandlers.dynHtmlParamName[6][strlen("Temperature...... ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[7]) = getTSI_sliderStr; 
+        memcpy(htmlHandlers.dynHtmlParamName[7],"Slider Position.. ",strlen("Slider Position.. "));
+        htmlHandlers.dynHtmlParamName[7][strlen("Slider Position.. ")] ='\0';
+
+        (htmlHandlers.dynHtmlFunc[8]) = getViewsNum;
+        memcpy(htmlHandlers.dynHtmlParamName[8],"Page Views....... ",strlen("Page Views....... "));
+        htmlHandlers.dynHtmlParamName[8][strlen("Page Views....... ")] ='\0';
+
+        // Configure CGI Handler
+        (pHandlers.cgiHandlerFunc[0]) = testFunc;
+
+        serverMain(HTTP_PORT,(char *)index, &pHandlers, &htmlHandlers);
+    }
+}
+
+
+void testFunc(char * str)
+{
+    memcpy(testString,str,strlen(str));
+    if(strcmp(str, "-Red-") == 0)
+    {
+        RED_ON; GREEN_OFF; BLUE_OFF; 
+    }
+    else if(strcmp(str, "Green") == 0) 
+    {
+        RED_OFF; GREEN_ON; BLUE_OFF;
+    }
+    else if (strcmp(str, "Blue-") == 0) 
+    {
+        RED_OFF; GREEN_OFF; BLUE_ON;
+    }      
+}
+
+void getBatteryVoltageStr(char * str)
+{
+    sprintf(str,"    "); //clears field (needed if previous string had more characters)
+    sprintf(str, "%d %%", adc_sample3);
+}
+ 
+void getLightVoltageStr(char * str)
+{
+    int LightPercent = 0;
+    LightPercent = (axis6.light * 100) / 4096; 
+    sprintf(str,"    "); //clears field (needed if previous string had more characters)
+    sprintf(str, "%d %%", LightPercent);
+}
+
+void getAccelXYZ_Str(char * str) // MMA8451Q accelerometer - report axis with highest value 
+{
+    sprintf(str,"                                    "); //clears field (needed if previous string had more characters)   
+    sprintf(str, "X= %1.2f, Y= %1.2f, Z= %1.2f", axis6.fGax, axis6.fGay, axis6.fGaz);;  
+}  
+
+void getTemperatureStr(char * str) // 
+{
+    sprintf(str, "%+d C", axis6.temp); 
+}
+
+void getTSI_sliderStr(char * str) // TSI Slider position 
+{
+    uint8_t slider_position; 
+    
+    slider_position = tsi.readPercentage() * 100; // Slider position as percentage
+    sprintf(str,"    "); //clears field (needed if previous string had more characters)
+    sprintf(str, "%d %%", slider_position);
+}   
+
+void getCompassStr(char * str)   // Mag3110 generated Compass bearing 
+{
+    char *compass_points[9] = {"North", "N-East", "East", "S-East", "South", "S-West", "West", "N-West", "North"};
+    signed short compass_bearing = (axis6.compass + 23) / 45;
+    sprintf(str,"                                        "); //clears field (needed if previous string had more characters)
+    sprintf(str, "Roll=%-d  Pitch=%-d  Yaw=%-d [%s]", axis6.roll, axis6.pitch, axis6.yaw, compass_points[compass_bearing]);   // 
+}   
+
+void getM3110Str(char * str)   // Mag3110 displayed in units of UT 
+{
+    sprintf(str,"                                    "); //clears field (needed if previous string had more characters)
+    sprintf(str, "X= %3.1f, Y= %3.1f, Z= %3.1f", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz);
+}   
+
+void getAltitudeStr(char * str)    // Get Altitude 
+{
+    sprintf(str, "%+d meters", axis6.alt);   // str = integer portion of result 
+}   
+
+
+
+//*****************************************************************************
+//
+//! \brief  Main HTTP Server
+//!
+//! \param none
+//!
+//! \return none
+//!
+//
+//*****************************************************************************
+void serverMain(int port,
+                char * ipage,
+                cgi_handler * handleList,
+                dyn_html_handler * dhList)
+{
+    static TCPSocketServer server;
+    static TCPSocketConnection client;
+
+    indexPage = ipage;
+    chList = handleList;
+    htmlList = dhList;
+
+    server.bind(port);
+
+    printf("Main HTTP server\r\n");
+
+    // Start Listening
+    if(server.listen() != 0);
+
+    // Handle Clients and Data
+    while(1)
+    {
+        int32_t status = server.accept(client);
+        if (status >= 0)
+        {
+            LED_D2_ON;
+            // Connection Accepted, Send Data
+            // Wait for a data update
+            client.set_blocking(true);
+            printf("Connection\r\n");
+//            printf("Connection from: %s \r\n", client.get_address());
+            if(newData) handleHTTPRequest(&client);
+            newData = 0;
+            client.close();
+            LED_D2_OFF;
+        }
+        else if(status == -57)
+        {
+            // BUG: Socket inactive so reopen socket
+            // Inactive Socket, close and reopen it
+            printf("Oops!!!\r\n");
+            server.close();
+            indexPage = ipage;
+            chList = handleList;
+            htmlList = dhList;
+            server.bind(port);
+
+            // Start Listening
+            if (server.listen() != 0);
+        }
+    }
+}
+
+//*****************************************************************************
+//
+//! \brief  Handles HTTP Requests
+//!
+//! \param cnum is the client socket handle to be used
+//!
+//! \return none
+//!
+//
+//*****************************************************************************
+void handleHTTPRequest(TCPSocketConnection *client)
+{
+    char * reqline[3];
+    char * cgiTok;
+
+    int i = 0;
+    char paramBuf[20];
+    int bytesRecvd;
+    char tempStr[40]; //PF was 26
+
+    memset(requestBuffer,0,sizeof (requestBuffer));
+    bytesRecvd = client->receive(requestBuffer, sizeof(requestBuffer));
+
+    printf("handleHTTPRequest\r\n");
+
+    if(bytesRecvd > 0)
+    {
+        // Received some data, check it and send data back
+        reqline[0] = strstr(requestBuffer, "GET");
+        if ( reqline[0] != NULL )
+        {
+            if (strstr (requestBuffer, "HTTP/1.0") != NULL && strstr (requestBuffer, "HTTP/1.1") != NULL )
+            {
+                client->send_all("HTTP/1.0 400 Bad Request\n", 25);
+            }
+            else
+            {
+
+#ifdef HTTP_CGI_ENABLED
+                // Do we have CGI parameters we need to parse?
+                if(strchr(requestBuffer, '?') != NULL)
+                {
+                    // Decode URL and handle each parameter sequentially
+                    // according to table previously setup.
+                    cgiTok = strstr(requestBuffer,"=");
+                    if(cgiTok != NULL)
+                    {
+                        memset(paramBuf,0,sizeof(paramBuf));
+                        memcpy(paramBuf,cgiTok+1,5);     // hard-coded for demo: 5 character parameter (-Red-/Green/Blue-)
+                        chList->cgiHandlerFunc[0](paramBuf);
+
+                    }
+                }
+#endif
+
+#ifdef HTTP_DYN_HTML_ENABLED
+                // The code below replaces data in the HTML page
+                // with that generated by the specified functions.
+                for(i = 0; i < 9; i++)  // change the range here for more dynamic fields on webpage
+                {
+                    memset(tempStr,0,sizeof(tempStr));
+                    htmlList->dynHtmlFunc[i](tempStr);
+                    tempStr[strlen(tempStr)]= ' ';
+                    pageReplace((char *)indexPage,
+                                (char *)htmlList->dynHtmlParamName[i],
+                                (char *)tempStr);
+                }
+#endif
+                viewCounter++;
+                sendHTTPData(HTTP_RESP, strlen(HTTP_RESP), client);
+                                
+                for(i = 0; i < strlen(indexPage); i += HTTP_TX_BLOCK_SIZE)
+                {
+                    if(strlen(indexPage) - i < HTTP_TX_BLOCK_SIZE)
+                    {
+                        sendHTTPData(&indexPage[i], strlen(indexPage) - i, client);
+                    }
+                    else
+                    {
+                        sendHTTPData(&indexPage[i], HTTP_TX_BLOCK_SIZE, client);
+                    }
+                }
+            }
+        }
+    }
+}
+
+//*****************************************************************************
+//
+//! \brief  Inserts characters in page that appear after an indicator ind
+//! with the value from val
+//!
+//! \param  page is a pointer to the array holding the page's HTML code
+//! \param ind is a pointer to a string that has the name of the parameter on the page to modify
+//! \param val is the pointer to a string holding the string to insert in the XXX
+//!
+//! \return none
+//!
+//
+//*****************************************************************************
+void pageReplace(char * page, char * ind, char * val)
+{
+    char * indicLoc;
+    indicLoc = strstr (page,ind);
+    memcpy(indicLoc+strlen(ind), val, strlen(val));
+}
+
+//*****************************************************************************
+//
+//! \brief  Returns a string with the number of views of the page
+//!
+//! \param  str is a pointer to the array where the number of views will be put
+//!
+//! \return none
+//!
+//
+//*****************************************************************************
+void getViewsNum(char * str)
+{
+    sprintf(str, "%d", viewCounter);
+}
+
+//*****************************************************************************
+//
+//! \brief  Sends HTTP Data
+//!
+//! \param sdesc is the socket descriptor of the socket used for sending data
+//! \param buf is a pointer to the buffer with the data to be sent
+//! \param len is the number of bytes to send
+//!
+//! \return none
+//!
+//
+//*****************************************************************************
+void sendHTTPData(char * buf, long len, TCPSocketConnection *client)
+{
+    int bytesSent = -2;
+    while(bytesSent == -2) bytesSent = client->send_all(buf, len);
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/demo.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,66 @@
+#ifndef DEMO_H
+#define DEMO_H
+#include "TCPSocketConnection.h"
+#include "TCPSocketServer.h"
+
+#ifdef    __cplusplus
+extern "C" {
+#endif
+
+#define MAX_CGI_PARAMS 4
+#define MAX_DYN_HTML_PARAMS 9
+#define MAX_DYN_HTML_PARAM_SIZE 40
+#define ROOT "/"
+
+
+#define HTTP_RESP "HTTP/1.0 200 OK\n\n"
+
+#define HTTP_CGI_ENABLED
+#define HTTP_DYN_HTML_ENABLED
+#define HTTP_PORT     80
+
+#define MAX_REPLACE_CHAR 16
+
+
+// Struct that indicates all the elements necessary to handle
+typedef struct
+{
+    // name of parameter that will be analyzed
+    // Currently not implemented to verify each
+    // This would enable us to be flexible with parameter list
+    //char [][]
+    
+    // Array of functions that will handle each parameter
+    void (*cgiHandlerFunc[MAX_CGI_PARAMS])(char *);
+        
+} cgi_handler;
+
+
+typedef struct
+{
+     char dynHtmlParamName[MAX_DYN_HTML_PARAMS][MAX_DYN_HTML_PARAM_SIZE];
+     void (*dynHtmlFunc[40])(char *);  //PF was 20
+} dyn_html_handler;
+
+void serverMain(int port, char * ipage,  cgi_handler * handleList, dyn_html_handler * dhList);
+void handleHTTPRequest(TCPSocketConnection *client);
+void pageReplace(char * page, char * ind, char * val);
+void getViewsNum(char * str);
+void sendHTTPData(char * buf, long len, TCPSocketConnection *client);
+
+int demo_wifi_main(void);
+void testFunc(char * str);
+void getBatteryVoltageStr(char * str);
+void getLightVoltageStr(char * str);
+void getAccelXYZ_Str(char * str);
+void getTemperatureStr(char * str);
+void getTSI_sliderStr(char * str);
+void getCompassStr(char * str);
+void getM3110Str(char * str);
+void getAltitudeStr(char * str);
+
+#ifdef    __cplusplus
+}
+#endif // __cplusplus
+#endif // DEMO_H
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/doTCPIP.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,138 @@
+/****************************************************************************
+*
+*  doTCPIP.cpp - CC3000 TCP/IP
+*  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+*
+*  Redistribution and use in source and binary forms, with or without
+*  modification, are permitted provided that the following conditions
+*  are met:
+*
+*    Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+*
+*    Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the
+*    distribution.
+*
+*    Neither the name of Texas Instruments Incorporated nor the names of
+*    its contributors may be used to endorse or promote products derived
+*    from this software without specific prior written permission.
+*
+*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*****************************************************************************/
+
+#include "mbed.h"
+#include "defLED.h"
+#include "doTCPIP.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+
+extern DigitalOut ledr;
+extern DigitalOut ledg;
+extern DigitalOut ledb;
+extern DigitalOut led1;
+extern DigitalOut led2;
+extern DigitalOut led3;
+
+extern int do_mDNS;
+extern axis6_t axis6;
+extern unsigned char newData;
+extern int HsecondFlag;
+extern unsigned int seconds;
+
+// Setup the functions to handle our CGI parameters
+extern char requestBuffer[];
+  
+//Device name - used for Smart config in order to stop the Smart phone configuration process
+extern char DevServname;
+
+void runTCPIPserver(void)
+{
+    while(1)
+    {
+        long temp, stat, sss, skip, skipc, newsock;
+        LED_D3_OFF;
+        LED_D2_OFF;
+        printf("\n\nStarting TCP/IP Server\n");
+        TCPSocketServer server;
+        server.bind(TCPIP_PORT);
+        server.listen();
+        printf("\r\nWait for new connection...\r\n");
+        skip = 0;
+        skipc = 0;
+        while(1)
+        {
+            newsock = -2;
+            printf("\r\nServer waiting for connection\r\n");
+            TCPSocketConnection client;
+            LED_D2_ON;
+            while((newsock == -1) || (newsock == -2))
+            {
+                newsock = server.accept(client);
+                client.set_blocking(true);
+                if(do_mDNS)
+                {
+                    printf("mDNS= 0x%08x\n", wifi._socket.mdns_advertiser(1, (uint8_t *)DevServname, sizeof(DevServname)));
+                    do_mDNS = 0;
+                }
+            }
+            printf("Connection from: %s \r\n", client.get_address());
+            sss = seconds;
+            //receive TCP data
+            temp = 0;   
+            if(newsock >= 0)
+            {
+                client.receive((char *)requestBuffer,20);
+                printf("Input = %s\n", requestBuffer);
+                HsecondFlag = 0;
+                while(1)
+                {
+                    while(!newData) __wfi();
+                    newData = 0;
+                    if(HsecondFlag)
+                    {
+                        printf("FB= %d\n", wifi._simple_link.get_number_free_buffers());
+                        HsecondFlag = 0;
+                    }
+                    LED_D2_ON;  
+                    stat = -2;
+                    stat = client.send_all((char *)&axis6, sizeof(axis6));
+                    LED_D2_OFF;
+                    if(stat != 96)
+                    {
+                        if(stat == -2)
+                        {
+                            skip++;
+                            skipc++;
+                        }
+                        if(stat == -1) break;
+                    }
+                    else
+                    {
+                        temp++;
+                        skipc = 0;
+                    }
+                    if(skipc > 150)
+                    {
+                        printf("Zero Buffer Error Sent=%d, time=%d\n", temp, seconds - sss);
+                        break;
+                    }
+                }   
+            } else printf("bad socket= %d\n", newsock);
+            client.close();
+            printf("Done %d, time= %d, skipped= %d\n", temp, seconds - sss, skip);
+            skip = 0;
+        }
+    }   
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/doTCPIP.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,66 @@
+/****************************************************************************
+*
+*  doTCPIP.h - CC3000 TCP/IP
+*  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+*
+*  Redistribution and use in source and binary forms, with or without
+*  modification, are permitted provided that the following conditions
+*  are met:
+*
+*    Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+*
+*    Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the
+*    distribution.
+*
+*    Neither the name of Texas Instruments Incorporated nor the names of
+*    its contributors may be used to endorse or promote products derived
+*    from this software without specific prior written permission.
+*
+*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*****************************************************************************/
+
+#ifndef DOTCPIP_H
+#define DOTCPIP_H
+
+#include "TCPSocketConnection.h"
+#include "TCPSocketServer.h"
+
+extern cc3000 wifi;
+extern tUserFS user_info;
+
+/** TCP/IP Functions
+*
+*/
+#ifdef    __cplusplus
+extern "C" {
+#endif
+
+// SMTP Specific
+#define HTTP_PORT     80
+#define TCPIP_PORT    15000
+
+#define REQ_BUFFER_SIZE 400
+
+void runTCPIPserver(void);
+
+#ifdef    __cplusplus
+}
+#endif // __cplusplus
+
+#endif // DOTCPIP_H
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/run_exosite.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,692 @@
+/*****************************************************************************
+*
+*  demo.c - CC3000 Main Demo Application
+*  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+*
+*  Redistribution and use in source and binary forms, with or without
+*  modification, are permitted provided that the following conditions
+*  are met:
+*
+*    Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+*
+*    Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the   
+*    distribution.
+*
+*    Neither the name of Texas Instruments Incorporated nor the names of
+*    its contributors may be used to endorse or promote products derived
+*    from this software without specific prior written permission.
+*
+*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*****************************************************************************/
+
+#include "run_exosite.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+#include "mbed.h"
+#include "defLED.h"
+#include "strlib.h"
+
+extern DigitalOut ledr;
+extern DigitalOut ledg;
+extern DigitalOut ledb;
+extern DigitalOut led1;
+extern DigitalOut led2;
+extern DigitalOut led3;
+
+// local defines
+#define WRITE_INTERVAL 5
+#define EXO_BUFFER_SIZE 300 //reserve 300 bytes for our output buffer
+
+typedef struct
+{
+    float *p;
+    char *s;
+} exo_data_ft;
+
+typedef struct
+{
+    int16_t *p;
+    char *s;
+} exo_data_it;
+
+//extern tUserFS user_info;
+
+extern char requestBuffer[];
+
+extern unsigned int compass_type, seconds;
+
+char exo_meta[META_SIZE];
+
+#define RX_SIZE 60
+#define MAC_LEN 6
+
+typedef enum
+{
+    CIK_LINE,
+    HOST_LINE,
+    CONTENT_LINE,
+    ACCEPT_LINE,
+    LENGTH_LINE,
+    GETDATA_LINE,
+    POSTDATA_LINE,
+    VENDOR_LINE,
+    EMPTY_LINE
+} lineTypes;
+
+#define STR_CIK_HEADER "X-Exosite-CIK: c3c675e0601551c6d4d3230e162d62cc8bba3311\r\n"
+#define STR_CONTENT_LENGTH "Content-Length: "
+#define STR_GET_URL "GET /api:v1/stack/alias?"
+#define STR_HTTP "  HTTP/1.1\r\n"
+#define STR_HOST "Host: avnet.m2.exosite.com\r\n"
+#define STR_ACCEPT "Accept: application/x-www-form-urlencoded; charset=utf-8\r\n"
+#define STR_CONTENT "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"
+#define STR_VENDOR "vendor=avnet&model=wigosmartconfig&sn="
+#define STR_CRLF "\r\n"
+#define MY_CIK "27b9684751332589be52c8e5819e7c438f7e7479"
+char myCIK[] = "c3c675e0601551c6d4d3230e162d62cc8bba3311";
+
+// local functions
+void activate_device(TCPSocketConnection *socket);
+int readResponse(TCPSocketConnection *socket, char * expectedCode);
+long connect_to_exosite(TCPSocketConnection *socket);
+void sendLine(TCPSocketConnection *socket, unsigned char LINE, char * payload);
+void exosite_meta_write(unsigned char * write_buffer, unsigned short srcBytes, unsigned char element);
+void exosite_meta_read(unsigned char * read_buffer, unsigned short destBytes, unsigned char element);
+int Exosite_Write(TCPSocketConnection *socket, char * pbuf, unsigned char bufsize);
+int Exosite_Read(char * palias, char * pbuf, unsigned char bufsize);
+int Exosite_Init(TCPSocketConnection *socket);
+
+// global variables
+static unsigned char exositeWriteFailures = 0;
+
+// exported functions
+
+// externs
+extern char *itoa(int n, char *s, int b);
+
+extern axis6_t axis6;
+extern int secondFlag;
+extern int server_running;
+
+/** \brief Definition of data packet to be sent by server */
+unsigned char dataPacket[] = { '\r', 0xBE, 128, 128, 128, 70, 36, 0xEF };
+char activeCIK[41];
+
+exo_data_ft exo_fdata[] = {
+        &axis6.fGax,    "acc_x=%f&",
+        &axis6.fGay,    "acc_y=%f&",
+        &axis6.fGaz,    "acc_z=%f&",
+        &axis6.fUTmx,   "mag_x=%f&",
+        &axis6.fUTmy,   "mag_y=%f&",
+        &axis6.fUTmz,   "mag_z=%f&",    
+        &axis6.q0,      "q_w=%f&",  
+        &axis6.q1,      "q_x=%f&",  
+        &axis6.q2,      "q_y=%f&",  
+        &axis6.q3,      "q_z=%f&",  
+        0, 0 };
+
+exo_data_it exo_idata[] = {
+        &axis6.roll,    "roll=%d&",
+        &axis6.pitch,   "pitch=%d&",
+        &axis6.yaw,     "yaw=%d&",
+        &axis6.alt,     "alt=%d&",
+        &axis6.temp,    "temp=%d&",
+        &axis6.light,   "light=%d&",
+        0, 0
+};
+    
+//*****************************************************************************
+//
+//!  main
+//!
+//!  \param  None
+//!
+//!  \return none
+//!
+//!  \brief   The main loop is executed here
+//
+//*****************************************************************************
+void run_exosite(TCPSocketConnection *socket)
+{
+    int value;
+    exo_data_it *tsp;
+    exo_data_ft *tspf;
+    
+    printf("\nConnecting to Exosite\n");
+    //user_info.validCIK = 0; // uncomment this to force provisioning every time, only used for debug
+    
+    if(!user_info.validCIK)
+    {
+        printf("Activating Wi-Go System on Exosite\n");
+        uint8_t myMAC[8];
+        wifi.get_mac_address(myMAC);
+        printf(" MAC address %02x:%02x:%02x:%02x:%02x:%02x \r\n \r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]);
+        wait_ms(100);
+        printf("Enter the device MAC on your Exosite device portal to prepare\n");
+        wait_ms(100);
+        printf("the system for provisioning your Wi-Go system onto Exosite\n");
+        wait_ms(100);
+        printf("Hit any key to continue.....\n");
+        getchar();
+        Exosite_Init(socket);
+    }
+    
+    for(value=0 ;value < CIK_LENGTH ; value++) activeCIK[value] = user_info.CIK[value];
+    activeCIK[value] = NULL;
+    // Main Loop
+    while (1)
+    {
+        while(!secondFlag) /*__wfi()*/;
+        secondFlag = 0;
+        LED_D2_ON;
+
+        // Build string
+        requestBuffer[0] = 0;
+        tsp     = &exo_idata[0];
+        tspf    = &exo_fdata[0];
+        while(tsp->p)
+        {
+            sprintf( requestBuffer + strlen(requestBuffer), tsp->s, *tsp->p);
+            tsp++;
+        }
+        while(tspf->p)
+        {
+            sprintf( requestBuffer + strlen(requestBuffer), tspf->s, *tspf->p);
+            tspf++;
+        }
+        sprintf( requestBuffer + strlen(requestBuffer), "time=%d\r\n", axis6.timestamp);
+
+        if(strlen(requestBuffer) > 300) printf("Buffer size= %d too small!!!", strlen(requestBuffer));
+        //printf("Buffer size= %d\n", strlen(requestBuffer));
+        value = Exosite_Write(socket, requestBuffer, strlen(requestBuffer));    //write all sensor values to the cloud
+        LED_D2_OFF; 
+        if(value == -1)
+        {
+            LED_D3_OFF;
+            wifi.stop();
+            if (wifi.connect() == -1)
+                printf("Failed to connect. Please verify connection details and try again. \r\n");
+            else
+            {
+                printf("Connected - IP address: %s \r\n",wifi.getIPAddress());
+                LED_D3_ON;
+            }
+        }
+    }
+}
+
+//*****************************************************************************
+//
+//! Exosite_Init
+//!
+//!  \param  None
+//!
+//!  \return 0 success; -1 failure
+//!
+//!  \brief  The function initializes the cloud connection to Exosite
+//
+//*****************************************************************************
+int Exosite_Init(TCPSocketConnection *socket)
+{
+    char strBuf[META_MARK_SIZE];
+    const unsigned char meta_server_ip[6] = {173,255,209,28,0,80};
+    uint8_t mac_status = 1;
+    uint8_t myMAC[8];
+    int i;
+    char tempCIK[CIK_LENGTH];
+
+    //check our meta mark - if it isn't there, we wipe the meta structure
+    exosite_meta_read((unsigned char *)strBuf, META_MARK_SIZE, META_MARK);
+    if (strncmp(strBuf, EXOMARK, META_MARK_SIZE))
+    {
+        memset(exo_meta, 0, META_SIZE); //erase the information currently in meta
+        exosite_meta_write((unsigned char *)meta_server_ip, 6, META_SERVER);     //store server IP
+        exosite_meta_write((unsigned char *)EXOMARK, META_MARK_SIZE, META_MARK); //store exosite mark
+    }
+
+    while(mac_status) mac_status = wifi.get_mac_address(myMAC);
+    exosite_meta_write((unsigned char *)myMAC, 17, META_UUID);
+
+    //setup some of our globals for operation
+    exositeWriteFailures = 0;
+
+    //exosite Re-init : Called after Init has been ran in the past, but maybe
+    //                  comms were down and we have to keep trying...
+    activate_device(socket);    //the moment of truth - can this device provision with the Exosite cloud?...
+    exosite_meta_read((unsigned char *)tempCIK, CIK_LENGTH, META_CIK); //sanity check on the CIK
+    for (i = 0; i < CIK_LENGTH; i++)
+    {
+        if (!(tempCIK[i] >= 'a' && tempCIK[i] <= 'f' || tempCIK[i] >= '0' && tempCIK[i] <= '9'))
+        {
+            return -1;
+        }
+    }
+    for(i=0;i<CIK_LENGTH;i++) user_info.CIK[i] = tempCIK[i];
+    user_info.validCIK = 1;
+    wifi._nvmem.write( NVMEM_USER_FILE_1_FILEID, sizeof(user_info), 0, (unsigned char *) &user_info);
+    return 0;
+}
+
+//*****************************************************************************
+//
+//! Exosite_Write
+//!
+//!  \param  pbuf - string buffer containing data to be sent
+//!          bufsize - number of bytes to send
+//!
+//!  \return 0 success; -1 failure
+//!
+//!  \brief  The function writes data to Exosite
+//
+//*****************************************************************************
+int Exosite_Write(TCPSocketConnection *socket, char * pbuf, unsigned char bufsize)
+{
+    char strBuf[10];
+    long sock = -1;
+
+    sock = connect_to_exosite(socket);
+    if(sock == -1) return(sock);
+
+// This is an example write POST...
+//  s.send('POST /api:v1/stack/alias HTTP/1.1\r\n')
+//  s.send('Host: m2.exosite.com\r\n')
+//  s.send('X-Exosite-CIK: 5046454a9a1666c3acfae63bc854ec1367167815\r\n')
+//  s.send('Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n')
+//  s.send('Content-Length: 6\r\n\r\n')
+//  s.send('temp=2')
+
+    sprintf(strBuf, "%d", (int)bufsize); //make a string for length
+
+    sendLine(socket, POSTDATA_LINE, "/onep:v1/stack/alias");
+    sendLine(socket, HOST_LINE, NULL);
+    sendLine(socket, CIK_LINE, NULL);
+    sendLine(socket, CONTENT_LINE, NULL);
+    sendLine(socket, LENGTH_LINE, strBuf);
+    //printf("Data=%s\n", pbuf);
+    socket->send_all(pbuf, bufsize); //alias=value
+    wifi._event.hci_unsolicited_event_handler();
+
+    if (0 == readResponse(socket, "204"))
+    {
+        exositeWriteFailures = 0;
+    }
+    else
+    {
+        exositeWriteFailures++;
+    }
+
+    socket->close();
+
+    if (exositeWriteFailures > 5)
+    {
+        // sometimes transport connect works even if no connection...
+        printf("ERROR %d\r\n", EXO_ERROR_WRITE);
+    }
+
+    if (!exositeWriteFailures)
+    {
+        //printf("ShowUIcode %d\n", EXO_CLIENT_RW);
+        return 0; // success
+    }
+    return 0;
+}    
+
+
+//*****************************************************************************
+//
+//! activate_device
+//!
+//!  \param  none
+//!
+//!  \return none
+//!
+//!  \brief  Calls activation API - if successful, it saves the returned
+//!          CIK to non-volatile
+//
+//*****************************************************************************
+void activate_device(TCPSocketConnection *socket)
+{
+    long sock = -1;
+    volatile int length;
+    char strLen[5];
+
+    while (sock < 0)
+    sock = connect_to_exosite(socket);
+    printf("Activating Device\n");
+
+    length = strlen(STR_VENDOR) + META_UUID_SIZE;
+    itoa(length, strLen, 10); //make a string for length
+
+    sendLine(socket, POSTDATA_LINE, "/provision/activate");
+    sendLine(socket, HOST_LINE, NULL);
+    sendLine(socket, CONTENT_LINE, NULL);
+    sendLine(socket, LENGTH_LINE, strLen);
+    sendLine(socket, VENDOR_LINE, NULL);
+
+    if (0 == readResponse(socket, "200"))
+    {
+        char strBuf[RX_SIZE];
+        unsigned char strLen, len;
+        char *p;
+        unsigned char crlf = 0;
+        unsigned char ciklen = 0;
+        char NCIK[CIK_LENGTH];
+
+        do
+        {
+            strLen = socket->receive(strBuf, RX_SIZE);
+            len = strLen;
+            p = strBuf;
+            // Find 4 consecutive \r or \n - should be: \r\n\r\n
+            while (0 < len && 4 > crlf)
+            {
+                if ('\r' == *p || '\n' == *p)
+                {
+                    ++crlf;
+                }
+                else
+                {
+                    crlf = 0;
+                }
+                ++p;
+                --len;
+            }
+
+            // The body is the CIK
+            if (0 < len && 4 == crlf && CIK_LENGTH > ciklen)
+            {
+                // TODO, be more robust - match Content-Length header value to CIK_LENGTH
+                unsigned char need, part;
+                need = CIK_LENGTH - ciklen;
+                part = need < len ? need : len;
+                strncpy(NCIK + ciklen, p, part);
+                ciklen += part;
+            }
+        } while (RX_SIZE == strLen);
+
+        if (CIK_LENGTH == ciklen)
+        {
+            exosite_meta_write((unsigned char *)NCIK, CIK_LENGTH, META_CIK);
+        }
+    }
+    else
+    {
+        printf("Activation failed\n");
+        getchar();
+    }
+    socket->close();
+}
+
+//*****************************************************************************
+//
+//! connect_to_exosite
+//!
+//!  \param  None
+//!
+//!  \return socket handle
+//!
+//!  \brief  Establishes a connection with the Exosite API server
+//
+//*****************************************************************************
+long connect_to_exosite(TCPSocketConnection *socket)
+{    
+    static unsigned char connectRetries = 0;
+    long sock;
+
+    if (connectRetries++ > 5)
+    {
+        connectRetries = 0;
+        printf("ERROR %d\r\n", EXO_ERROR_CONNECT);
+    }
+
+    const char* ECHO_SERVER_ADDRESS = "173.255.209.28"; //TODO - use DNS or check m2.exosite.com/ip to check for updates
+    const int ECHO_SERVER_PORT = 80;
+    
+    unsigned char server[META_SERVER_SIZE];
+    exosite_meta_read(server, META_SERVER_SIZE, META_SERVER);
+
+    sock = socket->connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+    if(sock < 0)
+    {
+        printf("Connection to server failed\n");
+        socket->close();
+        wait_ms(200);
+        return -1;
+    }
+    else
+    {
+        connectRetries = 0;
+        //printf("ShowUIcode %d\n", EXO_SERVER_CONNECTED);
+    }
+
+    // Success
+    //printf("success\n");
+    return sock;
+}
+
+
+//*****************************************************************************
+//
+//! readResponse
+//!
+//!  \param  socket handle, pointer to expected HTTP response code
+//!
+//!  \return 0 if match, -1 if no match
+//!
+//!  \brief  Reads first 12 bytes of HTTP response and extracts the 3 byte code
+//
+//*****************************************************************************
+int readResponse(TCPSocketConnection *socket, char * code)
+{
+    char rxBuf[12];
+    unsigned char rxLen;
+    rxLen = socket->receive(rxBuf, 12);
+//PROBLEM : more than 12 chars are printed 
+    printf("rec %s\n", rxBuf);
+    if (12 == rxLen && code[0] == rxBuf[9] && code[1] == rxBuf[10] && code[2] == rxBuf[11])
+    {
+        return 0;
+    }
+
+    return -1;
+}
+
+
+//*****************************************************************************
+//
+//! sendLine
+//!
+//!  \param  Which line type
+//!
+//!  \return socket handle
+//!
+//!  \brief  Sends data out the socket
+//
+//*****************************************************************************
+void sendLine(TCPSocketConnection *socket, unsigned char LINE, char * payload)
+{
+    char strBuf[80];
+    unsigned char strLen = 0;
+
+    switch(LINE)
+    {
+    case CIK_LINE:
+        sprintf(strBuf, "X-Exosite-CIK: %s\r\n", activeCIK);    
+        strLen = strlen(strBuf);
+        //strLen = 57;
+        //memcpy(strBuf,STR_CIK_HEADER,strLen);
+        //exosite_meta_read((unsigned char *)&strBuf[strLen], CIK_LENGTH, META_CIK);
+        //strLen += CIK_LENGTH;
+        //memcpy(&strBuf[strLen],STR_CRLF, 2);
+        //strLen += 2;
+        break;
+    case HOST_LINE:
+        strLen = 28;
+        memcpy(strBuf,STR_HOST,strLen);
+        strBuf[strLen] = NULL;
+        break;
+    case CONTENT_LINE:
+        strLen = 64;
+        memcpy(strBuf,STR_CONTENT,strLen);
+        strBuf[strLen] = NULL;
+        break;
+    case ACCEPT_LINE:
+        strLen = 58;
+        memcpy(strBuf,STR_ACCEPT,strLen);
+        memcpy(&strBuf[strLen],payload, strlen(payload));
+        strLen += strlen(payload);
+        break;
+    case LENGTH_LINE: // Content-Length: NN
+        strLen = 16;
+        memcpy(strBuf,STR_CONTENT_LENGTH,strLen);
+        memcpy(&strBuf[strLen],payload, strlen(payload));
+        strLen += strlen(payload);
+        memcpy(&strBuf[strLen],STR_CRLF, 2);
+        strLen += 2;
+        memcpy(&strBuf[strLen],STR_CRLF, 2);
+        strLen += 2;
+        strBuf[strLen] = NULL;
+        break;
+    case GETDATA_LINE:
+        strLen = 24;
+        memcpy(strBuf,STR_GET_URL,strLen);
+        memcpy(&strBuf[strLen],payload, strlen(payload));
+        strLen += strlen(payload);
+        memcpy(&strBuf[strLen],STR_HTTP, 12);
+        strLen += 12;
+        break;
+    case VENDOR_LINE:
+        strLen = strlen(STR_VENDOR);
+        memcpy(strBuf, STR_VENDOR, strLen);
+        exosite_meta_read((unsigned char *)&strBuf[strLen], META_UUID_SIZE, META_UUID);
+        strLen += META_UUID_SIZE;
+        strBuf[strLen] = NULL;
+        break;
+    case POSTDATA_LINE:
+        strLen = 5;
+        memcpy(strBuf,"POST ", strLen);
+        memcpy(&strBuf[strLen],payload, strlen(payload));
+        strLen += strlen(payload);
+        memcpy(&strBuf[strLen],STR_HTTP, 12);
+        strLen += 12;
+        strBuf[strLen] = NULL;
+        break;
+    case EMPTY_LINE:
+        strLen = 2;
+        memcpy(strBuf,STR_CRLF,strLen);
+        break;
+    default:
+        break;
+    }
+    //printf("sendLine: %s\n", strBuf);
+    socket->send_all(strBuf, strLen);
+    wifi._event.hci_unsolicited_event_handler();
+    return;
+}
+
+//*****************************************************************************
+//
+//! exosite_meta_write
+//!
+//!  \param  write_buffer - string buffer containing info to write to meta;
+//!          srcBytes - size of string in bytes; element - item from
+//!          MetaElements enum.
+//!
+//!  \return None
+//!
+//!  \brief  Writes specific meta information to meta memory.
+//
+//*****************************************************************************
+void exosite_meta_write(unsigned char * write_buffer, unsigned short srcBytes, unsigned char element)
+{
+    exosite_meta * meta_info = 0;
+
+    //TODO - do not write if the data already there is identical...
+
+    switch (element)
+    {
+        case META_CIK:
+            if (srcBytes > META_CIK_SIZE) return;
+            memcpy((char *)(exo_meta + (int)meta_info->cik), write_buffer, srcBytes); //store CIK
+            break;
+        case META_SERVER:
+            if (srcBytes > META_SERVER_SIZE) return;
+            memcpy((char *)(exo_meta + (int)meta_info->server), write_buffer, srcBytes); //store server IP
+            break;
+        case META_MARK:
+            if (srcBytes > META_MARK_SIZE) return;
+            memcpy((char *)(exo_meta + (int)meta_info->mark), write_buffer, srcBytes); //store exosite mark
+            break;
+        case META_UUID:
+            if (srcBytes > META_UUID_SIZE) return;
+            memcpy((char *)(exo_meta + (int)meta_info->uuid), write_buffer, srcBytes); //store UUID
+            break;
+        case META_MFR:
+            if (srcBytes > META_MFR_SIZE) return;
+            memcpy((char *)(exo_meta + (int)meta_info->mfr), write_buffer, srcBytes); //store manufacturing info
+            break;
+        case META_NONE:
+        default:
+            break;
+    }
+    return;
+}
+
+
+//*****************************************************************************
+//
+//! exosite_meta_read
+//!
+//!  \param  read_buffer - string buffer to receive element data; destBytes -
+//!          size of buffer in bytes; element - item from MetaElements enum.
+//!
+//!  \return None
+//!
+//!  \brief  Writes specific meta information to meta memory.
+//
+//*****************************************************************************
+void exosite_meta_read(unsigned char * read_buffer, unsigned short destBytes, unsigned char element)
+{
+    exosite_meta * meta_info = 0;
+
+    switch (element)
+    {
+        case META_CIK:
+            if (destBytes < META_CIK_SIZE) return;
+            memcpy(read_buffer, (char *)(exo_meta + (int)meta_info->cik), destBytes); //read CIK
+            break;
+        case META_SERVER:
+            if (destBytes < META_SERVER_SIZE) return;
+            memcpy(read_buffer, (char *)(exo_meta + (int)meta_info->server), destBytes); //read server IP
+            break;
+        case META_MARK:
+            if (destBytes < META_MARK_SIZE) return;
+            memcpy(read_buffer, (char *)(exo_meta + (int)meta_info->mark), destBytes); //read exosite mark
+            break;
+        case META_UUID:
+            if (destBytes < META_UUID_SIZE) return;
+            memcpy(read_buffer, (char *)(exo_meta + (int)meta_info->uuid), destBytes); //read exosite mark
+            break;
+        case META_MFR:
+            if (destBytes < META_MFR_SIZE) return;
+            memcpy(read_buffer, (char *)(exo_meta + (int)meta_info->mfr), destBytes); //read exosite mark
+            break;
+        case META_NONE:
+            default:
+            break;
+    }
+    return;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Webserver/run_exosite.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,120 @@
+#ifndef RUN_EXOSITE_H
+#define RUN_EXOSITE_H
+
+#include "TCPSocketConnection.h"
+#include "TCPSocketServer.h"
+
+extern cc3000 wifi;
+extern tUserFS user_info;
+
+#ifdef    __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+void run_exosite(TCPSocketConnection *socket);
+
+// defines
+enum UUIDInterfaceTypes
+{
+    IF_WIFI,
+    IF_ENET,
+    IF_FILE,
+    IF_HDD,
+    IF_I2C,
+    IF_GPRS,
+    IF_NONE
+};
+
+enum ExositeStatusCodes
+{
+    EXO_STATUS_OK,
+    EXO_STATUS_INIT,
+    EXO_STATUS_BAD_UUID,
+    EXO_STATUS_BAD_VENDOR,
+    EXO_STATUS_BAD_MODEL,
+    EXO_STATUS_BAD_INIT,
+    EXO_STATUS_BAD_TCP,
+    EXO_STATUS_BAD_SN,
+    EXO_STATUS_CONFLICT,
+    EXO_STATUS_BAD_CIK,
+    EXO_STATUS_NOAUTH,
+    EXO_STATUS_END
+};
+
+#define EXOSITE_VENDOR_MAXLENGTH                20
+#define EXOSITE_MODEL_MAXLENGTH                 20
+#define EXOSITE_SN_MAXLENGTH                    EXOSITE_HAL_SN_MAXLENGTH
+#define EXOSITE_DEMO_UPDATE_INTERVAL            4000// ms
+#define CIK_LENGTH                              40
+
+// --------------   META   --------------
+// defines
+#define META_SIZE                 256
+#define META_CIK_SIZE             40
+#define META_SERVER_SIZE          6
+#define META_PAD0_SIZE            2
+#define META_MARK_SIZE            8
+#define META_UUID_SIZE            17
+#define META_PAD1_SIZE            4
+#define META_RSVD_SIZE            56
+#define META_MFR_SIZE             128
+typedef struct {
+  char cik[META_CIK_SIZE];                   // our client interface key
+  char server[META_SERVER_SIZE];             // ip address of m2.exosite.com (not using DNS at this stage)
+  char pad0[META_PAD0_SIZE];                 // pad 'server' to 8 bytes
+  char mark[META_MARK_SIZE];                 // watermark
+  char uuid[META_UUID_SIZE];                 // UUID in ascii
+  char pad1[META_PAD1_SIZE];                 // pad 'uuid' to 16 bytes
+  char rsvd[META_RSVD_SIZE];                 // reserved space - pad to ensure mfr is at end of RDK_META_SIZE
+  char mfr[META_MFR_SIZE];                   // manufacturer data structure
+} exosite_meta;
+
+#define EXOMARK "exosite!"
+
+typedef enum
+{
+    META_CIK,
+    META_SERVER,
+    META_MARK,
+    META_UUID,
+    META_MFR,
+    META_NONE
+} MetaElements;
+
+
+// --------------   HAL   --------------
+// defines
+/*typedef enum
+{
+    IF_WIFI,
+    IF_ENET,
+    IF_FILE,
+    IF_HDD,
+    IF_I2C,
+    IF_NONE
+} UUIDInterfaceTypes;*/
+
+typedef enum
+{
+    EXO_ERROR_WRITE,
+    EXO_ERROR_READ,
+    EXO_ERROR_CONNECT,
+    EXO_ERROR_UNKNOWN,
+    EXO_ERROR_END
+} ExositeErrorCodes;
+
+typedef enum
+{
+    EXO_SERVER_CONNECTED,
+    EXO_CLIENT_RW,
+    EXO_UI_END
+} ExositeUICodes;
+
+#ifdef    __cplusplus
+}
+#endif // __cplusplus
+
+#endif // RUN_EXOSITE_H
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cc3000_hostdriver_mbedsocket.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/#ca8c234997c0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dbg.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,17 @@
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#include "nsdl_support.h"
+#include "mbed.h"
+
+//Debug is disabled by default
+#define DEBUG 1
+
+#if (DEBUG)
+extern Serial pc;
+#define NSDL_DEBUG(x, ...) pc.printf("[NSDL_DEBUG: %s:%d]" x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#else
+#define NSDL_DEBUG(x, ...)
+#endif
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/defLED.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,27 @@
+#ifndef DEFLED_H
+#define DEFLED_H
+
+#if (MY_BOARD == WIGO)
+#define RED_OFF        ledr = 1
+#define RED_ON         ledr = 0
+#define RED_TOGGLE     ledr = !ledr
+#define GREEN_OFF      ledg = 1
+#define GREEN_ON       ledg = 0
+#define GREEN_TOGGLE   ledg = !ledg
+#define BLUE_OFF       ledb = 1
+#define BLUE_ON        ledb = 0
+#define BLUE_TOGGLE    ledb = !ledb
+#define LED_D1_OFF     led1 = 1
+#define LED_D1_ON      led1 = 0
+#define LED_D1_TOGGLE  led1 = !led1
+#define LED_D2_OFF     led2 = 1
+#define LED_D2_ON      led2 = 0
+#define LED_D2_TOGGLE  led2 = !led2
+#define LED_D3_OFF     led3 = 1
+#define LED_D3_ON      led3 = 0
+#define LED_D3_TOGGLE  led3 = !led3
+#else
+
+#endif
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/init.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,66 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "main.h"
+#include "mbed.h"
+
+#if (MY_BOARD == WIGO)
+
+#include "NVIC_set_all_priorities.h"
+
+/**
+ *  \brief Wi-Go initialization
+ *  \param none
+ *  \return none
+ */
+void init() {
+
+    NVIC_set_all_irq_priorities(3);
+    NVIC_SetPriority(SPI0_IRQn, 0x0);     // Wi-Fi SPI interrupt must be higher priority than SysTick
+    NVIC_SetPriority(PORTA_IRQn, 0x1);
+    NVIC_SetPriority(SysTick_IRQn, 0x2);  // SysTick set to lower priority than Wi-Fi SPI bus interrupt
+    PORTA->PCR[16] |=PORT_PCR_ISF_MASK;
+    PORTA->ISFR |= (1 << 16);
+}
+
+#elif (MY_BOARD == WIFI_DIPCORTEX)
+
+/**
+ *  \brief Wifi DipCortex initialization
+ *  \param none
+ *  \return none
+ */
+void init() {
+    NVIC_SetPriority(SSP1_IRQn, 0x0);
+    NVIC_SetPriority(PIN_INT0_IRQn, 0x1);
+
+    // SysTick set to lower priority than Wi-Fi SPI bus interrupt
+    NVIC_SetPriority(SysTick_IRQn, 0x2);
+}
+
+#else
+
+/**
+ *  \brief Place here init routine for your board
+ *  \param none
+ *  \return none
+ */
+void init() {
+
+}
+
+#endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,607 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "mbed.h"
+#include "cc3000.h"
+#include "main.h"
+#include "TCPSocketConnection.h"
+#include "TCPSocketServer.h"
+#include "nsdl_support.h"
+
+using namespace mbed_cc3000;
+
+tUserFS user_info;
+
+/* cc3000 module declaration specific for user's board. Check also init() */
+#if (MY_BOARD == WIGO)
+
+#include "I2C_busreset.h"
+#include "defLED.h"
+#include "TSISensor.h"
+#include "TEMT6200.h"
+#include "WiGo_BattCharger.h"
+#include "MMA8451Q.h"
+#include "MAG3110.h"
+#include "MPL3115A2.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+#include "demo.h"
+#include "doTCPIP.h"
+#include "run_exosite.h"
+
+#define FCOUNTSPERG  4096.0F // sensor specific: MMA8451 provide 4096 counts / g in 2g mode
+#define FCOUNTSPERUT   10.0F // sensor specific: MAG3110 provide 10 counts / uT
+
+#define BATT_0          0.53
+#define BATT_100        0.63
+
+DigitalOut ledr (LED_RED);
+DigitalOut ledg (LED_GREEN);
+DigitalOut ledb (LED_BLUE);
+DigitalOut led1 (PTB8);
+DigitalOut led2 (PTB9);
+DigitalOut led3 (PTB10);
+
+cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "", "", NONE, true);
+
+TCPSocketConnection socket;
+
+Serial pc(USBTX, USBRX);
+
+// Slide sensor
+TSISensor tsi;
+
+// Systick
+Ticker systick;
+
+// Ambient light sensor : PTD5 = enable, PTB0 = analog input
+TEMT6200 ambi(PTD5, PTB0);
+
+//Wi-Go battery charger control
+WiGo_BattCharger Batt(CHRG_EN1, CHRG_EN2, CHRG_SNS_EN, CHRG_SNS, CHRG_POK, CHRG_CHG);
+
+// Accelerometer
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+
+// Magnetometer
+#define MAG3110_I2C_ADDRESS (0x0e<<1)
+MAG3110 mag(PTE0, PTE1, MAG3110_I2C_ADDRESS);
+
+// altimeter-Pressure-Temperature (apt)
+#define MPL3115A2_I2C_ADDRESS (0x60<<1)
+MPL3115A2 apt( PTE0, PTE1, MPL3115A2_I2C_ADDRESS);
+
+volatile int secondFlag;
+volatile int HsecondFlag;
+unsigned int seconds;
+unsigned int compass_type;
+unsigned short adc_sample3;
+float fcountperg = 1.0F / FCOUNTSPERG;
+float fcountperut = 1.0F / FCOUNTSPERUT;
+volatile unsigned char newData;
+volatile int server_running;
+axis6_t axis6;
+int do_mDNS = 0;
+//Device name - used for Smart config in order to stop the Smart phone configuration process
+char DevServname[] = "CC3000";
+
+void initLEDs(void)
+{
+    RED_OFF;
+    GREEN_OFF;
+    BLUE_OFF;
+    LED_D1_OFF;
+    LED_D2_OFF;
+    LED_D3_OFF;
+}
+
+void GreenStop(void)
+{
+    RED_OFF; GREEN_OFF; BLUE_OFF;
+    while(1)
+    {
+        GREEN_ON;
+        secondFlag = 0;
+        while(!secondFlag);
+        GREEN_OFF;
+        secondFlag = 0;
+        while(!secondFlag);
+    }
+}
+
+void accel_read(void)
+{
+    signed short resultx, resulty, resultz;
+    if(acc.isDataAvailable())
+    {
+        resultx = acc.readReg(0x01)<<8;
+        resultx |= acc.readReg(0x02);
+        resultx = resultx >> 2;
+        resulty = acc.readReg(0x03)<<8;
+        resulty |= acc.readReg(0x04);
+        resulty = resulty >> 2;
+        resultz = acc.readReg(0x05)<<8;
+        resultz |= acc.readReg(0x06);
+        resultz = resultz >> 2;
+        if(compass_type == NED_COMPASS)
+        {
+            axis6.acc_x = resultx;
+            axis6.acc_y = -1 * resulty; // multiple by -1 to compensate for PCB layout
+            axis6.acc_z = resultz;
+        }
+        if(compass_type == ANDROID_COMPASS)
+        {
+            axis6.acc_x = resulty; // 
+            axis6.acc_y = -1 * resultx;
+            axis6.acc_z = resultz;
+        }
+        if(compass_type == WINDOWS_COMPASS)
+        {
+            axis6.acc_x = -1 * resulty; // 
+            axis6.acc_y = resultx;
+            axis6.acc_z = resultz;
+        }
+        axis6.fax = axis6.acc_x;
+        axis6.fay = axis6.acc_y;
+        axis6.faz = axis6.acc_z;
+        axis6.fGax = axis6.fax * fcountperg;
+        axis6.fGay = axis6.fay * fcountperg;
+        axis6.fGaz = axis6.faz * fcountperg;                    
+    }
+}        
+
+void readTempAlt(void) // We don't use the fractional data
+{
+    unsigned char raw_data[2];
+    if(apt.getAltimeterRaw(&raw_data[0]))
+        axis6.alt = ((raw_data[0] << 8) | raw_data[1]);
+    if(apt.getTemperatureRaw(&raw_data[0]))
+        axis6.temp = raw_data[0];
+}
+
+void readCompass( void )
+{
+    if(mag.isDataAvailable())
+    {
+        uint8_t  mx_msb, my_msb, mz_msb;
+        uint8_t  mx_lsb, my_lsb, mz_lsb;
+
+        mx_msb = mag.readReg(0x01);
+        mx_lsb = mag.readReg(0x02);
+        my_msb = mag.readReg(0x03);
+        my_lsb = mag.readReg(0x04);
+        mz_msb = mag.readReg(0x05);
+        mz_lsb = mag.readReg(0x06);
+
+        if(compass_type == NED_COMPASS)
+        {
+            axis6.mag_y = (((mx_msb << 8) | mx_lsb));      // x & y swapped to compensate for PCB layout
+            axis6.mag_x = (((my_msb << 8) | my_lsb));
+            axis6.mag_z = (((mz_msb << 8) | mz_lsb));
+        }
+        if(compass_type == ANDROID_COMPASS)
+        {
+            axis6.mag_x = (((mx_msb << 8) | mx_lsb));
+            axis6.mag_y = (((my_msb << 8) | my_lsb));
+            axis6.mag_z = -1 * (((mz_msb << 8) | mz_lsb)); // negate to reverse axis of Z to conform to Android coordinate system
+        }
+        if(compass_type == WINDOWS_COMPASS)
+        {
+            axis6.mag_x = (((mx_msb << 8) | mx_lsb));
+            axis6.mag_y = (((my_msb << 8) | my_lsb));
+            axis6.mag_z = -1 * (((mz_msb << 8) | mz_lsb));
+        }
+        axis6.fmx = axis6.mag_x;
+        axis6.fmy = axis6.mag_y;
+        axis6.fmz = axis6.mag_z;
+        axis6.fUTmx = axis6.fmx * fcountperut;
+        axis6.fUTmy = axis6.fmy * fcountperut;
+        axis6.fUTmz = axis6.fmz * fcountperut;
+    }
+}   
+
+void axis6Print(void)
+{
+    char *compass_points[9] = {"North", "N-East", "East", "S-East", "South", "S-West", "West", "N-West", "North"};
+    signed short compass_bearing = (axis6.compass + 23) / 45;
+    printf("Compass : Roll=%-d  Pitch=%-d  Yaw=%-d [%s]\r\n", axis6.roll, axis6.pitch, axis6.yaw, compass_points[compass_bearing]);
+    printf("Accel   : X= %1.2f, Y= %1.2f, Z= %1.2f\r\n", axis6.fGax, axis6.fGay, axis6.fGaz);
+    printf("Magneto : X= %3.1f, Y= %3.1f, Z= %3.1f\r\n\r\n", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz);
+}
+
+void set_dir_LED(void)
+{
+    RED_OFF; GREEN_OFF; BLUE_OFF;
+    
+    if((axis6.compass >= 353) || (axis6.compass <= 7))
+    {
+        GREEN_ON;
+    }
+    else
+    {
+        GREEN_OFF;
+    }
+    if(((axis6.compass >= 348) && (axis6.compass <= 357)) || ((axis6.compass >= 3) && (axis6.compass <= 12)))
+    {
+        BLUE_ON;
+    }
+    else
+    {
+        BLUE_OFF;
+    }
+    if((axis6.compass >= 348) || (axis6.compass <= 12)) return;
+    if(((axis6.compass >= 268) && (axis6.compass <= 272)) || ((axis6.compass >= 88) && (axis6.compass <= 92)))
+    {
+        RED_ON;
+        return;
+    }
+    if((axis6.compass >= 178) && (axis6.compass <= 182))
+    {
+        BLUE_ON;
+        RED_ON;
+        return;
+    }
+}
+
+void SysTick_Handler(void)
+{
+    static unsigned int ttt = 1;
+    int ts;
+    ts = ttt & 0x1;
+    if(ts == 0)
+    {
+        accel_read();
+        readCompass();
+    }
+    if(ts == 1)
+    {
+        run_eCompass();
+        newData = 1; // a general purpose flag for things that need to synch to the ISR
+        axis6.timestamp++;
+        if(!server_running) set_dir_LED(); // Set the LEDs based on direction when nothing else is usng them
+    }
+    if(ttt == 50)
+    {
+        LED_D1_ON;
+        if(seconds && (seconds < 15)) calibrate_eCompass();
+        readTempAlt();
+        axis6.light = ambi.readRaw(); // Light Sensor    
+        HsecondFlag = 1; // A general purpose flag for things that need to happen every 500ms   
+    }
+    if(ttt >= 100)
+    {
+        LED_D1_OFF;
+        ttt = 1;  
+        calibrate_eCompass();
+        Batt.sense_en(1);
+        adc_sample3 = Batt.level(); 
+        Batt.sense_en(0);
+        secondFlag = 1; // A general purpose flag for things that need to happen once a second
+        HsecondFlag = 1;
+        seconds++;
+        if(!(seconds & 0x1F)) do_mDNS = 1;          
+    } else ttt++;
+}
+/*void SysTick_Handler(void)
+{
+    static unsigned int ttt = 1;
+    int ts;
+    ts = ttt & 0x3;
+    if(ts == 2) readCompass();
+    if(ts == 1) accel_read();
+    if(ts == 3)
+    {
+        run_eCompass();
+        newData = 1; // a general purpose flag for things that need to synch to the ISR
+        axis6.timestamp++;
+        if(!server_running) set_dir_LED(); // Set the LEDs based on direction when nothing else is usng them
+    }
+    if(ttt == 100)//systick = 0.005 : 100 - systick = 0.025 : 20
+    {
+        LED_D1_ON;
+        if(seconds && (seconds < 15)) calibrate_eCompass();
+        readTempAlt();
+        axis6.light = ambi.readRaw(); // Light Sensor    
+        HsecondFlag = 1; // A general purpose flag for things that need to happen every 500ms   
+    }
+    if(ttt >= 200)//systick = 0.005 : 200 - systick = 0.025 : 40
+    {
+        LED_D1_OFF;
+        ttt = 1;  
+        calibrate_eCompass();
+        Batt.sense_en(1);
+        adc_sample3 = Batt.level(); 
+        Batt.sense_en(0);
+        secondFlag = 1; // A general purpose flag for things that need to happen once a second
+        HsecondFlag = 1;
+        seconds++;
+        if(!(seconds & 0x1F)) do_mDNS = 1;
+    } else ttt++;
+}*/
+
+#elif (MY_BOARD == WIFI_DIPCORTEX)
+cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), PIN_INT0_IRQn);
+Serial pc(UART_TX, UART_RX);
+#else
+
+#endif
+
+#ifndef CC3000_UNENCRYPTED_SMART_CONFIG
+  const uint8_t smartconfigkey[] = {0x73,0x6d,0x61,0x72,0x74,0x63,0x6f,0x6e,0x66,0x69,0x67,0x41,0x45,0x53,0x31,0x36};
+#else
+  const uint8_t smartconfigkey = 0;
+#endif
+
+/**
+ *  \brief Print cc3000 information
+ *  \param none
+ *  \return none
+ */
+void print_cc3000_info() {
+    uint8_t myMAC[8];
+    uint8_t spVER[5];
+    wifi._nvmem.read_sp_version(spVER);
+    printf("SP Version (TI) : %d %d %d %d %d\r\n", spVER[0], spVER[1], spVER[2], spVER[3], spVER[4]);
+    printf("MAC address + cc3000 info \r\n");
+    wifi.get_user_file_info((uint8_t *)&user_info, sizeof(user_info));
+    wifi.get_mac_address(myMAC);
+    printf(" MAC address %02x:%02x:%02x:%02x:%02x:%02x \r\n \r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]);
+
+    printf(" FTC        %i \r\n",user_info.FTC);
+    printf(" PP_version %i.%i \r\n",user_info.PP_version[0], user_info.PP_version[1]);
+    printf(" SERV_PACK  %i.%i \r\n",user_info.SERV_PACK[0], user_info.SERV_PACK[1]);
+    printf(" DRV_VER    %i.%i.%i \r\n",user_info.DRV_VER[0], user_info.DRV_VER[1], user_info.DRV_VER[2]);
+    printf(" FW_VER     %i.%i.%i \r\n",user_info.FW_VER[0], user_info.FW_VER[1], user_info.FW_VER[2]);
+}
+
+/**
+ *  \brief Connect to SSID with a timeout
+ *  \param ssid     Name of SSID
+ *  \param key      Password
+ *  \param sec_mode Security mode
+ *  \return none
+ */
+void connect_to_ssid(char *ssid, char *key, unsigned char sec_mode) {
+    printf("Connecting to SSID: %s. Timeout is 10s. \r\n",ssid);
+    if (wifi.connect_to_AP((uint8_t *)ssid, (uint8_t *)key, sec_mode) == true) {
+        printf(" Connected. \r\n");
+    } else {
+        printf(" Connection timed-out (error). Please restart. \r\n");
+        while(1);
+  }
+}
+
+/**
+ *  \brief Connect to SSID without security
+ *  \param ssid Name of SSID
+ *  \return none
+ */
+void connect_to_ssid(char *ssid) {
+    wifi.connect_open((uint8_t *)ssid);
+}
+
+/**
+ *  \brief First time configuration
+ *  \param none
+ *  \return none
+ */
+void do_FTC(void) {
+    printf("Running First Time Configuration \r\n");
+    wifi.start_smart_config(smartconfigkey);
+    while (wifi.is_dhcp_configured() == false) {
+         wait_ms(500);
+         printf("Waiting for dhcp to be set. \r\n");
+    }
+    user_info.FTC = 1;
+    wifi.set_user_file_info((uint8_t *)&user_info, sizeof(user_info));
+    wifi._wlan.stop();
+    printf("FTC finished. \r\n");
+}
+
+/**
+ *  \brief TCP server demo
+ *  \param  none
+ *  \return int
+ */
+int main() {
+    int loop;
+    int temp;
+    unsigned int oldseconds;
+
+    //Board dependent init
+    init();
+
+    // Initalize global variables
+    axis6.packet_id = 1;
+    axis6.timestamp = 0;
+    axis6.acc_x = 0;
+    axis6.acc_y = 0;
+    axis6.acc_z = 0;
+    axis6.mag_x = 0;
+    axis6.mag_y = 0;
+    axis6.mag_z = 0;
+    axis6.roll = 0;
+    axis6.pitch = 0;
+    axis6.yaw = 0;
+    axis6.compass = 0;      
+    axis6.alt = 0;
+    axis6.temp = 0;
+    axis6.light = 0;
+    compass_type = ANDROID_COMPASS;
+    seconds = 0;
+    server_running = 1;
+    newData = 0;    
+    secondFlag = 0;
+    HsecondFlag = 0;
+    GREEN_ON;
+
+    // Unlock I2C bus if blocked by a device
+    I2C_busreset();
+
+    pc.baud(115200);
+
+    // set current to 500mA since we're turning on the Wi-Fi
+    Batt.init(CHRG_500MA);
+
+    //Init LEDs
+    initLEDs();
+    // Read the Magnetometer a couple of times to initalize
+    for(loop=0 ; loop < 5 ; loop++)
+    {
+        temp = mag.readReg(0x01);
+        temp = mag.readReg(0x02);
+        temp = mag.readReg(0x03);
+        temp = mag.readReg(0x04);
+        temp = mag.readReg(0x05);
+        temp = mag.readReg(0x06);
+        wait_ms(50);
+    }
+
+    init_eCompass();
+
+    // Start Ticker
+    systick.attach(&SysTick_Handler, 0.01);
+    // Trigger a WLAN device
+    wifi.init();
+    //wifi.start(0);
+    printf("CC3000 Wi-Go IOT ARM Sensinode demo.\r\n");
+    print_cc3000_info();
+    server_running = 1;
+    newData = 0;    
+    GREEN_ON;
+
+    if(!user_info.FTC)
+    {
+        do_FTC(); // Call First Time Configuration if SmartConfig has not been run
+        printf("Please restart your board. \r\n");
+        GreenStop();
+    }
+
+    // Wait for slider touch
+    printf("\r\nUse the slider to start an application.\r\n");
+    printf("Releasing the slider for more than 3 seconds\r\nwill start the chosen application.\r\n");
+    printf("Touching the slider within the 3 seconds\r\ntimeframe allows you to re-select an application.\r\n");
+    printf("\r\nThe RGB LED indicates the selection:\r\n");
+    printf("ORANGE - Erase all profiles.\r\n");
+    printf("PURPLE - Force SmartConfig.\r\n");
+    printf("BLUE   - Webserver displaying live sensor data.\r\n");
+    printf("RED    - ARM Sensinode LWM2M client.\r\n");
+    printf("GREEN  - Android sensor fusion app.\r\n");
+    while( tsi.readPercentage() == 0 )
+    {
+        RED_ON;
+        wait(0.2);
+        RED_OFF;
+        wait(0.2);
+    }
+    RED_OFF;
+
+    oldseconds = seconds;
+    loop = 100;
+    temp = 0;
+    // Read slider as long as it is touched.
+    // If released for more than 3 seconds, exit
+    while((loop != 0) || ((seconds - oldseconds) < 3))
+    {
+        loop = tsi.readPercentage() * 100;
+        if(loop != 0)
+        {
+            oldseconds = seconds;
+            temp = loop;
+        }
+        if(temp > 80)
+        {
+             RED_ON; GREEN_ON; BLUE_OFF; //Orange
+        }
+        else if(temp > 60)
+        {
+             RED_ON; GREEN_OFF; BLUE_ON; //Purple
+        }
+        else if(temp > 40)
+        {
+            RED_OFF; GREEN_OFF; BLUE_ON; //Blue
+        }
+        else if(temp > 20)
+        {
+            RED_ON; GREEN_OFF; BLUE_OFF; //Red
+        }
+        else
+        {
+            RED_OFF; GREEN_ON; BLUE_OFF; //Green
+        }
+    }
+    RED_OFF; GREEN_OFF; BLUE_OFF;
+
+    // Execute the user selected application
+    if(temp > 80) // Erase all profiles
+    {
+        server_running = 1;
+        RED_OFF; GREEN_OFF; BLUE_OFF;
+        printf("\r\nErasing all wireless profiles. \r\n");
+        wifi.delete_profiles();
+        wifi.stop();
+        printf("Finished. Please restart your board. \r\n");
+        GreenStop();
+    }
+
+    if(temp > 60) // Force SmartConfig
+    {
+        server_running = 1;
+        RED_OFF; GREEN_OFF; BLUE_OFF;
+        printf("\r\nStarting Smart Config configuration. \r\n");
+        wifi.start_smart_config(smartconfigkey);
+        while (wifi.is_dhcp_configured() == false)
+        {
+            wait_ms(500);
+            printf("Waiting for dhcp to be set. \r\n");
+        }
+        printf("Finished. Please restart your board. \r\n");
+        GreenStop();
+    }
+
+    RED_OFF; GREEN_OFF; BLUE_OFF; 
+
+    printf("\r\nAttempting SSID Connection. \r\n");
+    if (wifi.connect() == -1) {
+        printf("Failed to connect. Please verify connection details and try again. \r\n");
+    } else {
+        printf("Connected - IP address: %s \r\n",wifi.getIPAddress());
+    }
+    LED_D3_ON;
+
+    server_running = 0;
+        
+    // Start the selected application
+    if(temp > 40) // Run Webserver
+    {
+        compass_type = NED_COMPASS;
+        init_eCompass();
+        seconds = 0;
+        demo_wifi_main();
+    }
+    if(temp > 20) // Sensinode LWM2M client
+    {
+        compass_type = NED_COMPASS;
+        init_eCompass();
+        seconds = 0;
+        nsdl_run();
+    }
+    init_eCompass();
+    seconds = 0;
+    // Run TCP/IP Connection to host - Sensor Fusion App
+    runTCPIPserver();
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,32 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef MAIN_H
+#define MAIN_H
+
+#define WIGO           1
+#define WIFI_DIPCORTEX 2
+#define UNDEFINED      3
+
+#define MY_BOARD WIGO
+
+ // Default SSID Settings
+#define AP_KEY       "test"
+#define AP_SECURITY  WPA2            // WPA2 must be enabled for use with iPhone or Android phone hotspot!
+#define SSID         "test"
+
+void init();
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/673126e12c73
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nanoservice_client_1_12.lib	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/zdshelby/code/nanoservice_client_1_12/#14a9b0f4b9d6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nsdl_run.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,174 @@
+#include "mbed.h"
+#include "cc3000.h"
+//#include "C12832_lcd.h"
+#include "nsdl_support.h"
+#include "dbg.h"
+// Include various resources
+//#include "temperature.h"
+//#include "light.h"
+//#include "gps.h"
+//#include "relay.h"
+#include "UDPSocket.h"
+#include "Endpoint.h"
+
+//static C12832_LCD lcd;
+//Serial pc(USBTX, USBRX); // tx, rx
+extern Serial pc;
+
+// ****************************************************************************
+// Configuration section
+
+// Ethernet configuration
+/* Define this to enable DHCP, otherwise manual address configuration is used */
+#define DHCP
+
+// default timeout values for DHCP, ARP, keepalive, disable socket timeout
+uint32_t dhcp = 14400;
+uint32_t arp = 3600;
+uint32_t keep_alive = 10;
+uint32_t inactivity = 0;
+int32_t to_rtn;
+
+/* Manual IP configurations, if DHCP not defined */
+#define IP      "10.45.0.206"
+#define MASK    "255.255.255.0"
+#define GW      "10.45.0.1"
+
+// NSP configuration
+/* Change this IP address to that of your NanoService Platform installation */
+//static const char* NSP_ADDRESS = "192.168.1.220"; /* Arndale board running NSP on local network for Hackathon */ 
+static const char* NSP_ADDRESS = "217.140.101.20"; /* public mbed demo server */ 
+static const int NSP_PORT = 5683;
+char endpoint_name[16] = "mbed-TESTNEW";
+uint8_t ep_type[] = {"mbed_device"};
+uint8_t lifetime_ptr[] = {"120000"}; //30+ hours 
+
+// ****************************************************************************
+// Ethernet initialization
+
+// EthernetInterface eth;
+extern cc3000 wifi;
+
+// this modified to startup as an option in the Wi-Go demo
+
+static void ethernet_init()
+{
+    char mbed_uid[33]; // for creating unique name for the board
+
+// set timeout values to disable socket timeout  
+    to_rtn = wifi._netapp.timeout_values(&dhcp, &arp, &keep_alive, &inactivity);
+    pc.printf("timeout set: %d\r\n", to_rtn);
+
+    /* Initialize network */
+//#ifdef DHCP
+//    NSDL_DEBUG("DHCP in use\r\n");
+//    eth.init();
+//#else
+//    eth.init(IP, MASK, GW);
+//#endif
+//    if(eth.connect(30000) == 0)
+//        pc.printf("Connect OK\n\r");
+
+//    mbed_interface_uid(mbed_uid);
+    mbed_uid[32] = '\0';
+    strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
+
+//    lcd.locate(0,11);
+//    lcd.printf("IP:%s", eth.getIPAddress());
+
+    NSDL_DEBUG("IP Address:%s ", wifi.getIPAddress());
+}
+
+// ****************************************************************************
+// NSP initialization
+
+UDPSocket server;
+Endpoint nsp;
+
+static void nsp_init()
+{
+    server.init();
+    server.bind(NSP_PORT);
+
+    nsp.set_address(NSP_ADDRESS, NSP_PORT);
+    
+    NSDL_DEBUG("name: %s", endpoint_name);
+    NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
+
+//    lcd.locate(0,22);
+//    lcd.printf("EP name:%s\n", endpoint_name);
+}
+
+// ****************************************************************************
+// Resource creation
+
+static int create_resources()
+{
+    sn_nsdl_resource_info_s *resource_ptr = NULL;
+    sn_nsdl_ep_parameters_s *endpoint_ptr = NULL;
+    
+    NSDL_DEBUG("Creating resources");
+
+    /* Create resources */
+    resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s));
+    if(!resource_ptr)
+        return 0;
+    memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s));
+
+    resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s));
+    if(!resource_ptr->resource_parameters_ptr)
+    {
+        nsdl_free(resource_ptr);
+        return 0;
+    }
+    memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
+
+    // Static resources
+    nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0,  (uint8_t*) "Sensinode", sizeof("Sensinode")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0,  (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1);
+
+    // Dynamic resources
+//    create_temperature_resource(resource_ptr);
+//    create_light_resource(resource_ptr);
+//    create_gps_resource(resource_ptr);
+//    create_relay_resource(resource_ptr);
+
+        /* Register with NSP */
+    endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
+    if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
+        pc.printf("NSP registering failed\r\n");
+    else
+        pc.printf("NSP registering OK\r\n");
+    nsdl_clean_register_endpoint(&endpoint_ptr);
+
+    nsdl_free(resource_ptr->resource_parameters_ptr);
+    nsdl_free(resource_ptr);
+    return 1;
+}
+
+// ****************************************************************************
+// Program entry point
+
+void nsdl_run()
+{
+//    lcd.cls();
+//    lcd.locate(0,0);
+//    lcd.printf("mbed NanoService demo");
+    NSDL_DEBUG("ARM mbed NanoService Demo on Wi-Go for IoT World Hackathon\n");
+    
+    // Initialize Ethernet interface first
+    ethernet_init();
+    
+    // Initialize NSP node
+    nsp_init();
+    
+    // Initialize NSDL stack
+    nsdl_init();
+    
+    // Create NSDL resources
+    create_resources();
+    
+    // Run the NSDL event loop (never returns)
+    nsdl_event_loop();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nsdl_support.cpp	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,170 @@
+// NSDL library support functions
+
+#include "mbed.h"
+#include "nsdl_support.h"
+#include "mbed.h"
+//#include "rtos.h"
+//put re-registration in timeout loop instead of thread
+#include "cc3000.h"
+#include "UDPSocket.h"
+#include "Endpoint.h"
+
+extern Serial pc;
+extern cc3000 wifi;
+extern Endpoint nsp;
+extern UDPSocket server;
+extern char endpoint_name[16];
+extern uint8_t ep_type[];
+extern uint8_t lifetime_ptr[];
+
+/* The number of seconds between NSP registration messages */
+#define RD_UPDATE_PERIOD  60
+
+void *nsdl_alloc(uint16_t size)
+{
+    return malloc(size);
+}
+
+void nsdl_free(void* ptr_to_free)
+{
+    free(ptr_to_free);
+}
+
+/*
+ * Create a static resoure
+ * Only get is allowed
+ */
+void nsdl_create_static_resource(sn_nsdl_resource_info_s *resource_structure, uint16_t pt_len, uint8_t *pt, uint16_t rpp_len, uint8_t *rpp_ptr, uint8_t *rsc, uint16_t rsc_len)
+{
+    resource_structure->access = SN_GRS_GET_ALLOWED;
+    resource_structure->mode = SN_GRS_STATIC;
+    resource_structure->pathlen = pt_len;
+    resource_structure->path = pt;
+    resource_structure->resource_parameters_ptr->resource_type_len = rpp_len;
+    resource_structure->resource_parameters_ptr->resource_type_ptr = rpp_ptr;
+    resource_structure->resource = rsc;
+    resource_structure->resourcelen = rsc_len;
+    sn_nsdl_create_resource(resource_structure);
+}
+
+void nsdl_create_dynamic_resource(sn_nsdl_resource_info_s *resource_structure, uint16_t pt_len, uint8_t *pt, uint16_t rpp_len, uint8_t *rpp_ptr, uint8_t is_observable, sn_grs_dyn_res_callback_t callback_ptr, int access_right)
+{
+    resource_structure->access = (sn_grs_resource_acl_e)access_right;
+    resource_structure->resource = 0;
+    resource_structure->resourcelen = 0;
+    resource_structure->sn_grs_dyn_res_callback = callback_ptr;
+    resource_structure->mode = SN_GRS_DYNAMIC;
+    resource_structure->pathlen = pt_len;
+    resource_structure->path = pt;
+    resource_structure->resource_parameters_ptr->resource_type_len = rpp_len;
+    resource_structure->resource_parameters_ptr->resource_type_ptr = rpp_ptr;
+    resource_structure->resource_parameters_ptr->observable = is_observable;
+    sn_nsdl_create_resource(resource_structure);
+}
+
+sn_nsdl_ep_parameters_s* nsdl_init_register_endpoint(sn_nsdl_ep_parameters_s *endpoint_structure, uint8_t* name, uint8_t* typename_ptr, uint8_t *lifetime_ptr)
+{
+    if (NULL == endpoint_structure)
+    {   
+        endpoint_structure = (sn_nsdl_ep_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_ep_parameters_s));
+    }
+    if (endpoint_structure)
+    {
+        memset(endpoint_structure, 0, sizeof(sn_nsdl_ep_parameters_s));
+        endpoint_structure->endpoint_name_ptr = name;
+        endpoint_structure->endpoint_name_len = strlen((char*)name);
+        endpoint_structure->type_ptr = typename_ptr;
+        endpoint_structure->type_len =  strlen((char*)typename_ptr);
+        endpoint_structure->lifetime_ptr = lifetime_ptr;
+        endpoint_structure->lifetime_len =  strlen((char*)lifetime_ptr);
+    }
+    return endpoint_structure;
+}
+
+void nsdl_clean_register_endpoint(sn_nsdl_ep_parameters_s **endpoint_structure)
+{
+    if (*endpoint_structure)
+    {
+        nsdl_free(*endpoint_structure);
+        *endpoint_structure = NULL;
+    }
+}
+
+static uint8_t tx_cb(sn_nsdl_capab_e protocol, uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr)
+{
+    pc.printf("TX callback!\n\rSending %d bytes\r\n", data_len);
+
+    if(server.sendTo(nsp, (char*)data_ptr, data_len) != data_len)
+        pc.printf("sending failed\n\r");
+
+    return 1;
+}
+
+static uint8_t rx_cb(sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr)
+{
+    pc.printf("RX callback!\r\n");
+    return 0;
+}
+
+static void registration_update_thread(void const *args)
+{
+    sn_nsdl_ep_parameters_s *endpoint_ptr = NULL;
+
+    while(true)
+    {
+        wait(RD_UPDATE_PERIOD);
+        endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
+        if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
+            pc.printf("NSP re-registering failed\r\n");
+        else
+            pc.printf("NSP re-registering OK\r\n");
+        nsdl_clean_register_endpoint(&endpoint_ptr);
+    }
+}
+
+void nsdl_init()
+{
+    uint8_t nsp_addr[4];
+    sn_nsdl_mem_s memory_cbs;
+
+    /* Initialize libNsdl */
+    memory_cbs.sn_nsdl_alloc = &nsdl_alloc;
+    memory_cbs.sn_nsdl_free = &nsdl_free;
+    if(sn_nsdl_init(&tx_cb, &rx_cb, &memory_cbs) == -1)
+        pc.printf("libNsdl init failed\r\n");
+    else
+        pc.printf("libNsdl init done\r\n");
+
+    /* Set nsp address for library */
+    set_NSP_address(nsp_addr, 5683, SN_NSDL_ADDRESS_TYPE_IPV4);
+}
+
+void nsdl_event_loop()
+{
+//    Thread registration_thread(registration_update_thread);
+//put re-registration in timeout loop instead of thread
+
+    sn_nsdl_addr_s received_packet_address;
+    uint8_t received_address[4];
+    char buffer[1024];
+    Endpoint from;
+
+    memset(&received_packet_address, 0, sizeof(sn_nsdl_addr_s));
+    received_packet_address.addr_ptr = received_address;
+
+    while(1)
+    {
+        int n = server.receiveFrom(from, buffer, sizeof(buffer));
+        if (n < 0)
+        {
+            pc.printf("Socket error %d\n\r", n);
+        }
+        else
+        {   
+            pc.printf("Received %d bytes\r\n", n);
+            sn_nsdl_process_coap((uint8_t*)buffer, n, &received_packet_address);
+        }
+    }
+}
+
+            
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nsdl_support.h	Fri Jun 13 18:00:38 2014 +0000
@@ -0,0 +1,25 @@
+// Support functions for the NSDL library
+
+#ifndef NSDL_SUPPORT_H
+#define NSDL_SUPPORT_H
+
+#include "mbed.h"
+#include <stdint.h>
+#include "sn_nsdl.h"
+#include "sn_coap_header.h"
+#include "sn_coap_protocol.h"
+#include "sn_nsdl_lib.h"
+
+typedef uint8_t (*sn_grs_dyn_res_callback_t)(sn_coap_hdr_s *, sn_nsdl_addr_s *, sn_proto_info_s *);
+
+extern "C" void *nsdl_alloc(uint16_t size);
+extern "C" void nsdl_free(void* ptr_to_free);
+void nsdl_create_static_resource(sn_nsdl_resource_info_s *resource_structure, uint16_t pt_len, uint8_t *pt, uint16_t rpp_len, uint8_t *rpp_ptr, uint8_t *rsc, uint16_t rsc_len);
+void nsdl_create_dynamic_resource(sn_nsdl_resource_info_s *resource_structure, uint16_t pt_len, uint8_t *pt, uint16_t rpp_len, uint8_t *rpp_ptr, uint8_t is_observable, sn_grs_dyn_res_callback_t callback_ptr, int access_right);
+sn_nsdl_ep_parameters_s* nsdl_init_register_endpoint(sn_nsdl_ep_parameters_s *endpoint_structure, uint8_t* name, uint8_t* ypename_ptr, uint8_t *lifetime_ptr);
+void nsdl_clean_register_endpoint(sn_nsdl_ep_parameters_s **endpoint_structure);
+void nsdl_init();
+void nsdl_event_loop();
+void nsdl_run();
+
+#endif // NSDL_SUPPORT_H