Using DHT11 sensor, sdWrite, wdt. Need to sleep more then this.

Dependencies:   DHT GPRSInterface HTTPClient_GPRS SDFileSystem USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
seedteam20
Date:
Wed Apr 01 16:16:13 2015 +0000
Commit message:
Using DHT11 sensor and wdt. Not fully going to sleep.

Changed in this revision

ARCH_GPRS_HW/ARCH_GPRS_HW.cpp Show annotated file Show diff for this revision Revisions of this file
ARCH_GPRS_HW/ARCH_GPRS_HW.h Show annotated file Show diff for this revision Revisions of this file
ARCH_GPRS_HW/ARCH_GPRS_HW_DFS.h Show annotated file Show diff for this revision Revisions of this file
DHT.lib Show annotated file Show diff for this revision Revisions of this file
GPRSInterface.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient_GPRS.lib Show annotated file Show diff for this revision Revisions of this file
I2C_UART/i2c_uart.cpp Show annotated file Show diff for this revision Revisions of this file
I2C_UART/i2c_uart.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SLEEP/ARCH_GPRS_Sleep.cpp Show annotated file Show diff for this revision Revisions of this file
SLEEP/ARCH_GPRS_Sleep.h Show annotated file Show diff for this revision Revisions of this file
TCP_YEELINK/tcp_yeelink.cpp Show annotated file Show diff for this revision Revisions of this file
TCP_YEELINK/tcp_yeelink.h Show annotated file Show diff for this revision Revisions of this file
TCP_YEELINK/tcp_yeelink_dfs.h Show annotated file Show diff for this revision Revisions of this file
USBDevice.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
roam_v1.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b6b64c1e74bb ARCH_GPRS_HW/ARCH_GPRS_HW.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARCH_GPRS_HW/ARCH_GPRS_HW.cpp	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,139 @@
+/*
+  IOT_hw.cpp
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:Loovee
+  2013-7-21
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "mbed.h"
+#include "tcp_yeelink.h"
+#include "tcp_yeelink_dfs.h"
+#include "ARCH_GPRS_HW.h"
+#include "ARCH_GPRS_HW_DFS.h"
+
+DigitalOut eg10_pwr(PINPWR);
+DigitalOut eg10_on(PINONOFF);
+DigitalInOut eg10_state(PINEGSTATE);
+DigitalOut eg10_rst(PINSYSRST);
+
+DigitalOut led1(PINLED1);
+DigitalOut led2(PINLED2);
+DigitalOut led3(PINLED3);
+DigitalOut led4(PINLED4);
+
+DigitalOut grove_pwr(GROVE_PWR);
+DigitalIn  charging(PIN_CHRGING);
+DigitalIn  chargdone(PIN_CHRGDONE);
+
+AnalogIn vol_bat(PIN_READBAT);
+
+void IOT_HW::EG10_PWRON()
+{
+    eg10_pwr = 0;
+}
+
+void IOT_HW::EG10_PWROFF()
+{
+    eg10_pwr = 1;
+}
+
+void IOT_HW::EG10_ON()
+{
+    eg10_on = 0;
+    wait(2);
+    eg10_on = 1;
+}
+
+int IOT_HW::init()
+{
+    init_io();
+    EG10_PWROFF();
+    wait(2);                // wait 2s
+    EG10_PWRON();
+    EG10_PWRON();
+    EG10_ON();
+    return (IOT.waitString("M2MRSSI", 30));
+}
+
+void IOT_HW::init_io()
+{
+    eg10_pwr = 1;
+    eg10_on  = 1;
+}
+
+int IOT_HW::getEG10_State()
+{
+    eg10_state.input();
+    eg10_state.mode(PullDown);
+    if(eg10_state.read())
+    {
+        return 1;
+    }
+    return 0;
+}
+
+void IOT_HW::EG10StateLed(unsigned char state)
+{
+    eg10_state.output();
+    eg10_state = 1-state;
+}
+
+void IOT_HW::userLed(unsigned char led, unsigned char state)
+{
+    //    if(state!=0 || state!=1)return;
+
+    if(1==led)led1 = state;
+    else if(2==led)led2 = state;
+    else if(3==led)led3 = state;
+    else if(4==led)led4 = state;
+
+}
+
+int IOT_HW::readChrgState()
+{
+    if(!charging.read())return CHRGDONE;
+    if(!chargdone.read())return CHRGING;
+    return NOCHRG;
+}
+
+float IOT_HW::readBatVol()
+{
+    unsigned int tmp = vol_bat.read_u16();
+    
+        return tmp;
+    float dr = tmp;
+    dr = dr/65536.0*3.3*2.0;
+    return dr;
+    // return ((float tmp)/65536.0*3.3*2.0);
+}
+
+void IOT_HW::grovePwrOn()
+{
+    grove_pwr = 0;
+}
+
+void IOT_HW::grovePwrOff()
+{
+    grove_pwr = 1;
+}
+
+
+IOT_HW iot_hw;
+/*********************************************************************************************************
+  END FILE
+*********************************************************************************************************/
\ No newline at end of file
diff -r 000000000000 -r b6b64c1e74bb ARCH_GPRS_HW/ARCH_GPRS_HW.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARCH_GPRS_HW/ARCH_GPRS_HW.h	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,55 @@
+/*
+  IOT_hw.h
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:Loovee
+  2013-7-21
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef __ARCH_GPRS_HW_H__
+#define __ARCH_GPRS_HW_H__
+
+#include "ARCH_GPRS_HW_DFS.h"
+
+class IOT_HW{
+
+private:
+
+public:
+    int init();                                     // init all
+    void init_io();                                 // init io
+    void EG10_PWRON();                              // power on eg10
+    void EG10_PWROFF();                             // power off eg10, cut the power
+    void EG10_ON();                                 // turn on eg10
+    void EG10_OFF();                                // turn off eg10
+    int getEG10_State();                            // get state of eg10
+    void EG10StateLed(unsigned char state);         // control led
+
+        int readChrgState();
+    float readBatVol();
+    void userLed(unsigned char led, unsigned char state);
+    void grovePwrOn();
+    void grovePwrOff();
+};
+
+extern IOT_HW iot_hw;
+
+#endif
+
+/*********************************************************************************************************
+  END FILE
+*********************************************************************************************************/
diff -r 000000000000 -r b6b64c1e74bb ARCH_GPRS_HW/ARCH_GPRS_HW_DFS.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARCH_GPRS_HW/ARCH_GPRS_HW_DFS.h	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,67 @@
+/*
+  IOT_hw_dfs.h
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:Loovee
+  2013-7-21
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef __ARCH_GPRS_HW_DFS_H__
+#define __ARCH_GPRS_HW_DFS_H__
+
+// pin define
+#define PINPWR          P1_2            // power on EG 10, low enable
+#define PINONOFF        P1_7            // switch of EG10, low enable, low for 2s to turn on EG10
+#define PINTX           P0_18           // EG10 TX
+#define PINRX           P0_19           // EG10 RX
+#define PINSYSRST       P1_6            // EG10 RST,high enable
+#define PINEGSTATE      P1_15           // in and out, read eg10 state, HIGH: on, LOW: off
+
+
+// grove pin
+#define GROVE_I2C_SCL   P0_4            // grove i2c pin
+#define GROVE_I2C_SDA   P0_5            // grove i2c sda
+
+#define GROVE_UART_RX   P0_14           // grove uart rx
+#define GROVE_UART_TX   P0_13           // grove uart tx
+
+#define GROVE_ADC_1     P0_12           // grove ADC, the outside one
+#define GROVE_ADC_2     P0_11           // grove ADC, the other one
+
+#define GROVE_PWR       P1_3            // control all grove power, low enable
+
+// charge circuit
+#define PIN_CHRGING     P1_1            // charging, low enable
+#define PIN_CHRGDONE    P1_0            // charge done
+#define PIN_READBAT     P0_23           // battery voltage in, the value should x2
+
+// led pin
+#define PINLED1         P1_8
+#define PINLED2         P1_9
+#define PINLED3         P1_10
+#define PINLED4         P1_11
+
+// charge state
+#define CHRGING         1
+#define CHRGDONE        2
+#define NOCHRG          3
+
+#endif
+
+/*********************************************************************************************************
+  END FILE
+*********************************************************************************************************/
diff -r 000000000000 -r b6b64c1e74bb DHT.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT.lib	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/components/code/DHT/#df22ddf10d75
diff -r 000000000000 -r b6b64c1e74bb GPRSInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPRSInterface.lib	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Seeed/code/GPRSInterface/#180feb3ebe62
diff -r 000000000000 -r b6b64c1e74bb HTTPClient_GPRS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient_GPRS.lib	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lawliet/code/HTTPClient_GPRS/#aaab2081c1c0
diff -r 000000000000 -r b6b64c1e74bb I2C_UART/i2c_uart.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2C_UART/i2c_uart.cpp	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+#include "i2c_uart.h"
+#include "ARCH_GPRS_HW_DFS.h"
+
+#define ADDRESS        8
+
+I2C i2c_debug(GROVE_I2C_SDA, GROVE_I2C_SCL);
+
+
+void debug_i2c(char *dta)
+{
+    int len = strlen(dta);
+    i2c_debug.write(ADDRESS, dta, len);
+    //wait_ms(10);
+}
+
+void debug_i2c(char dta)
+{
+    char dta1[5];
+    sprintf(dta1, "%c", dta);
+    debug_i2c(dta1);
+}
+//
diff -r 000000000000 -r b6b64c1e74bb I2C_UART/i2c_uart.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2C_UART/i2c_uart.h	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,17 @@
+#ifndef __I2C_UART_H__
+#define __I2C_UART_H__
+
+#define __Debug            1
+
+#if __Debug
+#define DBG(X)    debug_i2c(X)
+#else
+#define DBG(X)
+#endif
+
+
+void debug_i2c(char *dta);
+
+
+void debug_i2c(char dta);
+#endif
diff -r 000000000000 -r b6b64c1e74bb SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/neilt6/code/SDFileSystem/#c2c1f0b16380
diff -r 000000000000 -r b6b64c1e74bb SLEEP/ARCH_GPRS_Sleep.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLEEP/ARCH_GPRS_Sleep.cpp	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,90 @@
+#include "mbed.h"
+#include "ARCH_GPRS_Sleep.h"
+#include "ARCH_GPRS_HW.h"
+
+void Stalker3_0_sleep::gotoSleep()               // goto sleep mode, untill wdt interrupt
+{
+    LPC_PMU->PCON          |= 0x01;                                     /* ?????????           */
+    LPC_SYSCON->PDSLEEPCFG |= (1UL << 3);                               /* ??BOD???????        */
+    SCB->SCR &= ~(1UL << 2);                                            /* ??????                 */
+    __wfi();
+}
+
+void Stalker3_0_sleep::wdtClkSetup(unsigned long clksrc)
+{
+  /* Freq = 0.5Mhz, div_sel is 0x1F, divided by 64. WDT_OSC should be 7.8125khz */
+    LPC_SYSCON->WDTOSCCTRL = (0x1<<5)|0x1F;
+    LPC_SYSCON->PDRUNCFG &= ~(0x1<<6);    /* Let WDT clock run */
+
+  /* Enables clock for WDT */
+    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<15);
+    LPC_WWDT->CLKSEL = clksrc;        /* Select clock source */
+
+}
+
+void Stalker3_0_sleep::wdtInit(long tc)          // init wdt
+{
+    uint32_t regVal;
+
+    LPC_WWDT->TC = tc;
+
+    regVal = WDEN;
+    LPC_WWDT->MOD = regVal;
+
+    LPC_WWDT->FEED = 0xAA;        /* Feeding sequence */
+    LPC_WWDT->FEED = 0x55;
+
+    NVIC_EnableIRQ(WDT_IRQn);
+    NVIC_SetPriority(WDT_IRQn, 2);
+    return;
+
+}
+
+void Stalker3_0_sleep::init()
+{
+
+}
+
+void Stalker3_0_sleep::sleep(long ts)            // sleep for ts (s)
+{
+
+    workMode = MODE_SLEEP;
+    wdtInit(0x2dc6c0);
+
+    for(int i=0; i<ts; i++)
+    {
+        gotoSleep();
+    }
+
+    workMode = MODE_WORKING;
+    feed();
+}
+
+void Stalker3_0_sleep::wakeUp()                  // wake up from sleep
+{
+
+}
+
+void Stalker3_0_sleep::feed()                    // watch dog feed
+{
+    LPC_WWDT->FEED = 0xAA;        /* Feeding sequence */
+    LPC_WWDT->FEED = 0x55;
+    return;
+}
+
+Stalker3_0_sleep wdt_sleep;
+
+extern "C"{
+
+    void WDT_IRQHandler(void)
+    {
+
+        if(wdt_sleep.workMode == MODE_WORKING)      // WORKING MODE, AND NO FEET WDT, RESET!!!
+        {
+            NVIC_SystemReset();
+        }
+        LPC_WWDT->MOD &= ~WDTOF;        /* clear the time-out flag and interrupt flag */
+        LPC_WWDT->MOD &= ~WDINT;        /* clear the time-out flag and interrupt flag */
+        wdt_sleep.wdtInit(0x2dc6c0);
+    }
+}
diff -r 000000000000 -r b6b64c1e74bb SLEEP/ARCH_GPRS_Sleep.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLEEP/ARCH_GPRS_Sleep.h	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,48 @@
+#ifndef __ARCH_GPRS_SLEEP_H__
+#define __ARCH_GPRS_SLEEP_H__
+
+
+#define WDTCLK_SRC_IRC_OSC          0
+#define WDTCLK_SRC_WDT_OSC          1
+
+#define WDEN              (0x1<<0)
+#define WDRESET           (0x1<<1)
+#define WDTOF             (0x1<<2)
+#define WDINT             (0x1<<3)
+#define WDPROTECT         (0x1<<4)
+#define WDLOCKCLK         (0x1<<5)
+
+#define WDT_FEED_VALUE        0x003FFFFF
+
+#define WINDOW_MODE       0
+#define PROTECT_MODE      0
+#define WATCHDOG_RESET    1
+#define WDLOCK_MODE       0
+#define LOCKCLK_MODE      0
+
+#define MODE_SLEEP        0
+#define MODE_WORKING      1
+
+class Stalker3_0_sleep{
+
+    public:
+
+    int workMode;                 // working mode, sleep or working
+
+    public:
+
+    void gotoSleep();               // goto sleep mode, untill wdt interrupt
+    void wdtClkSetup(unsigned long clksrc);
+
+    public:
+
+    void init();
+
+    void sleep(long ts);            // sleep for ts (s)
+    void wakeUp();                  // wake up from sleep
+    void feed();                    // watch dog feed
+    void wdtInit(long tc);          // init wdt
+};
+
+extern Stalker3_0_sleep wdt_sleep;
+#endif
diff -r 000000000000 -r b6b64c1e74bb TCP_YEELINK/tcp_yeelink.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCP_YEELINK/tcp_yeelink.cpp	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,336 @@
+/*
+  IOT_Mbed.cpp
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:Loovee
+  2013-7-21
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#include <stdio.h>
+
+#include "mbed.h"
+#include "tcp_yeelink.h"
+#include "tcp_yeelink_dfs.h"
+#include "i2c_uart.h"
+#include "ARCH_GPRS_Sleep.h"
+
+
+Serial serial1(P0_19, P0_18);        // tx, rx
+Timer tcnt;
+
+void IOT_Mbed::init(char *postURL, char *APIKey)
+{
+    serial1.baud(115200);
+    strcpy(yeelinkPostURL, postURL);
+    sprintf(yeelinkPostHeads, "U-ApiKey: %s\r\n", APIKey);
+    strcpy(yeelinkDns, "42.96.164.52");                             // api.yeelink.net
+    sprintf(yeelinkPort, "%d", HTTP_DEFAULT_PORT);
+}
+
+void IOT_Mbed::callTest()
+{
+    sendCmdAndWaitForRest("ATD:10086;\r\n", "OK", 10);
+}
+
+int IOT_Mbed::checkAT(int timeout)
+{
+    return sendCmdAndWaitForRest("AT\r\n", "OK", timeout);
+}
+
+int IOT_Mbed::waitString(const char *str, int timeout)                // time out : s
+{
+    int len = strlen(str);
+    int sum=0;
+
+    tcnt.start();                                                   // start timer
+
+    for(;;)
+    {
+        if(serial1.readable())
+        {
+            char c = serial1.getc();
+            DBG(c);
+            sum = (c==str[sum]) ? sum+1 : 0;
+            if(sum == len)break;
+        }
+
+        if(tcnt.read() > timeout)           // time out
+        {
+            tcnt.stop();
+            tcnt.reset();
+
+            DBG("time out\r\n");
+            return ERRTOUT;
+        }
+        
+        wdt_sleep.feed();
+    }
+
+    tcnt.stop();                            // stop timer
+    tcnt.reset();                           // clear timer
+
+    while(serial1.readable())               // display the other thing..
+    {
+        char c = serial1.getc();
+        DBG(c);
+    }
+
+    return 1;
+}
+
+
+int IOT_Mbed::sendCmdAndWaitForRest(char *dta, const char *resq, int timeout)
+{
+    sendCmd(dta);
+    return waitString(resq, timeout);
+}
+
+void IOT_Mbed::sendCmd(char *dta)
+{
+    serial1.printf("%s\r\n", dta);
+}
+
+int IOT_Mbed::connectTCP()
+{
+
+    sendCmdAndWaitForRest("ATE0\r\n", "OK", 3);
+    int tout = 0;
+    while(1)
+    {
+        if(sendCmdAndWaitForRest(STROPENGPRS, "OK", 20) == ERRTOUT)
+        {
+            DBG("GPRS OPEN ERR, OPEN AGAIN\r\n");
+            wait(5);
+        }
+        else
+        {
+            DBG("GPRS OPEN OK!\r\n");
+            break;
+        }
+        tout++;
+        if(tout>5)return 0;
+    }
+
+
+    if(!sendCmdAndWaitForRest(STRSETGPRS, "OK", 20))return 0;
+    if(!sendCmdAndWaitForRest(STRSETAPN, "OK", 20))return 0;;
+
+    char cipstart[50];
+    sprintf(cipstart, "AT+CIPSTART=\"TCP\",\"%s\",\"%s\"", yeelinkDns, yeelinkPort);
+    if(!sendCmdAndWaitForRest(cipstart, "CONNECT OK", 20))return 0;;              // connect tcp
+
+    return 1;
+}
+
+int IOT_Mbed::connectTCP(char *ip, char *port)
+{
+
+    sendCmdAndWaitForRest("ATE0\r\n", "OK", 3);
+    int tout = 0;
+
+    while(1)
+    {
+        if(sendCmdAndWaitForRest(STROPENGPRS, "OK", 20) == ERRTOUT)
+        {
+            DBG("GPRS OPEN ERR, OPEN AGAIN\r\n");
+            wait(5);
+        }
+        else
+        {
+            DBG("GPRS OPEN OK!\r\n");
+            break;
+        }
+        tout++;
+        if(tout>5)return 0;
+    }
+
+
+    if(!sendCmdAndWaitForRest(STRSETGPRS, "OK", 20))return 0;
+    if(!sendCmdAndWaitForRest(STRSETAPN, "OK", 20))return 0;;
+
+    char cipstart[50];
+    sprintf(cipstart, "AT+CIPSTART=\"TCP\",\"%s\",\"%s\"", ip, port);
+    if(!sendCmdAndWaitForRest(cipstart, "CONNECT OK", 20))return 0;;              // connect tcp
+    return 1;
+
+}
+
+//send data to tcp
+int IOT_Mbed::sendDtaTcp(char *dta, int timeout)
+{
+    serial1.printf("AT+CIPSEND=%d\r\n", strlen(dta));
+    waitString(">", 10);
+    serial1.printf("%s", dta);
+
+    wait_ms(50);
+    return waitString("SEND OK", timeout);
+}
+
+bool IOT_Mbed::sendToYeelink_t()
+{
+    char dtaSend[300];
+    sprintf(dtaSend, "%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n%s\r\n", POST1, POST2, POST3, POST4, POST5, POST6, POST7);
+    return sendDtaTcp(dtaSend, 20);
+}
+
+void IOT_Mbed::postDtaToYeelink()
+{
+
+}
+
+int IOT_Mbed::postDtaToYeelink(char *url, char *apikey, int sensorDta)
+{
+    return postDtaToYeelink(url, apikey, sensorDta, 0);
+}
+
+int IOT_Mbed::postDtaToYeelink(char *url, char *apikey, float sensorDta, int dec)
+{
+    char dtaPost[350];
+
+    char request[100];
+    char heads[200];
+    char body[100];
+
+    unsigned int port;
+
+    char host[HTTP_MAX_HOST_LEN];
+    char path[HTTP_MAX_PATH_LEN];
+
+    if (parseURL(url, host, sizeof(host), &port, path, sizeof(path)) != 0)
+    {
+        DBG("Failed to parse URL.\r\n");
+        return 0;
+    }
+
+    if(!connectTCP())
+    {
+        DBG("connect to tcp err!\r\n");
+        return 0;
+    }
+
+    if(dec == 0)
+    {
+        sprintf(body, "{\"value\": %.0f}\r\n", sensorDta);
+    }
+    else if(dec == 1)
+    {
+        sprintf(body, "{\"value\": %.1f}\r\n", sensorDta);
+    }
+    else if(dec == 2)
+    {
+        sprintf(body, "{\"value\": %.2f}\r\n", sensorDta);
+    }
+    else
+    {
+        sprintf(body, "{\"value\": %.3f}\r\n", sensorDta);
+
+    }
+    sprintf(request, "POST %s HTTP/1.1\r\n", path);
+    sprintf(heads, "Host: %s\r\nU-ApiKey: %s\r\nContent-Length: %d\r\nContent-Type: %s\r\n\r\n",host, apikey, strlen(body), CONTENT_TYPE);
+    sprintf(dtaPost, "%s%s%s", request, heads, body);
+
+    sendDtaTcp(dtaPost, 10);
+
+    while(serial1.readable())
+    {
+        char c = serial1.getc();
+        DBG(c);
+    }
+
+    return sendCmdAndWaitForRest(STRCLOSE, "OK", 20);
+}
+
+int IOT_Mbed::parseURL(const char *url, char *host, int max_host_len, unsigned int *port, char *path, int max_path_len)
+{
+    char *scheme_ptr = (char *)url;
+    char *host_ptr = (char *)strstr(url, "://");
+    if (host_ptr != NULL)
+    {
+        if (strncmp(scheme_ptr, "http://", 7))
+        {
+            DBG("Bad scheme\r\n");
+            return -1;
+        }
+        host_ptr += 3;
+    }
+    else
+    {
+        host_ptr = (char *)url;
+    }
+
+    int host_len = 0;
+    char *port_ptr = strchr(host_ptr, ':');
+
+    if (port_ptr != NULL)
+    {
+        host_len = port_ptr - host_ptr;
+        port_ptr++;
+        if (sscanf(port_ptr, "%hu", port) != 1)
+        {
+            DBG("Could not find port.\r\n");
+            return -3;
+        }
+    }
+    else
+    {
+        *port = HTTP_DEFAULT_PORT;
+    }
+
+    char *path_ptr = strchr(host_ptr, '/');
+
+    if (host_len == 0)
+    {
+        host_len = path_ptr - host_ptr;
+    }
+
+    if (max_host_len < (host_len + 1))
+    {
+        DBG("Host buffer is too small.\r\n");
+        return -4;
+    }
+
+    memcpy(host, host_ptr, host_len);
+    host[host_len] = '\0';
+
+    int path_len;
+
+    char *fragment_ptr = strchr(host_ptr, '#');
+    if (fragment_ptr != NULL)
+    {
+        path_len = fragment_ptr - path_ptr;
+    }
+    else
+    {
+        path_len = strlen(path_ptr);
+    }
+
+    if (max_path_len < (path_len + 1))
+    {
+        DBG("Path buffer is too small.\r\n");
+        return -5;
+    }
+    memcpy(path, path_ptr, path_len);
+    path[path_len] = '\0';
+
+    return 0;
+}
+
+
+
+IOT_Mbed IOT;
+/*********************************************************************************************************
+  END FILE
+*********************************************************************************************************/
diff -r 000000000000 -r b6b64c1e74bb TCP_YEELINK/tcp_yeelink.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCP_YEELINK/tcp_yeelink.h	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,72 @@
+/*
+  IOT_Mbed.h
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:Loovee
+  2013-7-21
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef __TCP_YEELINK_H__
+#define __TCP_YEELINK_H__
+
+#include "mbed.h"
+
+class IOT_Mbed{
+
+    private:
+
+    //Serial serial1(P0_19, P0_18);        // tx, rx
+    private:
+    char yeelinkPostURL[100];
+    char yeelinkPostHeads[100];
+
+    char yeelinkDns[20];
+    char yeelinkPort[10];
+
+    private:
+
+    void callTest();
+
+    int sendCmdAndWaitForRest(char *dta, const char *resq, int timeout);
+    void sendCmd(char *dta);
+    int parseURL(const char *url, char *host, int max_host_len, unsigned int *port, char *path, int max_path_len);
+
+    public:
+    int waitString(const char *str, int timeout);
+    void init(char *postURL, char *APIKey);
+    int checkAT(int timeout);
+    int connectTCP();
+    int connectTCP(char *ip, char *port);
+    void postDtaToYeelink();
+    int postDtaToYeelink(char *url, char *apikey, int sensorDta);
+    int postDtaToYeelink(char *url, char *apikey, float sensorDta, int dec);
+
+    int sendDtaTcp(char *dta, int timeout);
+    bool sendToYeelink_t();
+
+
+};
+
+
+extern IOT_Mbed IOT;
+
+
+#endif
+
+/*********************************************************************************************************
+  END FILE
+*********************************************************************************************************/
diff -r 000000000000 -r b6b64c1e74bb TCP_YEELINK/tcp_yeelink_dfs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCP_YEELINK/tcp_yeelink_dfs.h	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,67 @@
+/*
+  IOT_MbedDfs.h
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+
+  Author:Loovee
+  2013-7-21
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef __TCP_YEELINK_DFS_H__
+#define __TCP_YEELINK_DFS_H__
+
+#define HTTP_DEFAULT_PORT                   80
+
+#define HTTP_MAX_HOST_LEN                   20
+#define HTTP_MAX_PATH_LEN                   64
+#define HTTP_MAX_BUF_LEN                    100
+
+// some useful AT command
+#define STRCSQ          "AT+CSQ"
+#define STROPENGPRS     "AT+CGATT=1"
+#define STRSETGPRS      "AT+CGDCONT=1,\"IP\",\"CMNET\""
+#define STRSETAPN       "AT+CSTT=\"CMNET\",\"\",\"\""
+#define STRSETMODE      "AT+CIPMODE=0"
+#define STRSTARTTCP     "AT+CIPSTART=\"TCP\",\"42.96.164.52\",\"80\""
+#define STRCLOSE        "AT+CIPCLOSE"
+#define STRECHOFF       "ATE0"
+#define STRSLEEP        "AT+ESLP=1"
+#define STRWAKE         "AT+ESLP=0"
+
+// err code
+#define ERRTOUT         0
+#define OK              1
+
+
+// post data
+#define POST1  "POST /v1.0/device/3091/sensor/4346/datapoints HTTP/1.1"
+#define POST2  "Host: api.yeelink.net"
+#define POST3  "Connection: close"
+#define POST4  "Content-Length: 15"
+#define POST5  "Content-Type: text/plain"
+#define POST6  "U-ApiKey: 9270322fd7c7683cb9ad198f3464cf0d"
+
+#define POST7  "{\"value\": 100}"
+
+#define CONTENT_TYPE    " application/x-www-form-urlencoded"
+
+
+
+#endif
+
+/*********************************************************************************************************
+  END FILE
+*********************************************************************************************************/
diff -r 000000000000 -r b6b64c1e74bb USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#3b1c43ac045c
diff -r 000000000000 -r b6b64c1e74bb mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file
diff -r 000000000000 -r b6b64c1e74bb roam_v1.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roam_v1.cpp	Wed Apr 01 16:16:13 2015 +0000
@@ -0,0 +1,196 @@
+/** Seed Team 20 - Michael Zonnenberg
+    Board: Arch GPRS V2
+    Sensors: DHT11 temp&humidity
+ */
+ 
+ #include "mbed.h"
+ #include "DHT.h"
+ #include "SDFileSystem.h"
+ #include "GPRSInterface.h"
+ #include "HTTPClient.h"
+ #include "ARCH_GPRS_Sleep.h"
+
+ 
+//LED Blink Functions
+DigitalOut yellowled(LED1);
+DigitalOut redled(LED2);
+DigitalOut greenled(LED3);
+DigitalOut blueled(LED4);
+void blinkYELLOW(void){
+    yellowled = 1;
+    wait(0.5);
+    yellowled = 0;
+    wait(0.5);
+    yellowled = 1;
+    wait(0.5);
+    yellowled = 0;
+    wait(0.5);  
+}
+void blinkRED(void){
+    redled = 1;
+    wait(0.5);
+    redled = 0;
+    wait(0.5);
+    redled = 1;
+    wait(0.5);
+    redled = 0;
+    wait(0.5);  
+}
+void blinkBLUE(void){
+    blueled = 1;
+    wait(0.5);
+    blueled = 0;
+    wait(0.5);
+    blueled = 1;
+    wait(0.5);
+    blueled = 0;
+    wait(0.5);  
+}
+void blinkGREEN(void){
+    greenled = 1;
+    wait(0.5);
+    greenled = 0;
+    wait(0.5);
+    greenled = 1;
+    wait(0.5);
+    greenled = 0;
+    wait(0.5);  
+}
+
+
+
+#define PIN_PWR                 P1_2    //power up gprs module
+#define PIN_PWR_KEY             P1_7
+#define PIN_TX                  P1_27
+#define PIN_RX                  P1_26
+DigitalOut power(PIN_PWR);
+DigitalOut powerKey(PIN_PWR_KEY);
+void gprsPowerUp(void)
+{
+    power = 1;
+    wait(2);
+    power = 0;
+    wait(2);
+ 
+    powerKey = 0;
+    wait(1);
+    powerKey = 1;
+    wait(2);
+    powerKey = 0;
+    wait(3);
+}
+void gprsPowerDown(void)
+{
+   power = 1;
+   wait(2);
+   power = 0;
+   wait(2); 
+}
+
+#define TEST_HTTP_GET       1
+#define TEST_HTTP_POST      1
+#define TEST_HTTP_PUT       1
+#define TEST_HTTP_DELETE    1
+
+#define TS_FEED_ID              25152
+#define TS_API                  "QY931S2NP23LG9IM"
+
+char* thingSpeakUrl = "http://api.thingspeak.com/update";
+char* thingSpeakKey = "QY931S2NP23LG9IM";
+char urlBuffer[256];
+char timeBuffer[64];
+char str[1024];
+GPRSInterface gprs(PIN_TX,PIN_RX,115200,"internetd.gdsp",NULL,NULL);
+HTTPClient http;
+
+/** 
+    Function sends args to thingskpeak
+    @param temperature The temperaure measurment from sensor
+    @param humidity The humidity measurment from sensor
+ */
+void sendToThingSpeak(float temperature, float humidity){
+    //turn on cellular module
+    gprsPowerUp();
+
+    gprs.init();
+    
+    int count = 0;
+    while(false == gprs.connect() && count < 5) {
+        wait(2);
+        count += 1;
+    }
+
+    // format url here
+    urlBuffer[0] = 0;
+    sprintf(urlBuffer, "%s?key=%s&field1=%f&field2=%f", thingSpeakUrl, thingSpeakKey, temperature, humidity);
+
+    // send request
+    HTTPResult res = http.get(urlBuffer, str,128);
+    // and verify the result
+    if (res != HTTP_OK) {
+        blinkRED();
+    } else {
+        blinkGREEN();
+    }
+    gprsPowerDown();
+}
+
+/** 
+    Function sends args to thingskpeak
+    @return temp and humid values from DHT11 sensor
+ */
+DHT sensor(P1_14, DHT11);
+DigitalOut POWER(P1_3); //drive low to activate pins
+void getTempHumid(float* temp, float* humid){
+   int err = 1;
+    wait(1); // wait 1 second for device stable status
+    POWER.write(0);
+    while (err != 0) {
+        err = sensor.readData();
+        *temp = sensor.ReadTemperature(FARENHEIT);
+        *humid = sensor.ReadHumidity();
+        wait(1);
+        }     
+}   
+
+/** 
+    Function writes data to sd card (comma seperated)
+    @param temperature The temperaure measurment from sensor
+    @param humidity The humidity measurment from sensor
+ */
+SDFileSystem sd(P1_22, P1_21, P1_20, P1_23, "sd"); // the pinout on the /Arch GPRS v2 mbed board.
+void sdWrite(double temp, double humid)
+{
+    mkdir("/sd", 0777);           // All other times open file in append mode
+    FILE *fp = fopen("/sd/node1.csv","a");
+    fprintf(fp,"%4.2f, %4.2f\r\n",temp, humid);
+    fclose(fp);
+    blinkBLUE();
+}
+
+///////////////////////////////////////////////////////////////////////
+#define BROADCAST_TIME      25     //sleep time
+float temp,humid; 
+
+int main(){
+    
+    wdt_sleep.wdtClkSetup(WDTCLK_SRC_IRC_OSC);
+    
+    PWRON:
+    // get temp and humidity
+    getTempHumid(&temp, &humid);
+    
+    sdWrite(temp, humid);
+
+    // send data to ThingSpeak.com
+    sendToThingSpeak(temp, humid);
+    
+    //sleep
+    wdt_sleep.sleep(BROADCAST_TIME);
+    
+    //wake
+    goto PWRON;
+    
+        
+    
+}
\ No newline at end of file