tester

Fork of GPRSInterface by -deleted-

Files at this revision

API Documentation at this revision

Comitter:
noahmilam
Date:
Fri Sep 25 04:10:56 2015 +0000
Parent:
9:5afc5b4e2df8
Commit message:
ff

Changed in this revision

GPRS/GPRS.cpp Show annotated file Show diff for this revision Revisions of this file
GPRS/GPRS.h Show annotated file Show diff for this revision Revisions of this file
GPRS/modem/modem.cpp Show annotated file Show diff for this revision Revisions of this file
GPRS/modem/modem.h Show annotated file Show diff for this revision Revisions of this file
GPRSInterface.h Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5afc5b4e2df8 -r 8c55dfcc9a7c GPRS/GPRS.cpp
--- a/GPRS/GPRS.cpp	Fri Jul 25 10:42:42 2014 +0000
+++ b/GPRS/GPRS.cpp	Fri Sep 25 04:10:56 2015 +0000
@@ -42,7 +42,51 @@
     }
     return checkSIMStatus();
 }
+// added by Noah Milam
+void GPRS::start_server()
+{     
+     sendCmdResp("AT+CGATT?\r\n");
+     
+     sendCmdResp("AT+CIPSERVER=1,8080\r\n");
+     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=\"+18183977481\"\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");
+}
 
+char* GPRS::read_SMS()
+{
+ wait(1);
+    sendCmd("AT+CMGF=1\r\n"); // sms mode
+    wait(2);
+    sendCmd("AT+CMGD=1\r\n"); // delete the frist message so incoming message is spot 1
+    wait(1);
+    wait_for_sms();
+    wait(10);  
+    sendCmd("AT+CMGR=1\r\n");
+    storeResp();
+    char temp[30];
+    return get_server_IP();
+}
+
+// end of what Noah Milam added
 bool GPRS::checkSIMStatus(void)
 {
     char gprsBuffer[32];
diff -r 5afc5b4e2df8 -r 8c55dfcc9a7c GPRS/GPRS.h
--- a/GPRS/GPRS.h	Fri Jul 25 10:42:42 2014 +0000
+++ b/GPRS/GPRS.h	Fri Sep 25 04:10:56 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*);
+	char* 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 8c55dfcc9a7c 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 04:10:56 2015 +0000
@@ -21,7 +21,102 @@
 */
 
 #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;
+                //pc.puts(&c);
+                if(count == 64) break;
+            }
+            
+            if(buffer[0] != '\0'){
+                buffer[count] = '\0';
+                FILE *fp = fopen("/sd/mydir/chemicalData.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;
+        }    
+    }
+}
+void Modem::get_message(){
+    char tempStr[30];
+    int count= 0;
+    int line_count = 0;
+    for(int i= 0;i < strlen(IPAdd);i++){
+            if(line_count == 3){
+                tempStr[count++] = IPAdd[i];    
+            }
+            if(IPAdd[i] == '\n'){
+                line_count++;
+            }
+    } 
+    tempStr[count - 2] = '\0';
+    count++;
+    strncpy(IPAdd, tempStr, count);
+   printf("IP Addr > %s \n", IPAdd);
+   printf("text size > %d\n",strlen(IPAdd));
+ } 
+void Modem::storeResp(){
+    
+    int line_count = 0;
+    int read = -1;
+    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';
+
+     strncpy(IPAdd, buffer, count);
+    printf("original>> %s",IPAdd);
+   printf("size of text > %d",strlen(IPAdd));
+    count = 0;
+    get_message();
+}   
+
+char* Modem::get_server_IP(){
+    return IPAdd;
+}
+//end added by Noah Milam
 char Modem::readByte(void)
 {
     return serialModem.getc();
@@ -63,6 +158,32 @@
 {
     serialModem.puts(cmd);
 }
+void Modem::sendCmdResp(const char* cmd)
+{
+    serialModem.puts(cmd);
+    getResp();
+}
+void Modem::getResp()
+{
+   char buffer[1000];
+     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::sendATTest(void)
 {
diff -r 5afc5b4e2df8 -r 8c55dfcc9a7c 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 04:10:56 2015 +0000
@@ -24,7 +24,7 @@
 #define __MODEM_H__
 
 #include "mbed.h"
-
+#include "SDFileSystem.h"
 #define DEFAULT_TIMEOUT   	5
 
 enum DataType {
@@ -47,7 +47,16 @@
     Modem(PinName tx, PinName rx, int baudRate) : serialModem(tx, rx) {
         serialModem.baud(baudRate);
     };
-	
+    // added by Noah Milam
+    char IPAdd[100];
+    void sendCmdResp(const char*);
+	void getResp();
+	void gprs_response();
+	void storeResp();
+	void wait_for_sms();
+	void get_message();
+	char* get_server_IP();
+	//
 	Serial serialModem;
 protected:
     /** Power on Modem
diff -r 5afc5b4e2df8 -r 8c55dfcc9a7c GPRSInterface.h
--- a/GPRSInterface.h	Fri Jul 25 10:42:42 2014 +0000
+++ b/GPRSInterface.h	Fri Sep 25 04:10:56 2015 +0000
@@ -63,7 +63,9 @@
      *  @returns ip address
      */
     char* getIPAddress();
-
+    
+    
+    bool checkOK();
 private:
 
     char ip_string[20];
diff -r 5afc5b4e2df8 -r 8c55dfcc9a7c Socket/TCPSocketConnection.cpp
--- a/Socket/TCPSocketConnection.cpp	Fri Jul 25 10:42:42 2014 +0000
+++ b/Socket/TCPSocketConnection.cpp	Fri Sep 25 04:10:56 2015 +0000
@@ -28,6 +28,7 @@
 
 int TCPSocketConnection::connect(const char* host, const int port)
 {
+    printf(">%s<",host);
     if (_sock_fd < 0) {
         _sock_fd = gprs->new_socket();
         if (_sock_fd < 0) {