Small Testprogram to have WebAccess via Webserver to a 433Mhz tranmitter to control remotly some devices from remote, with TFTP, NTP and RMF. This could be a base to develop applications.

Dependencies:   ChaNFSSD TFTPServer RMFWeb

Dependents:   RMFWeb

Committer:
ED7418
Date:
Mon Jun 16 07:40:08 2014 +0000
Revision:
1:809b59c7a800
Parent:
0:51f1ef89ec7b
mbed-lib and other libs are a based on a project, published in a Elektor-book "ARM-microkontroller Part II".

Who changed what in which revision?

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