seeedstudio ARCH GPRS Test for GPRS function
Fork of ARCH_GPRS_Demo by
ARCH GPRS Introduction
- 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; }
ARCH_GPRS_HW/ARCH_GPRS_HW.cpp@0:6d297fe482af, 2013-08-23 (annotated)
- Committer:
- loovee
- Date:
- Fri Aug 23 02:31:06 2013 +0000
- Revision:
- 0:6d297fe482af
seeedstudio Arch Gprs Demo. ; ; post data to yeelink.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
loovee | 0:6d297fe482af | 1 | /* |
loovee | 0:6d297fe482af | 2 | IOT_hw.cpp |
loovee | 0:6d297fe482af | 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. |
loovee | 0:6d297fe482af | 4 | |
loovee | 0:6d297fe482af | 5 | Author:Loovee |
loovee | 0:6d297fe482af | 6 | 2013-7-21 |
loovee | 0:6d297fe482af | 7 | |
loovee | 0:6d297fe482af | 8 | This library is free software; you can redistribute it and/or |
loovee | 0:6d297fe482af | 9 | modify it under the terms of the GNU Lesser General Public |
loovee | 0:6d297fe482af | 10 | License as published by the Free Software Foundation; either |
loovee | 0:6d297fe482af | 11 | version 2.1 of the License, or (at your option) any later version. |
loovee | 0:6d297fe482af | 12 | |
loovee | 0:6d297fe482af | 13 | This library is distributed in the hope that it will be useful, |
loovee | 0:6d297fe482af | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
loovee | 0:6d297fe482af | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
loovee | 0:6d297fe482af | 16 | Lesser General Public License for more details. |
loovee | 0:6d297fe482af | 17 | |
loovee | 0:6d297fe482af | 18 | You should have received a copy of the GNU Lesser General Public |
loovee | 0:6d297fe482af | 19 | License along with this library; if not, write to the Free Software |
loovee | 0:6d297fe482af | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
loovee | 0:6d297fe482af | 21 | */ |
loovee | 0:6d297fe482af | 22 | |
loovee | 0:6d297fe482af | 23 | #include "mbed.h" |
loovee | 0:6d297fe482af | 24 | #include "tcp_yeelink.h" |
loovee | 0:6d297fe482af | 25 | #include "tcp_yeelink_dfs.h" |
loovee | 0:6d297fe482af | 26 | #include "ARCH_GPRS_HW.h" |
loovee | 0:6d297fe482af | 27 | #include "ARCH_GPRS_HW_DFS.h" |
loovee | 0:6d297fe482af | 28 | |
loovee | 0:6d297fe482af | 29 | DigitalOut eg10_pwr(PINPWR); |
loovee | 0:6d297fe482af | 30 | DigitalOut eg10_on(PINONOFF); |
loovee | 0:6d297fe482af | 31 | DigitalInOut eg10_state(PINEGSTATE); |
loovee | 0:6d297fe482af | 32 | DigitalOut eg10_rst(PINSYSRST); |
loovee | 0:6d297fe482af | 33 | |
loovee | 0:6d297fe482af | 34 | DigitalOut led1(PINLED1); |
loovee | 0:6d297fe482af | 35 | DigitalOut led2(PINLED2); |
loovee | 0:6d297fe482af | 36 | DigitalOut led3(PINLED3); |
loovee | 0:6d297fe482af | 37 | DigitalOut led4(PINLED4); |
loovee | 0:6d297fe482af | 38 | |
loovee | 0:6d297fe482af | 39 | DigitalOut grove_pwr(GROVE_PWR); |
loovee | 0:6d297fe482af | 40 | DigitalIn charging(PIN_CHRGING); |
loovee | 0:6d297fe482af | 41 | DigitalIn chargdone(PIN_CHRGDONE); |
loovee | 0:6d297fe482af | 42 | |
loovee | 0:6d297fe482af | 43 | AnalogIn vol_bat(PIN_READBAT); |
loovee | 0:6d297fe482af | 44 | |
loovee | 0:6d297fe482af | 45 | void IOT_HW::EG10_PWRON() |
loovee | 0:6d297fe482af | 46 | { |
loovee | 0:6d297fe482af | 47 | eg10_pwr = 0; |
loovee | 0:6d297fe482af | 48 | } |
loovee | 0:6d297fe482af | 49 | |
loovee | 0:6d297fe482af | 50 | void IOT_HW::EG10_PWROFF() |
loovee | 0:6d297fe482af | 51 | { |
loovee | 0:6d297fe482af | 52 | eg10_pwr = 1; |
loovee | 0:6d297fe482af | 53 | } |
loovee | 0:6d297fe482af | 54 | |
loovee | 0:6d297fe482af | 55 | void IOT_HW::EG10_ON() |
loovee | 0:6d297fe482af | 56 | { |
loovee | 0:6d297fe482af | 57 | eg10_on = 0; |
loovee | 0:6d297fe482af | 58 | wait(2); |
loovee | 0:6d297fe482af | 59 | eg10_on = 1; |
loovee | 0:6d297fe482af | 60 | } |
loovee | 0:6d297fe482af | 61 | |
loovee | 0:6d297fe482af | 62 | int IOT_HW::init() |
loovee | 0:6d297fe482af | 63 | { |
loovee | 0:6d297fe482af | 64 | init_io(); |
loovee | 0:6d297fe482af | 65 | EG10_PWROFF(); |
loovee | 0:6d297fe482af | 66 | wait(2); // wait 2s |
loovee | 0:6d297fe482af | 67 | EG10_PWRON(); |
loovee | 0:6d297fe482af | 68 | EG10_PWRON(); |
loovee | 0:6d297fe482af | 69 | EG10_ON(); |
loovee | 0:6d297fe482af | 70 | return (IOT.waitString("M2MRSSI", 30)); |
loovee | 0:6d297fe482af | 71 | } |
loovee | 0:6d297fe482af | 72 | |
loovee | 0:6d297fe482af | 73 | void IOT_HW::init_io() |
loovee | 0:6d297fe482af | 74 | { |
loovee | 0:6d297fe482af | 75 | eg10_pwr = 1; |
loovee | 0:6d297fe482af | 76 | eg10_on = 1; |
loovee | 0:6d297fe482af | 77 | } |
loovee | 0:6d297fe482af | 78 | |
loovee | 0:6d297fe482af | 79 | int IOT_HW::getEG10_State() |
loovee | 0:6d297fe482af | 80 | { |
loovee | 0:6d297fe482af | 81 | eg10_state.input(); |
loovee | 0:6d297fe482af | 82 | eg10_state.mode(PullDown); |
loovee | 0:6d297fe482af | 83 | if(eg10_state.read()) |
loovee | 0:6d297fe482af | 84 | { |
loovee | 0:6d297fe482af | 85 | return 1; |
loovee | 0:6d297fe482af | 86 | } |
loovee | 0:6d297fe482af | 87 | return 0; |
loovee | 0:6d297fe482af | 88 | } |
loovee | 0:6d297fe482af | 89 | |
loovee | 0:6d297fe482af | 90 | void IOT_HW::EG10StateLed(unsigned char state) |
loovee | 0:6d297fe482af | 91 | { |
loovee | 0:6d297fe482af | 92 | eg10_state.output(); |
loovee | 0:6d297fe482af | 93 | eg10_state = 1-state; |
loovee | 0:6d297fe482af | 94 | } |
loovee | 0:6d297fe482af | 95 | |
loovee | 0:6d297fe482af | 96 | void IOT_HW::userLed(unsigned char led, unsigned char state) |
loovee | 0:6d297fe482af | 97 | { |
loovee | 0:6d297fe482af | 98 | // if(state!=0 || state!=1)return; |
loovee | 0:6d297fe482af | 99 | |
loovee | 0:6d297fe482af | 100 | if(1==led)led1 = state; |
loovee | 0:6d297fe482af | 101 | else if(2==led)led2 = state; |
loovee | 0:6d297fe482af | 102 | else if(3==led)led3 = state; |
loovee | 0:6d297fe482af | 103 | else if(4==led)led4 = state; |
loovee | 0:6d297fe482af | 104 | |
loovee | 0:6d297fe482af | 105 | } |
loovee | 0:6d297fe482af | 106 | |
loovee | 0:6d297fe482af | 107 | int IOT_HW::readChrgState() |
loovee | 0:6d297fe482af | 108 | { |
loovee | 0:6d297fe482af | 109 | if(!charging.read())return CHRGDONE; |
loovee | 0:6d297fe482af | 110 | if(!chargdone.read())return CHRGING; |
loovee | 0:6d297fe482af | 111 | return NOCHRG; |
loovee | 0:6d297fe482af | 112 | } |
loovee | 0:6d297fe482af | 113 | |
loovee | 0:6d297fe482af | 114 | float IOT_HW::readBatVol() |
loovee | 0:6d297fe482af | 115 | { |
loovee | 0:6d297fe482af | 116 | unsigned int tmp = vol_bat.read_u16(); |
loovee | 0:6d297fe482af | 117 | |
loovee | 0:6d297fe482af | 118 | return tmp; |
loovee | 0:6d297fe482af | 119 | float dr = tmp; |
loovee | 0:6d297fe482af | 120 | dr = dr/65536.0*3.3*2.0; |
loovee | 0:6d297fe482af | 121 | return dr; |
loovee | 0:6d297fe482af | 122 | // return ((float tmp)/65536.0*3.3*2.0); |
loovee | 0:6d297fe482af | 123 | } |
loovee | 0:6d297fe482af | 124 | |
loovee | 0:6d297fe482af | 125 | void IOT_HW::grovePwrOn() |
loovee | 0:6d297fe482af | 126 | { |
loovee | 0:6d297fe482af | 127 | grove_pwr = 0; |
loovee | 0:6d297fe482af | 128 | } |
loovee | 0:6d297fe482af | 129 | |
loovee | 0:6d297fe482af | 130 | void IOT_HW::grovePwrOff() |
loovee | 0:6d297fe482af | 131 | { |
loovee | 0:6d297fe482af | 132 | grove_pwr = 1; |
loovee | 0:6d297fe482af | 133 | } |
loovee | 0:6d297fe482af | 134 | |
loovee | 0:6d297fe482af | 135 | |
loovee | 0:6d297fe482af | 136 | IOT_HW iot_hw; |
loovee | 0:6d297fe482af | 137 | /********************************************************************************************************* |
loovee | 0:6d297fe482af | 138 | END FILE |
loovee | 0:6d297fe482af | 139 | *********************************************************************************************************/ |