seeedstudio ARCH GPRS Test for GPRS function

Dependencies:   GPRS mbed

Fork of ARCH_GPRS_Demo by hs loovee

ARCH GPRS Introduction

ARCH GPRS

  • Arch GPRS is a wireless network module based on EG-10, it can achive remote data colletion function to communicate with outside world by GPRS network.
  • Arch GPRS has standard Arduino interface and Grove connectors. It’s convenient to connect existing Shields and Grove products to Arch GPRS.
  • You can use the solar panel to charge for battery, and own to its low-power design, so Arch GPRS can work normally in outdoor.
  • For more information, please visit http://www.seeedstudio.com/depot/arch-gprs-p-1657.html?cPath=6_11

main.cpp

/*
  main.cpp
  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
 
  Author:lawliet zou(lawliet.zou@gmail.com)
  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 "string.h"
#include "gprs.h"
 
#define SEND_SMS_TEST           0
#define CALL_UP_TEST            0
#define ANSWER_TEST             0
#define READ_SMS_TEST           0
 
#define PHONE_NUMBER            "150****9566"
 
#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
 
DigitalOut eg10_pwr(PINPWR);
DigitalOut eg10_on(PINONOFF);
GPRS  gprsTest(P0_19, P0_18, 115200, PHONE_NUMBER);
 
void EG10_PowerUp(void)
{
    eg10_pwr = 1;
    eg10_on  = 1;
    wait(2);
    eg10_pwr = 0;
    eg10_on = 0;
    wait(2);
    eg10_on = 1;
    wait(2);
}
 
int main(void)
{
    EG10_PowerUp();
    while(0 != gprsTest.init()) {
        wait(2);
    }
 
#if CALL_UP_TEST
    gprsTest.callUp(PHONE_NUMBER);
#endif
 
#if SEND_SMS_TEST
    gprsTest.sendSMS(PHONE_NUMBER,"hello,lawliet");
#endif
 
#if ANSWER_TEST || READ_SMS_TEST
    while(1) {
        int messageType = gprsTest.loopHandle();
        if(MESSAGE_RING == messageType) {
            gprsTest.answer();
        } else if(MESSAGE_SMS == messageType) {
            char smsMessage[SMS_MAX_LENGTH];
            gprsTest.getSMS(smsMessage);
        }
    }
#endif
 
    return 0;
}
Revision:
1:a686793fb3d6
Parent:
0:6d297fe482af
Child:
2:293881d1c5c9
--- a/main.cpp	Fri Aug 23 02:31:06 2013 +0000
+++ b/main.cpp	Fri Nov 15 09:54:59 2013 +0000
@@ -19,190 +19,68 @@
   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 "tcp_yeelink.h"
 #include "mbed.h"
-#include "tcp_yeelink_dfs.h"
-#include "ARCH_GPRS_HW.h"
-#include "i2c_uart.h"
-#include "ARCH_GPRS_Sleep.h"
-
-AnalogIn light_sensor(GROVE_ADC_1);
-
-#define BROADCAST_TIME            100                            // broadcast time : 100s
-
-// you can get this information in www.yeelink.net
-#define HTTP_POST_URL "http://api.yeelink.net/v1.0/device/4190/sensor/6074/datapoints"
+#include "string.h"
+#include "gprs.h"
 
-//#define HTTP_POST_URL_BAT "http://api.yeelink.net/v1.0/device/4190/sensor/6089/datapoints"
-
-#define YEELINK_APIKEY "38645582d54121679dee8104f140c29a"
-
-void delay_ms(long ms)
-{
-    if(ms <= 900)
-    {
-        wait_ms(ms);
-        wdt_sleep.feed();
-    }
-    else
-    {
-        ms -= 900;
-        delay_ms(900);
-    }
-}
+#define TRUE    1
+#define FALSE   0
 
-int getAnalog()
-{
-    long sum = 0;
-    for(int i=0; i<32; i++)
-    {
-        sum += light_sensor.read_u16();
-    }
-    sum = sum >> 5;
-    sum = sum >> 6;
-    return sum;
-}
-
-void power_on()
-{
-    IOT.init(HTTP_POST_URL, YEELINK_APIKEY);
-    START:
-    DBG("begin to start\r\n");
-    iot_hw.EG10_PWROFF();                           // eg10 power off
-    wait(0.5);
-    wdt_sleep.feed();
-    iot_hw.EG10_PWRON();                            // eg10 power on
-    wait(0.5);
-    wdt_sleep.feed();
+#define SERIAL_DEBUG            0
+#define SEND_SMS_TEST           0
+#define CALL_UP_TEST            0
+#define ANSWER_TEST             0
+#define READ_SMS_TEST           0
+#define TCP_TEST                0
 
-    if(iot_hw.init()==1)
-    {
-        iot_hw.EG10StateLed(1);
-        DBG("hardware init ok\r\n");
-    }
-    else
-    {
-        DBG("hardware init fail\r\n");
-        DBG("hardware init again\r\n");
-        goto START;
-    }
-    wdt_sleep.feed();
-}
-
-#define LOWPWR        1
-
-void iot_demo()
-{
-    wdt_sleep.wdtClkSetup(WDTCLK_SRC_IRC_OSC);
-
-    PWRON:
-    power_on();
-    for(int i=0; i<10; i++)
-    {
-        wdt_sleep.feed();
-        wait(0.9);
-        wdt_sleep.feed();
-    }
-    int dtaSw = 0;
-    while(1)
-    {
+#define IP_ADDRSS               "42.96.164.52"
+#define PORT                    "80"
 
-        int dtaVal = getAnalog()/10;
-
-        if(!IOT.postDtaToYeelink(HTTP_POST_URL, YEELINK_APIKEY, dtaVal))
-        {
-            DBG("post data err\r\n");
-            wdt_sleep.feed();
-            goto PWRON;
-        }
-        else
-        {
-            DBG("post data ok!\r\n");
-        }
-
-        iot_hw.userLed(1, 1);
-        wait(.2);
-        iot_hw.userLed(1, 0);
+#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
+DigitalOut eg10_pwr(PINPWR);
+DigitalOut eg10_on(PINONOFF);
 
-        for(int i=0; i<10; i++)
-        {
-            wdt_sleep.feed();
-            wait(0.5);
-        }
-#if LOWPWR
-        DBG("goto sleep for 100s");
-        iot_hw.EG10_PWROFF();
-        iot_hw.grovePwrOff();
-        wdt_sleep.sleep(BROADCAST_TIME);
-
-        DBG("wake");
-        goto PWRON;
-#else
-
-        wait(5);
-#endif
-    }
-}
-
-void wdt_sleep_demo()
-{
-    DBG("begin to poweron\r\n");
-    // power_on();
-    wdt_sleep.wdtClkSetup(WDTCLK_SRC_IRC_OSC);
+gprs  gprsTest(P0_19, P0_18, 115200,"13925257382");
 
-    // start led
-    for(int i=0; i<5; i++)
-    {
-        iot_hw.userLed(2, 1);wait_ms(100);
-        iot_hw.userLed(2, 0);wait_ms(100);
-    }
-
-
-    // cut power
-    for(int i=0; i<10; i++)
-    {
-        wait(0.1);
-        wdt_sleep.feed();
-    }
-    iot_hw.EG10_PWROFF();
-    iot_hw.grovePwrOff();
-
-    while(1)
-    {
-#if 0
-        DBG("sleep\r\n");
-        wait(0.1);
-        //wdt_sleep.gotoSleep();
-        DBG("wake\r\n");
-        for(int i=0; i<5; i++)
-        {
-            wait(1);
-            wdt_sleep.feed();
-        }
-#else
-        DBG("sleep 5s\r\n");
-        wait(0.1);
-        wdt_sleep.sleep(5);
-
-        DBG("wake\r\n");
-        for(int i=0; i<10; i++)
-        {
-            wait(0.5);
-            wdt_sleep.feed();
-        }
-
-#endif
-    }
+void EG10_PowerUp(void)
+{
+    eg10_pwr = 1;
+    eg10_on  = 1;
+    wait(2);
+    eg10_pwr = 0;
+    eg10_on = 0;
+    wait(2);
+    eg10_on = 1;
+    wait(2);
 }
 
-
 int main(void)
 {
-    //wdt_sleep_demo();
-    iot_demo();
-}
+
+    EG10_PowerUp();
+    gprsTest.init();
+    wait(2);
+    
+#if CALL_UP_TEST
+    gprsTest.callUp("13925257382");
+#endif
+
+#if SEND_SMS_TEST
+    gprsTest.sendSMS("13925257382","hello,lawliet");
+#endif
 
-/*********************************************************************************************************
-  END FILE
-*********************************************************************************************************/
+#if ANSWER_TEST || READ_SMS_TEST
+    gprsTest.loop(FALSE);
+#endif
+
+#if TCP_TEST
+    gprsTest.connectTCP(IP_ADDRSS,PORT);
+#endif
+
+#if SERIAL_DEBUG
+    gprsTest.serialDebug(USBTX,USBRX);
+#endif
+
+    return 0;
+}
\ No newline at end of file