Leest de waarde van een sensor binnen een maakt deze beschikbaar via internet

Dependencies:   NTPClient_NetServices mbed

Committer:
hendrikvincent
Date:
Mon Dec 02 09:01:23 2013 +0000
Revision:
0:05ccbd4f84f1
eerste programma;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hendrikvincent 0:05ccbd4f84f1 1
hendrikvincent 0:05ccbd4f84f1 2 /*
hendrikvincent 0:05ccbd4f84f1 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hendrikvincent 0:05ccbd4f84f1 4
hendrikvincent 0:05ccbd4f84f1 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hendrikvincent 0:05ccbd4f84f1 6 of this software and associated documentation files (the "Software"), to deal
hendrikvincent 0:05ccbd4f84f1 7 in the Software without restriction, including without limitation the rights
hendrikvincent 0:05ccbd4f84f1 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hendrikvincent 0:05ccbd4f84f1 9 copies of the Software, and to permit persons to whom the Software is
hendrikvincent 0:05ccbd4f84f1 10 furnished to do so, subject to the following conditions:
hendrikvincent 0:05ccbd4f84f1 11
hendrikvincent 0:05ccbd4f84f1 12 The above copyright notice and this permission notice shall be included in
hendrikvincent 0:05ccbd4f84f1 13 all copies or substantial portions of the Software.
hendrikvincent 0:05ccbd4f84f1 14
hendrikvincent 0:05ccbd4f84f1 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hendrikvincent 0:05ccbd4f84f1 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hendrikvincent 0:05ccbd4f84f1 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hendrikvincent 0:05ccbd4f84f1 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hendrikvincent 0:05ccbd4f84f1 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hendrikvincent 0:05ccbd4f84f1 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hendrikvincent 0:05ccbd4f84f1 21 THE SOFTWARE.
hendrikvincent 0:05ccbd4f84f1 22 */
hendrikvincent 0:05ccbd4f84f1 23
hendrikvincent 0:05ccbd4f84f1 24 #include "netCfg.h"
hendrikvincent 0:05ccbd4f84f1 25 #if NET_GPRS_MODULE
hendrikvincent 0:05ccbd4f84f1 26
hendrikvincent 0:05ccbd4f84f1 27 #include "GPRSModuleNetIf.h"
hendrikvincent 0:05ccbd4f84f1 28
hendrikvincent 0:05ccbd4f84f1 29 #define __DEBUG
hendrikvincent 0:05ccbd4f84f1 30 #include "dbg/dbg.h"
hendrikvincent 0:05ccbd4f84f1 31
hendrikvincent 0:05ccbd4f84f1 32 GPRSModuleNetIf::GPRSModuleNetIf(PinName tx, PinName rx, int baud /*= 115200*/) : PPPNetIf(NULL), m_serial(tx, rx)
hendrikvincent 0:05ccbd4f84f1 33 {
hendrikvincent 0:05ccbd4f84f1 34 PPPNetIf::m_pIf = new GPRSModem();
hendrikvincent 0:05ccbd4f84f1 35 m_serial.baud(baud);
hendrikvincent 0:05ccbd4f84f1 36 }
hendrikvincent 0:05ccbd4f84f1 37
hendrikvincent 0:05ccbd4f84f1 38 GPRSModuleNetIf::~GPRSModuleNetIf()
hendrikvincent 0:05ccbd4f84f1 39 {
hendrikvincent 0:05ccbd4f84f1 40 delete PPPNetIf::m_pIf;
hendrikvincent 0:05ccbd4f84f1 41 }
hendrikvincent 0:05ccbd4f84f1 42
hendrikvincent 0:05ccbd4f84f1 43 PPPErr GPRSModuleNetIf::connect(const char* apn /*= NULL*/, const char* userId /*= NULL*/, const char* password /*= NULL*/) //Connect using GPRS
hendrikvincent 0:05ccbd4f84f1 44 {
hendrikvincent 0:05ccbd4f84f1 45
hendrikvincent 0:05ccbd4f84f1 46 DBG("Powering on module.\n")
hendrikvincent 0:05ccbd4f84f1 47 if(!setOn()) //Could not power on module
hendrikvincent 0:05ccbd4f84f1 48 {
hendrikvincent 0:05ccbd4f84f1 49 DBG("Could not power on module.\n");
hendrikvincent 0:05ccbd4f84f1 50 return PPP_MODEM;
hendrikvincent 0:05ccbd4f84f1 51 }
hendrikvincent 0:05ccbd4f84f1 52
hendrikvincent 0:05ccbd4f84f1 53 //wait(10); //Wait for module to init.
hendrikvincent 0:05ccbd4f84f1 54
hendrikvincent 0:05ccbd4f84f1 55 ATErr atErr;
hendrikvincent 0:05ccbd4f84f1 56 for(int i=0; i<3; i++)
hendrikvincent 0:05ccbd4f84f1 57 {
hendrikvincent 0:05ccbd4f84f1 58 atErr = m_pIf->open(&m_serial); //3 tries
hendrikvincent 0:05ccbd4f84f1 59 if(!atErr)
hendrikvincent 0:05ccbd4f84f1 60 break;
hendrikvincent 0:05ccbd4f84f1 61 DBG("Could not open AT If, trying again.\n");
hendrikvincent 0:05ccbd4f84f1 62 wait(4);
hendrikvincent 0:05ccbd4f84f1 63 }
hendrikvincent 0:05ccbd4f84f1 64
hendrikvincent 0:05ccbd4f84f1 65 if(atErr)
hendrikvincent 0:05ccbd4f84f1 66 {
hendrikvincent 0:05ccbd4f84f1 67 setOff();
hendrikvincent 0:05ccbd4f84f1 68 return PPP_MODEM;
hendrikvincent 0:05ccbd4f84f1 69 }
hendrikvincent 0:05ccbd4f84f1 70
hendrikvincent 0:05ccbd4f84f1 71 DBG("AT If opened.\n");
hendrikvincent 0:05ccbd4f84f1 72
hendrikvincent 0:05ccbd4f84f1 73 PPPErr pppErr;
hendrikvincent 0:05ccbd4f84f1 74 for(int i=0; i<3; i++)
hendrikvincent 0:05ccbd4f84f1 75 {
hendrikvincent 0:05ccbd4f84f1 76 DBG("Trying to connect.\n");
hendrikvincent 0:05ccbd4f84f1 77 pppErr = PPPNetIf::GPRSConnect(apn, userId, password);
hendrikvincent 0:05ccbd4f84f1 78 if(!pppErr)
hendrikvincent 0:05ccbd4f84f1 79 break;
hendrikvincent 0:05ccbd4f84f1 80 DBG("Could not connect.\n");
hendrikvincent 0:05ccbd4f84f1 81 wait(4);
hendrikvincent 0:05ccbd4f84f1 82 }
hendrikvincent 0:05ccbd4f84f1 83 if(pppErr)
hendrikvincent 0:05ccbd4f84f1 84 {
hendrikvincent 0:05ccbd4f84f1 85 setOff();
hendrikvincent 0:05ccbd4f84f1 86 return pppErr;
hendrikvincent 0:05ccbd4f84f1 87 }
hendrikvincent 0:05ccbd4f84f1 88
hendrikvincent 0:05ccbd4f84f1 89 DBG("Connected.\n");
hendrikvincent 0:05ccbd4f84f1 90
hendrikvincent 0:05ccbd4f84f1 91 return PPP_OK;
hendrikvincent 0:05ccbd4f84f1 92 }
hendrikvincent 0:05ccbd4f84f1 93
hendrikvincent 0:05ccbd4f84f1 94 PPPErr GPRSModuleNetIf::disconnect()
hendrikvincent 0:05ccbd4f84f1 95 {
hendrikvincent 0:05ccbd4f84f1 96 DBG("Disconnecting...\n");
hendrikvincent 0:05ccbd4f84f1 97 PPPErr pppErr = PPPNetIf::disconnect();
hendrikvincent 0:05ccbd4f84f1 98 if(pppErr)
hendrikvincent 0:05ccbd4f84f1 99 return pppErr;
hendrikvincent 0:05ccbd4f84f1 100
hendrikvincent 0:05ccbd4f84f1 101 m_pIf->close();
hendrikvincent 0:05ccbd4f84f1 102
hendrikvincent 0:05ccbd4f84f1 103 DBG("Powering off module.\n")
hendrikvincent 0:05ccbd4f84f1 104 setOff(); //Power off module
hendrikvincent 0:05ccbd4f84f1 105
hendrikvincent 0:05ccbd4f84f1 106 DBG("Off.\n")
hendrikvincent 0:05ccbd4f84f1 107
hendrikvincent 0:05ccbd4f84f1 108 return PPP_OK;
hendrikvincent 0:05ccbd4f84f1 109 }
hendrikvincent 0:05ccbd4f84f1 110
hendrikvincent 0:05ccbd4f84f1 111
hendrikvincent 0:05ccbd4f84f1 112 #endif