Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GPRSInterface by
Revision 10:698c04e25c6b, committed 2015-09-25
- Comitter:
- noahmilam
- Date:
- Fri Sep 25 03:35:58 2015 +0000
- Parent:
- 9:5afc5b4e2df8
- Commit message:
- first commit
Changed in this revision
diff -r 5afc5b4e2df8 -r 698c04e25c6b GPRS/GPRS.cpp --- a/GPRS/GPRS.cpp Fri Jul 25 10:42:42 2014 +0000 +++ b/GPRS/GPRS.cpp Fri Sep 25 03:35:58 2015 +0000 @@ -42,7 +42,47 @@ } return checkSIMStatus(); } +// added by Noah Milam +void GPRS::start_server() +{ + sendCmdResp("AT+CGATT?\r\n"); + + sendCmdResp("AT+CIPSERVER=1,\"1234\"\r\n"); + wait_for_sms(); + store_response(); + listen_server(); +} +void GPRS::listen_server() +{ + gprs_response(); +} + +void GPRS::send_SMS(char* IPAdress) +{ + printf("sending at command\n"); + sendCmdAndWaitForResp("AT+CMGF=1\r\n","OK",DEFAULT_TIMEOUT,CMD); + wait(2); + //printf("\032\n"); + sendCmdAndWaitForResp("AT+CMGS=\"+14358306480\"\r\n",">",DEFAULT_TIMEOUT,CMD); + printf("sent at cmgf\n"); + wait(2); + //printf("032"); + sendCmd(IPAdress); // sends the address + sendCmd("\x1a"); // this is like pressing control - z to end the send command + wait(10); // giving the send enough time to do its thing + printf("should have been received"); +} +void GPRS::read_SMS() +{ + wait(1); + sendCmd("AT+CMGF=1\r\n"); + wait(2); + sendCmd("AT+CMGL=\"ALL\"\r\n"); + store_response(); +} + +// end of what Noah Milam added bool GPRS::checkSIMStatus(void) { char gprsBuffer[32];
diff -r 5afc5b4e2df8 -r 698c04e25c6b GPRS/GPRS.h --- a/GPRS/GPRS.h Fri Jul 25 10:42:42 2014 +0000 +++ b/GPRS/GPRS.h Fri Sep 25 03:35:58 2015 +0000 @@ -62,7 +62,13 @@ * @return true if connected, false otherwise */ bool join(void); - + // added by Noah Milam + void start_server(); + void send_SMS(char*); + void read_SMS(); + void listen_server(); + + // end of what Noah Milam added /** Disconnect the GPRS module from the network * @returns true if successful */ @@ -142,10 +148,10 @@ int new_socket(); uint16_t new_port(); uint32_t _ip; - + bool preInit(); protected: - bool preInit(); + bool checkSIMStatus(void); uint32_t str_to_ip(const char* str); static GPRS* inst;
diff -r 5afc5b4e2df8 -r 698c04e25c6b GPRS/modem/modem.cpp --- a/GPRS/modem/modem.cpp Fri Jul 25 10:42:42 2014 +0000 +++ b/GPRS/modem/modem.cpp Fri Sep 25 03:35:58 2015 +0000 @@ -21,7 +21,51 @@ */ #include "modem.h" +//Serial pc(USBTX,USBRX); +SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //MOSI, MISO, SCLK, SSEL. Tested on K64F, correct pins. +AnalogIn LM35(PTB2); +// added by Noah Milam +void Modem::gprs_response() +{ + printf("\nlistening for client\n"); + char buffer[100]; + int count = 0; + + mkdir("/sd/mydir", 0777); // makes directory if needed + FILE *fp = fopen("/sd/mydir/chemData.csv", "w"); // creats new file to write + fprintf(fp,"phone Number,chem data, latitude,longitude\n"); // writes in a header for the table + fclose(fp); // closes file + + while(1) + { + if(serialModem.readable()) { + + while(serialModem.readable()) { + char c = serialModem.getc(); + buffer[count++] = c; + } + } + if(buffer[0] != '\0'){ + buffer[count] = '\0'; + FILE *fp = fopen("/sd/mydir/chemData.csv", "a"); // opens file to append it + fprintf(fp,"%s\n",buffer);//writes to file + fclose(fp); // closes file + printf("%s \n",buffer); + } + for(int i = 0; i < count+2; i++) {buffer[i] = NULL;} + count = 0; + } +} +void Modem::wait_for_sms(){ + printf("waiting for message\n"); + while(1){ + if(serialModem.readable()){ + return; + } + } +} +//end added by Noah Milam char Modem::readByte(void) { return serialModem.getc(); @@ -63,7 +107,45 @@ { serialModem.puts(cmd); } +void Modem::sendCmdResp(const char* cmd) +{ + serialModem.puts(cmd); + getResp(); +} +void Modem::getResp() +{ + char buffer[100]; + int count = 0; + timeCnt.start(); + while(timeCnt.read() < 5) + { while(serialModem.readable()) { + char c = serialModem.getc(); + buffer[count++] = c; + } + } + timeCnt.stop(); + timeCnt.reset(); + buffer[count] = '\0'; + printf("%s \n",buffer); + for(int i = 0; i < count+2; i++) { + buffer[i] = NULL; + } + count = 0; +} +void Modem::store_response() +{ + timeCnt.start(); + while(timeCnt.read() < 20) + { while(serialModem.readable()) + { + char c = serialModem.getc(); + printf(&c); + } + } + timeCnt.stop(); + timeCnt.reset(); +} void Modem::sendATTest(void) { sendCmdAndWaitForResp("AT\r\n","OK",DEFAULT_TIMEOUT,CMD);
diff -r 5afc5b4e2df8 -r 698c04e25c6b GPRS/modem/modem.h --- a/GPRS/modem/modem.h Fri Jul 25 10:42:42 2014 +0000 +++ b/GPRS/modem/modem.h Fri Sep 25 03:35:58 2015 +0000 @@ -24,7 +24,7 @@ #define __MODEM_H__ #include "mbed.h" - +#include "SDFileSystem.h" #define DEFAULT_TIMEOUT 5 enum DataType { @@ -47,7 +47,13 @@ Modem(PinName tx, PinName rx, int baudRate) : serialModem(tx, rx) { serialModem.baud(baudRate); }; - + // added by Noah Milam + void sendCmdResp(const char*); + void getResp(); + void gprs_response(); + void store_response(); + void wait_for_sms(); + // Serial serialModem; protected: /** Power on Modem
diff -r 5afc5b4e2df8 -r 698c04e25c6b GPRSInterface.h --- a/GPRSInterface.h Fri Jul 25 10:42:42 2014 +0000 +++ b/GPRSInterface.h Fri Sep 25 03:35:58 2015 +0000 @@ -63,7 +63,9 @@ * @returns ip address */ char* getIPAddress(); - + + + bool checkOK(); private: char ip_string[20];