Thermometer connected to internet

Dependencies:   BME280 EthernetInterface FXOS8700Q HTTPClient-wolfSSL NTPClient NetworkAPI OAuth4Tw TSL2561_I2C eCompass_FPU_Lib mbed-rtos mbed wolfSSL

Fork of TCP_Server_Example by Roy van Dam

Files at this revision

API Documentation at this revision

Comitter:
zeus3110
Date:
Sun Sep 27 11:04:54 2015 +0000
Parent:
11:90554d22ade5
Commit message:
Network thermometer test program

Changed in this revision

BME280.lib Show annotated file Show diff for this revision Revisions of this file
Compass.cpp Show annotated file Show diff for this revision Revisions of this file
EnvServer.cpp Show annotated file Show diff for this revision Revisions of this file
EnvServer.h Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
FXOS8700Q.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
NTPClient.lib Show annotated file Show diff for this revision Revisions of this file
OAuth4Tw.lib Show annotated file Show diff for this revision Revisions of this file
OAuthKey.h Show annotated file Show diff for this revision Revisions of this file
Port.h Show annotated file Show diff for this revision Revisions of this file
Sensor.cpp Show annotated file Show diff for this revision Revisions of this file
Sensor.h Show annotated file Show diff for this revision Revisions of this file
StatusLED.cpp Show annotated file Show diff for this revision Revisions of this file
StatusLED.h Show annotated file Show diff for this revision Revisions of this file
TSL2561_I2C.lib Show annotated file Show diff for this revision Revisions of this file
Twitter.cpp Show annotated file Show diff for this revision Revisions of this file
Twitter.h Show annotated file Show diff for this revision Revisions of this file
eCompass_FPU_Lib.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib 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
wolfSSL.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 90554d22ade5 -r 12369ee344ab BME280.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME280.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/MACRUM/code/BME280/#ddcaa259e65b
diff -r 90554d22ade5 -r 12369ee344ab Compass.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Compass.cpp	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,115 @@
+#include "mbed.h"
+#include "FXOS8700Q.h"
+#include "eCompass_Lib.h"
+#include "rtos.h"
+//#include "MotionSensorDtypes.h"
+
+
+FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+
+DigitalOut gpo(D0);
+DigitalOut led(LED_RED);
+eCompass compass;
+
+//void calibrate_thread(void const *argument);
+//void print_thread(void const *argument);
+//void compass_thread(void const *argument);
+
+
+
+extern axis6_t axis6;
+extern uint32_t seconds;
+extern uint32_t compass_type; // optional, NED compass is default
+extern int32_t tcount;
+extern uint8_t cdebug;
+int  l = 0;
+volatile int sflag = 0;
+
+MotionSensorDataCounts mag_raw;
+MotionSensorDataCounts acc_raw;
+
+void hal_map( MotionSensorDataCounts * acc_raw, MotionSensorDataCounts * mag_raw)
+{
+int16_t t;
+// swap and negate X & Y axis
+t = acc_raw->x;
+acc_raw->x = acc_raw->y * -1;
+acc_raw->y = t * -1;
+// swap mag X & Y axis
+t = mag_raw->x;
+mag_raw->x = mag_raw->y;
+mag_raw->y = t;
+// negate mag Z axis
+mag_raw->z *= -1;
+}
+
+//
+// Print data values for debug
+//
+void debug_print(void)
+{
+    // Some useful printf statements for debug
+    printf("roll=%d, pitch=%d, yaw=%d\r\n", axis6.roll, axis6.pitch, axis6.yaw);
+    printf("Acc: X= %2.3f Y= %2.3f Z= %2.3f    ", axis6.fGax, axis6.fGay, axis6.fGaz);
+    printf("Mag: X= %4.1f Y= %4.1f Z= %4.1f\r\n\r\n", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz);
+    printf("Quaternion: Q0= %1.4f Q1= %1.4f Q2= %1.4f Q3= %1.4f\r\n\r\n", axis6.q0, axis6.q1, axis6.q2, axis6.q3); 
+}
+
+
+void compass_thread(void const *argument) {
+
+    // get raw data from the sensors
+    acc.getAxis( acc_raw);
+    mag.getAxis( mag_raw);
+    if(tcount) compass.run( acc_raw, mag_raw); // calculate the eCompass
+    if(l++ >= 50) { // take car of business once a second
+        seconds++;
+        sflag = 1;
+        compass.calibrate();
+        debug_print();
+        l = 0;
+        led = !led;
+        }
+    tcount++;
+}
+ 
+/*  
+void calibrate_thread(void const *argument) {
+    while (true) {
+        // Signal flags that are reported as event are automatically cleared.
+        Thread::signal_wait(0x1);
+        compass.calibrate(); // re-calibrate the eCompass every second
+    }
+}
+ 
+
+  
+void print_thread(void const *argument) {
+    while (true) {
+        // Signal flags that are reported as event are automatically cleared.
+        Thread::signal_wait(0x1);
+        debug_print(); // re-calibrate the eCompass every second
+    }
+}
+ */            
+
+int compass_main() {
+
+
+RtosTimer compass_timer(compass_thread, osTimerPeriodic);
+
+//cdebug = 1;  // uncomment to disable compass
+printf("\r\n\n\n\n\n\n\n");
+printf("Who AM I= %X\r\n", acc.whoAmI());
+acc.enable();
+
+
+acc.getAxis( acc_raw);
+mag.getAxis( mag_raw);
+
+compass_timer.start(20); // Run the Compass every 20ms
+    while(1) {
+        Thread::wait(osWaitForever);
+    }
+}
diff -r 90554d22ade5 -r 12369ee344ab EnvServer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EnvServer.cpp	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,116 @@
+#include "EnvServer.h"
+#include "Sensor.h"
+
+Select select;
+tcp::Socket server;
+tcp::Socket client[MAX_CLIENTS];
+tcp::Socket *socket = NULL;
+
+void EnvServer(void const *arg)
+{
+    int result = 0;
+    int index = 0;
+    int num=0;
+    char SendBuf[16];
+    network::Buffer buffer(256);
+    //std::string message("Hello world!");
+
+    // Configure the server socket (assume everty thing works)
+    server.open();
+    server.bind(WAIT_PORT);
+    server.listen(MAX_CLIENTS);
+    printf("Start waiting ...\r\n");
+    
+    // Add sockets to the select api
+    select.set(&server, Select::Read);
+    for (index = 0; index < MAX_CLIENTS; index++) {
+        select.set(&client[index], Select::Read);
+    }
+
+    do {
+        // Wait for activity
+        result = select.wait();
+        if (result < -1) {
+            printf("Failed to select\n\r");
+            break;
+        }
+
+        // Get the first socket
+        socket = (tcp::Socket *)select.getReadable();
+
+        for (; socket != NULL; socket = (tcp::Socket *)select.getReadable()) {
+            // Check if there was a connection request.
+            if (socket->getHandle() == server.getHandle()) {
+                // Find an unused client
+                for (index = 0; index < MAX_CLIENTS; index++) {
+                    if (client[index].getStatus() == network::Socket::Closed) {
+                        break;
+                    }
+                }
+
+                // Maximum connections reached
+                if (index == MAX_CLIENTS) {
+                    printf("Maximum connections reached\n\r");
+                    continue;
+                }
+
+                // Accept the client
+                socket->accept(client[index]);
+                printf("Client connected %s:%d\n\r",
+                       client[index].getRemoteEndpoint().getAddress().toString().c_str(),
+                       client[index].getRemoteEndpoint().getPort());
+
+                // Send a nice message to the client
+                //client[index].write((void *)message.data(), message.size());
+                continue;
+            }
+
+            // It was not the server socket, so it must be a client talking to us.
+            num=socket->read(buffer);
+            switch (num) {
+                case 0:
+                    // Remote end disconnected
+                    printf("Client disconnected %s:%d\n\r",
+                           socket->getRemoteEndpoint().getAddress().toString().c_str(),
+                           socket->getRemoteEndpoint().getPort());
+
+                    // Close socket
+                    socket->close();
+                    break;
+
+                case -1:
+                    printf("Error while reading data from socket\n\r");
+                    socket->close();
+                    break;
+
+                default:
+                    printf("Message from %s:%d\n\r",
+                           socket->getRemoteEndpoint().getAddress().toString().c_str(),
+                           socket->getRemoteEndpoint().getPort());
+
+                    //command
+                    if(strcmp((char *)buffer.data(),TEMP_CMD)==0) {
+                        printf("Temperature:\r\n");
+                        sprintf(SendBuf,"%2.2f",pSensor->getTemperature());
+                    } else if(strcmp((char *)buffer.data(),HUMIDITY_CMD)==0) {
+                        printf("Humidity:\r\n");
+                        sprintf(SendBuf,"%3.2f",pSensor->getHumidity());
+                    } else if(strcmp((char *)buffer.data(),PRESSURE_CMD)==0) {
+                        printf("Pressure:\r\n");
+                        sprintf(SendBuf,"%4.2f",pSensor->getPressure());
+                    } else if(strcmp((char *)buffer.data(),ILLUM_CMD)==0) {
+                        printf("Illuminance:\r\n");
+                        sprintf(SendBuf,"%5.2f",pLumSensor->getLux());
+                    } else {
+                        printf("Unknown command:\r\n");
+                        sprintf(SendBuf,"NG");
+                    }
+
+                    socket->write((void *)SendBuf,strlen(SendBuf));
+
+                    printf("Command:%s Result:%s\n\r", (char *)buffer.data(),SendBuf);
+            }
+        }
+
+    } while (server.getStatus() == network::Socket::Listening);
+}
diff -r 90554d22ade5 -r 12369ee344ab EnvServer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EnvServer.h	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,30 @@
+#ifndef ENV_SERVER_H
+#define ENV_SERVER_H
+
+#include "mbed.h"
+
+#include "NetworkAPI/buffer.hpp"
+#include "NetworkAPI/select.hpp"
+#include "NetworkAPI/ip/address.hpp"
+#include "NetworkAPI/tcp/socket.hpp"
+using namespace network;
+
+#define MAX_CLIENTS 2
+#define WAIT_PORT 12345
+
+#define TEMP_CMD "TMP"
+#define HUMIDITY_CMD "HMD"
+#define PRESSURE_CMD "PRS"
+#define ILLUM_CMD "ILM"
+
+extern Select select;
+extern tcp::Socket server;
+extern tcp::Socket client[MAX_CLIENTS];
+extern tcp::Socket *socket;
+
+void EnvServer(void const *arg);
+
+
+#endif
+
+
diff -r 90554d22ade5 -r 12369ee344ab EthernetInterface.lib
--- a/EthernetInterface.lib	Sat Nov 15 21:46:59 2014 +0000
+++ b/EthernetInterface.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#de796e2a5e98
+http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r 90554d22ade5 -r 12369ee344ab FXOS8700Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXOS8700Q.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
diff -r 90554d22ade5 -r 12369ee344ab HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ban4jp/code/HTTPClient-wolfSSL/#81e61bd85dae
diff -r 90554d22ade5 -r 12369ee344ab NTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ban4jp/code/NTPClient/#15c04f752381
diff -r 90554d22ade5 -r 12369ee344ab OAuth4Tw.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OAuth4Tw.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ban4jp/code/OAuth4Tw/#5146becb651f
diff -r 90554d22ade5 -r 12369ee344ab OAuthKey.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OAuthKey.h	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,10 @@
+#ifndef OAUTHKEY_H
+#define OAUTHKEY_H
+
+// OAuthKey
+OAuth4Tw oa4t("xxx", // Consumer key
+              "xxx", // Consumer secret
+              "xxx", // Access token
+              "xxx"); // Access token secret
+
+#endif
\ No newline at end of file
diff -r 90554d22ade5 -r 12369ee344ab Port.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Port.h	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,16 @@
+#ifndef PORT_H
+#define PORT_H
+
+// I2C Port
+#define I2C_SCL PTE24
+#define I2C_SDA PTE25 
+
+// GPIO Port for LED
+#define LED_G LED2
+#define LED_R LED1
+#define LED_B LED3
+
+// Debug Port
+extern Serial pc;
+
+#endif
\ No newline at end of file
diff -r 90554d22ade5 -r 12369ee344ab Sensor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensor.cpp	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,4 @@
+#include "Sensor.h"
+
+BME280 *pSensor;
+TSL2561_I2C *pLumSensor; 
diff -r 90554d22ade5 -r 12369ee344ab Sensor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensor.h	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,14 @@
+#ifndef SENSOR_H
+#define SENSOR_H
+
+// MBED System Header
+#include "mbed.h"
+
+// Sensor Library Header
+#include "BME280.h"
+#include "TSL2561_I2C.h"
+
+extern BME280 *pSensor;
+extern TSL2561_I2C *pLumSensor; 
+
+#endif
diff -r 90554d22ade5 -r 12369ee344ab StatusLED.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/StatusLED.cpp	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,28 @@
+#include "StatusLED.h"
+
+//------------------------------------------------------------------------------------------
+
+StatusLED::StatusLED(DigitalOut *_pHBLed,DigitalOut *_pDataLed, DigitalOut *_pServerLed)
+{
+    pHBLed=_pHBLed;
+    pDataLed=_pDataLed;
+    pServerLed=_pServerLed;
+    
+    pHBLed->write(1);
+    pDataLed->write(1);
+    pServerLed->write(1);
+}
+
+void StatusLED::HBLedTick(){
+    pOBStatusLED->pHBLed->write(pOBStatusLED->pHBLed->read()?0:1);
+}
+
+StatusLED *pOBStatusLED;
+
+//------------------------------------------------------------------------------------------
+
+void HBLedTicker(void const *args)
+{
+        pOBStatusLED->HBLedTick();
+}
+
diff -r 90554d22ade5 -r 12369ee344ab StatusLED.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/StatusLED.h	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,27 @@
+#ifndef STATUS_LED_H
+#define STATUS_LED_H
+
+// MBED System Header
+#include "mbed.h"
+#include "rtos.h"
+
+#define HBLED_CYCLE 1000 // 1000ms
+#define START_THREAD 1
+
+class StatusLED
+{
+private:
+    DigitalOut *pHBLed;
+    DigitalOut *pDataLed;
+    DigitalOut *pServerLed;
+public:
+    StatusLED(DigitalOut *_pHBLed,DigitalOut *_pDataLed, DigitalOut *_pServerLed);
+    void HBLedTick();
+};
+
+void HBLedTicker(void const *args);
+
+extern StatusLED *pOBStatusLED;
+
+#endif
+
diff -r 90554d22ade5 -r 12369ee344ab TSL2561_I2C.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSL2561_I2C.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/karlmaxwell67/code/TSL2561_I2C/#17fef2caa563
diff -r 90554d22ade5 -r 12369ee344ab Twitter.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Twitter.cpp	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,125 @@
+#include <string.h>
+#include "mbed.h"
+#include "rtos.h"
+#include "EthernetInterface.h"
+#include "NTPClient.h"
+#include "OAuth4Tw.h"
+
+#include "Twitter.h"
+#include "OAuthKey.h"
+#include "Sensor.h"
+
+// NTP Client to correct RTC
+NTPClient ntp;
+
+// Twitter API URL
+const char url[] = "https://api.twitter.com/1.1/statuses/update.json";
+
+char response_buffer[RESPONSE_BUFFER_SIZE];
+HTTPText response(response_buffer, sizeof(response_buffer));
+
+void TwitterClient(void const *arg)
+{
+    int i;
+
+    for(;;) {
+        EnvTweet();
+        example_getUserData();
+        for(i=0; i<10; i++) {
+            Thread::wait(60*1000);
+        }
+    }
+}
+
+
+void updateTime()
+{
+    printf("Trying to update time...\n");
+
+    time_t ctTime;
+    NTPResult result;
+
+    while (1) {
+        //result = ntp.setTime("pool.ntp.org");
+        //result = ntp.setTime("pool.ntp.org", NTP_DEFAULT_PORT, 2000);
+        result = ntp.setTime("ntp.nict.jp");
+
+        if (result == NTP_OK) {
+            time(&ctTime);
+            printf("Time is set to (UTC): %s\n", ctime(&ctTime));
+            break;
+        }
+
+        switch (result) {
+            case NTP_CONN:      ///<Connection error
+                printf("Connection error\n");
+                break;
+            case NTP_TIMEOUT:   ///<Connection timeout
+                printf("Connection timeout\n");
+                break;
+            case NTP_PRTCL:     ///<Protocol error
+                printf("Protocol error\n");
+                break;
+            case NTP_DNS:       ///<Could not resolve name
+                printf("Could not resolve name\n");
+                break;
+            default:
+                printf("Error result=%d\n", result);
+                break;
+        }
+
+        wait(5);
+    }
+}
+
+void EnvTweet()
+{
+
+    std::vector<std::string> post;
+    post.reserve(3);
+
+    struct tm tmptr;
+    char tmstr[34];
+    char status[150];
+    char location_lat[24];
+    char location_long[24];
+
+    time_t ctTime;
+    time(&ctTime);
+    ctTime += 9 * 60 * 60;  // Timezone: JST(+9h)
+    localtime_r(&ctTime, &tmptr);
+
+    // Tweets in Japanese
+    strftime(tmstr, sizeof(tmstr), "%Y年%m月%d日 %H時%M分%S秒", &tmptr);
+    snprintf(status, sizeof(status), "status=只今%sですよ~\n温度:%2.2f℃ 気圧:%04.2fhPa 湿度:%2.2f%% 照度:%5.2flx",
+             tmstr, pSensor->getTemperature(), pSensor->getPressure(), pSensor->getHumidity(),pLumSensor->getLux());
+    post.push_back(status);
+
+    // Option: add Location information
+    // snprintf(location_lat, sizeof(location_lat), "lat=%f", 35.359577);
+    // snprintf(location_long, sizeof(location_long), "long=%f", 138.731414);
+    // post.push_back(location_lat);
+    // post.push_back(location_long);
+
+    HTTPResult result = oa4t.post(url, &post, &response);
+
+    if (result == HTTP_OK) {
+        printf("POST success.\n%s\n", response_buffer);
+    } else {
+        printf("POST error. (result = %d)\n", result);
+    }
+}
+
+void example_getUserData()
+{
+    const char url[] = "https://api.twitter.com/1.1/users/show.json"
+                       "?screen_name=twitter";
+
+    HTTPResult result = oa4t.get(url, &response);
+
+    if (result == HTTP_OK) {
+        printf("GET success.\n%s\n", response_buffer);
+    } else {
+        printf("GET error. (result = %d)\n", result);
+    }
+}
\ No newline at end of file
diff -r 90554d22ade5 -r 12369ee344ab Twitter.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Twitter.h	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,12 @@
+#ifndef TWITTER_H
+#define TWITTER_H
+
+// prototype
+void updateTime();
+void EnvTweet();
+void example_getUserData();
+void TwitterClient(void const *arg);
+
+#define RESPONSE_BUFFER_SIZE 4096
+
+#endif
\ No newline at end of file
diff -r 90554d22ade5 -r 12369ee344ab eCompass_FPU_Lib.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eCompass_FPU_Lib.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JimCarver/code/eCompass_FPU_Lib/#37bc03c3b1f9
diff -r 90554d22ade5 -r 12369ee344ab main.cpp
--- a/main.cpp	Sat Nov 15 21:46:59 2014 +0000
+++ b/main.cpp	Sun Sep 27 11:04:54 2015 +0000
@@ -1,108 +1,58 @@
 #include "mbed.h"
