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
Diff: source/main.cpp
- Revision:
- 37:fcb5efa391d5
- Parent:
- 36:32a0a71555f0
- Child:
- 38:0813e461b835
--- a/source/main.cpp Thu Aug 01 03:43:28 2019 +0000 +++ b/source/main.cpp Thu Aug 01 04:36:59 2019 +0000 @@ -103,6 +103,11 @@ } 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(); @@ -113,20 +118,41 @@ continue; } tweet = compute_intensity(mail->x, mail->y); + semaforo.lock(); pc.printf("%s\n\r",tweet); semaforo.unlock(); mail_meass.free(mail); - 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); + 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 httpbin.org + // 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"); - - const char body[] = "{\"hello\":\"world\"}"; + + // 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) {