Senses an earthquake with MPU6050 and gets time, coordenates and other details of the event with an Adafruit GPS. All the info is sent to an HTTP server

Dependencies:   MPU6050 mbed-http MBed_Adafruit-GPS-Library

Files at this revision

API Documentation at this revision

Comitter:
Alvaro13
Date:
Thu Aug 01 05:05:55 2019 +0000
Parent:
37:fcb5efa391d5
Commit message:
program reseted

Changed in this revision

source/main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r fcb5efa391d5 -r 0813e461b835 source/main.cpp
--- a/source/main.cpp	Thu Aug 01 04:36:59 2019 +0000
+++ b/source/main.cpp	Thu Aug 01 05:05:55 2019 +0000
@@ -6,9 +6,6 @@
 #include "FUNCTIONS.h"
 #include "Timer.h"
 #include "MBed_Adafruit_GPS.h"
-#include "http_request.h"
-#include "network-helper.h"
-#include "mbed_mem_trace.h"
 
 /**
 * Debbuging led
@@ -63,51 +60,12 @@
 */
 Adafruit_GPS myGPS(new Serial(PC_12, PD_2)); //object of Adafruit's GPS class
 
-/**
-* Codigo para el HTTP post
-*/
-void dump_response(HttpResponse* res) {
-    printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
-
-    printf("Headers:\n");
-    for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
-        printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
-    }
-    printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
-}
 
 /**
 * Imprime los resultados de la medicion del sismo
 */
 void print_debug(){    
     string tweet;
-    NetworkInterface* network = connect_to_default_network_interface();
-    if (!network) {
-        printf("Cannot connect to the network, see serial output\n");
-        return ;
-    }
-    // Create a TCP socket
-    printf("\n----- Setting up TCP connection -----\n");
-
-    TCPSocket* socket = new TCPSocket();
-    nsapi_error_t open_result = socket->open(network);
-    if (open_result != 0) {
-        printf("Opening TCPSocket failed... %d\n", open_result);
-        return ;
-    }
-    
-    nsapi_error_t connect_result = socket->connect("10.60.16.220", 80);
-    if (connect_result != 0) {
-        printf("Connecting over TCPSocket failed... %d\n", connect_result);
-        return ;
-    }
-    
-    printf("Connected over TCP to httpbin.org:80\n");
-    char timeChar[20]; //string para la hora
-    char dateChar[20]; //string para la fecha
-    char locationChar[20]; //string para las coordenadas
-    char altitudeChar[20]; //string para la altura
-    char tweetChar[30]; //string para el tweet
     while(true){
         wait(1);
         osEvent evt = mail_meass.get();
@@ -118,52 +76,14 @@
                 continue;
             }
             tweet = compute_intensity(mail->x, mail->y);
-            
             semaforo.lock();
             pc.printf("%s\n\r",tweet);
             semaforo.unlock();
             mail_meass.free(mail);
-            strcpy(tweetChar, tweet.c_str());
-            sprintf(timeChar,"%d:%d:%d.%u\r\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
-            sprintf(dateChar,"%d/%d/20%d\r\n", myGPS.day, myGPS.month, myGPS.year);
-            sprintf(locationChar,"%f%c, %f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-            sprintf(altitudeChar,"%f\r\n", myGPS.altitude);
-            
-            // POST request to http server
-            HttpRequest* post_req = new HttpRequest(socket, HTTP_POST, "http://10.60.16.200");
-            post_req->set_header("Content-Type", "application/json");
-            
-            // Formando el JSON de salida en la variable body
-            char body[90];
-            strcpy (body,"{\"Message\":\"");
-            strcat (body, tweetChar);
-            strcat (body, "\", ");
-            strcat (body,"\"Time\":\"");
-            strcat (body, timeChar);
-            strcat (body, "\", ");
-            strcat (body,"\"Date\":\"");
-            strcat (body, dateChar);
-            strcat (body, "\", ");
-            strcat (body,"\"Location\":\"");
-            strcat (body, locationChar);
-            strcat (body, "\", ");
-            strcat (body,"\"Altitude\":\"");
-            strcat (body, altitudeChar);
-            strcat (body, "\"");
-            strcat (body, "}");
-            
-            pc.printf("%s\n\r",body);
-
-            HttpResponse* post_res = post_req->send(body, strlen(body));
-            if (!post_res) {
-                printf("HttpRequest failed (error code %d)\n", post_req->get_error());
-                return ;
-            }
-
-            printf("\n----- HTTP POST response -----\n");
-            dump_response(post_res);
-
-            delete post_req;
+            pc.printf("Time: %d:%d:%d.%u\r\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
+            pc.printf("Date: %d/%d/20%d\r\n", myGPS.day, myGPS.month, myGPS.year);
+            pc.printf("Location: %f%c, %f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+            pc.printf("Altitude: %f\r\n", myGPS.altitude);
             
         }    
     }