+#include "rtos.h"
 #include "EthernetInterface.h"
- 
-#include "NetworkAPI/buffer.hpp"
-#include "NetworkAPI/select.hpp"
-#include "NetworkAPI/ip/address.hpp"
-#include "NetworkAPI/tcp/socket.hpp"
-using namespace network;
- 
-#define MAX_CLIENTS 5
- 
-int
-main()
+
+#include "Port.h"
+#include "EnvServer.h"
+#include "StatusLED.h"
+#include "Sensor.h"
+#include "Twitter.h"
+
+extern EthernetInterface eth;
+extern Serial pc;
+
+Serial pc(USBTX, USBRX);
+EthernetInterface eth;
+
+int main()
 {
-    EthernetInterface interface;
-    interface.init();
-    interface.connect();
-    printf("IP Address is %s\n\r", interface.getIPAddress());
-     
-    Select select;
-    tcp::Socket server;
-    tcp::Socket client[MAX_CLIENTS];
-    tcp::Socket *socket = NULL;
-     
-    int result = 0;
-    int index = 0;
-     
-    network::Buffer buffer(256);
-    std::string message("Hello world!");
-     
-    // Configure the server socket (assume everty thing works)
-    server.open();
-    server.bind(1234);
-    server.listen(MAX_CLIENTS);
-   
-    // Add sockets to the select api
-    select.set(&server, Select::Read);
-    for (index = 0; index < MAX_CLIENTS; index++) {
-        select.set(&client[index], Select::Read);
+    int ret;
+
+    // Timer for Hearbeat LED
+    RtosTimer HBLEDTickTimer(HBLedTicker,osTimerPeriodic);
+        
+    // Initialize COM Port
+    pc.baud(115200);
+
+    // Initialize Status LED
+    pOBStatusLED=new StatusLED(new DigitalOut(LED_G),new DigitalOut(LED_R),new DigitalOut(LED_B));
+
+    // Initialize Sensor with I2C port
+    pSensor=new BME280(PTE25, PTE24);
+    pLumSensor=new TSL2561_I2C(PTE25, PTE24);
+    pLumSensor->enablePower();
+
+    //Initialize ethernet interface
+    eth.init(); //Use DHCP
+    printf("Initialized, MAC: %s\n", eth.getMACAddress());
+    while ((ret = eth.connect()) != 0) {
+        printf("Error eth.connect() - ret = %d\n", ret);
     }
-     
-    do {
-        // Wait for activity
-        result = select.wait();
-        if (result < -1) {
-            printf("Failed to select\n\r");
-            break;
-        }
-         
-        // Get the first socket
-        socket = (tcp::Socket *)select.getReadable();
-         
-        for (; socket != NULL; socket = (tcp::Socket *)select.getReadable()) {
-            // Check if there was a connection request.
-            if (socket->getHandle() == server.getHandle()) {                
-                // Find an unused client
-                for (index = 0; index < MAX_CLIENTS; index++) {
-                    if (client[index].getStatus() == network::Socket::Closed) {
-                        break;
-                    }
-                }
-                 
-                // Maximum connections reached
-                if (index == MAX_CLIENTS) {
-                    printf("Maximum connections reached\n\r");
-                    continue;
-                }
-             
-                // Accept the client
-                socket->accept(client[index]);
-                printf("Client connected %s:%d\n\r",
-                    client[index].getRemoteEndpoint().getAddress().toString().c_str(),
-                    client[index].getRemoteEndpoint().getPort());
-                     
-                // Send a nice message to the client
-                client[index].write((void *)message.data(), message.size());
-                continue;
-            }
-             
-            // It was not the server socket, so it must be a client talking to us.
-            switch (socket->read(buffer)) {
-                case 0:
-                    // Remote end disconnected
-                    printf("Client disconnected %s:%d\n\r",
-                        socket->getRemoteEndpoint().getAddress().toString().c_str(),
-                        socket->getRemoteEndpoint().getPort());
-                     
-                    // Close socket
-                    socket->close();
-                    break;
-                 
-                case -1:
-                    printf("Error while reading data from socket\n\r");
-                    socket->close();
-                    break;
-                 
-                default:
-                    printf("Message from %s:%d\n\r",
-                        socket->getRemoteEndpoint().getAddress().toString().c_str(),
-                        socket->getRemoteEndpoint().getPort());
-                         
-                    printf("%s\n\r", (char *)buffer.data());
-                    break;
-            }
-        }
-             
-    } while (server.getStatus() == network::Socket::Listening);
+    printf("Connected, IP: %s, MASK: %s, GW: %s\n",
+           eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
+
+    // Correct internal RTC by connecting NTP Server
+    updateTime();
+
+    // Start Heartbeat LED Tick Thread
+    HBLEDTickTimer.start(HBLED_CYCLE);
+
+    // Start Server Thread
+    Thread ThServer(EnvServer);
+
+    // Start Twitter Client Thread
+    Thread TwetterClientTh(TwitterClient,NULL,osPriorityNormal,16384);
+    
+    // wait forever
+    Thread::wait(osWaitForever);
 }
\ No newline at end of file
diff -r 90554d22ade5 -r 12369ee344ab mbed-rtos.lib
--- a/mbed-rtos.lib	Sat Nov 15 21:46:59 2014 +0000
+++ b/mbed-rtos.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/
+http://mbed.org/users/mbed_official/code/mbed-rtos/#9d001ed5feec
diff -r 90554d22ade5 -r 12369ee344ab mbed.bld
--- a/mbed.bld	Sat Nov 15 21:46:59 2014 +0000
+++ b/mbed.bld	Sun Sep 27 11:04:54 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa
\ No newline at end of file
diff -r 90554d22ade5 -r 12369ee344ab wolfSSL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wolfSSL.lib	Sun Sep 27 11:04:54 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/wolfSSL/code/wolfSSL/#28278596c2a2