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
Revision 36:32a0a71555f0, committed 2019-08-01
- Comitter:
- Alvaro13
- Date:
- Thu Aug 01 03:43:28 2019 +0000
- Parent:
- 35:4b847971db1b
- Child:
- 37:fcb5efa391d5
- Commit message:
- First commit!
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MBed_Adafruit-GPS-Library.lib Thu Aug 01 03:43:28 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/jorgmassih/code/MBed_Adafruit-GPS-Library/#130bb8aa6cf2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MPU6050.lib Thu Aug 01 03:43:28 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/moklumbys/code/MPU6050/#9b414412b09e
--- a/mbed_app.json Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-{
- "config": {
- "main-stack-size": {
- "value": 8192
- }
- },
- "macros": [
- "MBEDTLS_MPI_MAX_SIZE=1024",
- "MBEDTLS_MPI_WINDOW_SIZE=1",
- "MBEDTLS_USER_CONFIG_FILE=\"mbedtls_entropy_config.h\"",
- "MBEDTLS_TEST_NULL_ENTROPY",
- "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
- "MBED_HEAP_STATS_ENABLED=1"
- ],
- "target_overrides": {
- "*": {
- "platform.stdio-baud-rate": 115200,
- "platform.stdio-convert-newlines": true,
- "mbed-mesh-api.6lowpan-nd-channel-page": 0,
- "mbed-mesh-api.6lowpan-nd-channel": 12,
- "mbed-trace.enable": null,
- "mbed-http.http-buffer-size": 2048,
- "nsapi.default-wifi-security": "WPA_WPA2",
- "nsapi.default-wifi-ssid": "\"SSID\"",
- "nsapi.default-wifi-password": "\"Password\""
- },
- "DISCO_L475VG_IOT01A": {
- "target.network-default-interface-type" : "WIFI"
- }
- }
-}
--- a/mbedtls_entropy_config.h Fri Jan 04 13:32:26 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) - */ - -#include "select-demo.h" - -/* Enable entropy for devices with TRNG. This means entropy is disabled for all other targets. */ -/* Do **NOT** deploy this code in production on other targets! */ -/* See https://tls.mbed.org/kb/how-to/add-entropy-sources-to-entropy-pool */ -#if defined(DEVICE_TRNG) -#undef MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES -#undef MBEDTLS_TEST_NULL_ENTROPY -#endif
--- a/simconfig.json Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-{
- "ignore": [
- "./mbed-http"
- ]
-}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/CONSTANTS.h Thu Aug 01 03:43:28 2019 +0000 @@ -0,0 +1,9 @@ +#ifndef CONSTANTS_H +#define CONSTANTS_H + +#define BAUD_RATE 115200 +#define GRAVITY_CONSTANT 9.81 +#define SAMPLE_RATE_MEASURE 0.016 + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/FUNCTIONS.h Thu Aug 01 03:43:28 2019 +0000 @@ -0,0 +1,11 @@ +#ifndef FUNCTIONS_H +#define FUNCTIONS_H + +void print_debug(); +string compute_intensity(float xPGA, float yPGA); +void measure(); +void send_meassure(); +void getGPSCoordinates(); + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/REF_VALUES.h Thu Aug 01 03:43:28 2019 +0000
@@ -0,0 +1,34 @@
+#ifndef REF_VALUES_H
+#define REF_VALUES_H
+
+#include <string>
+
+struct corelation {
+ string scale;
+ float lowBound;
+ float highBound;
+ string perception;
+ string damage;
+} ;
+
+corelation notAppreciable = {"I", 0.0000, 0.0017, "Not Appreciable", "None"};
+corelation verySlight = {"II-III", 0.0017, 0.0140, "Very Slight", "None"};
+corelation slight = {"IV", 0.0140, 0.0390, "Slight", "None"};
+corelation moderate = {"V", 0.0390, 0.0920, "Moderate", "Very Slight"};
+corelation strong = {"VI", 0.0920, 0.1800, "Strong", "Slight"};
+corelation veryStrong = {"VII", 0.1800, 0.3400, "Very Strong", "Moderate"};
+corelation severe = {"VIII", 0.3400, 0.6500, "Severe", "Moderate to Strong"};
+corelation violent = {"IX", 0.6500, 1.2400, "Violent", "Strong"};
+corelation extreme = {"X+", 1.2400, 20.0000, "Extreme", "Very Strong"};
+
+typedef struct {
+ float x;
+ float y;
+}acceleration ;
+
+
+
+
+
+
+#endif
\ No newline at end of file
--- a/source/main-http-ipv6.cpp Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-#include "select-demo.h"
-
-#if DEMO == DEMO_HTTP_IPV6
-
-#include "mbed.h"
-#include "network-helper.h"
-#include "http_request.h"
-
-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());
-}
-
-int main() {
- NetworkInterface* network = connect_to_default_network_interface();
- if (!network) {
- printf("Cannot connect to the network, see serial output\n");
- return 1;
- }
-
- // Do a GET request to icanhazip.com which returns the public IPv6 address for the device
- // This page is only accessible over IPv6
- {
- // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
- // To receive chunked response, pass in a callback as last parameter to the constructor.
- HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "http://ipv6.icanhazip.com");
-
- HttpResponse* get_res = get_req->send();
- if (!get_res) {
- printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTP GET response -----\n");
- dump_response(get_res);
-
- delete get_req;
- }
-
- wait(osWaitForever);
-}
-
-#endif
--- a/source/main-http-socket-reuse.cpp Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-#include "select-demo.h"
-
-#if DEMO == DEMO_HTTP_SOCKET_REUSE
-
-#include "mbed.h"
-#include "network-helper.h"
-#include "http_request.h"
-
-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());
-}
-
-int main() {
- NetworkInterface* network = connect_to_default_network_interface();
- if (!network) {
- printf("Cannot connect to the network, see serial output\n");
- return 1;
- }
-
- // 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 1;
- }
-
- nsapi_error_t connect_result = socket->connect("httpbin.org", 80);
- if (connect_result != 0) {
- printf("Connecting over TCPSocket failed... %d\n", connect_result);
- return 1;
- }
-
- printf("Connected over TCP to httpbin.org:80\n");
-
- // Do a GET request to httpbin.org
- {
- HttpRequest* get_req = new HttpRequest(socket, HTTP_GET, "http://httpbin.org/status/418");
-
- // By default the body is automatically parsed and stored in a string, this is memory heavy.
- // To receive chunked response, pass in a callback as third parameter to 'send'.
- HttpResponse* get_res = get_req->send();
- if (!get_res) {
- printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTP GET response -----\n");
- dump_response(get_res);
-
- delete get_req;
- }
-
- // POST request to httpbin.org
- {
- HttpRequest* post_req = new HttpRequest(socket, HTTP_POST, "http://httpbin.org/post");
- post_req->set_header("Content-Type", "application/json");
-
- const char body[] = "{\"hello\":\"world\"}";
-
- HttpResponse* post_res = post_req->send(body, strlen(body));
- if (!post_res) {
- printf("HttpRequest failed (error code %d)\n", post_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTP POST response -----\n");
- dump_response(post_res);
-
- delete post_req;
- }
-
- socket->close();
- delete socket;
-
- wait(osWaitForever);
-}
-
-#endif
--- a/source/main-http.cpp Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-#include "select-demo.h"
-
-#if DEMO == DEMO_HTTP
-
-#include "mbed.h"
-#include "http_request.h"
-#include "network-helper.h"
-#include "mbed_mem_trace.h"
-
-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());
-}
-
-int main() {
- // Connect to the network with the default networking interface
- // if you use WiFi: see mbed_app.json for the credentials
- NetworkInterface* network = connect_to_default_network_interface();
- if (!network) {
- printf("Cannot connect to the network, see serial output\n");
- return 1;
- }
-
- // Do a GET request to httpbin.org
- {
- // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
- // To receive chunked response, pass in a callback as last parameter to the constructor.
- HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "http://httpbin.org/status/418");
-
- HttpResponse* get_res = get_req->send();
- if (!get_res) {
- printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTP GET response -----\n");
- dump_response(get_res);
-
- delete get_req;
- }
-
- // POST request to httpbin.org
- {
- HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
- post_req->set_header("Content-Type", "application/json");
-
- const char body[] = "{\"hello\":\"world\"}";
-
- HttpResponse* post_res = post_req->send(body, strlen(body));
- if (!post_res) {
- printf("HttpRequest failed (error code %d)\n", post_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTP POST response -----\n");
- dump_response(post_res);
-
- delete post_req;
- }
-
- wait(osWaitForever);
-}
-
-#endif
--- a/source/main-https-chunked-request.cpp Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-/**
- * This is an example of doing chunked requests, where you do not need to load the full request body
- * into memory. You do this by adding a callback to the `send` function of the HTTP/HTTPS request.
- */
-
-#include "select-demo.h"
-
-#if DEMO == DEMO_HTTPS_CHUNKED_REQUEST
-
-#include "mbed.h"
-#include "mbed_trace.h"
-#include "https_request.h"
-#include "network-helper.h"
-
-/* List of trusted root CA certificates
- * currently one: Comodo, the CA for reqres.in
- *
- * To add more root certificates, just concatenate them.
- */
-const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
- "MIICiTCCAg+gAwIBAgIQH0evqmIAcFBUTAGem2OZKjAKBggqhkjOPQQDAzCBhTEL\n"
- "MAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE\n"
- "BxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMT\n"
- "IkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDgwMzA2MDAw\n"
- "MDAwWhcNMzgwMTE4MjM1OTU5WjCBhTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdy\n"
- "ZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09N\n"
- "T0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlv\n"
- "biBBdXRob3JpdHkwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQDR3svdcmCFYX7deSR\n"
- "FtSrYpn1PlILBs5BAH+X4QokPB0BBO490o0JlwzgdeT6+3eKKvUDYEs2ixYjFq0J\n"
- "cfRK9ChQtP6IHG4/bC8vCVlbpVsLM5niwz2J+Wos77LTBumjQjBAMB0GA1UdDgQW\n"
- "BBR1cacZSBm8nZ3qQUfflMRId5nTeTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/\n"
- "BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjEA7wNbeqy3eApyt4jf/7VGFAkK+qDm\n"
- "fQjGGoe9GKhzvSbKYAydzpmfz1wPMOG+FDHqAjAU9JM8SaczepBGR7NjfRObTrdv\n"
- "GDeAU/7dIOA1mjbRxwG55tzd8/8dLDoWV9mSOdY=\n"
- "-----END CERTIFICATE-----\n";
-
-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 (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
-}
-
-// Spread the message out over 3 different chunks
-const char * chunks[] = {
- "{\"message\":",
- "\"this is an example",
- " of chunked encoding\"}"
-};
-
-int chunk_ix = 0;
-
-// Callback function, grab the next chunk and return it
-const void * get_chunk(uint32_t* out_size) {
- // If you don't have any data left, set out_size to 0 and return a null pointer
- if (chunk_ix == (sizeof(chunks) / sizeof(chunks[0]))) {
- *out_size = 0;
- return NULL;
- }
- const char *chunk = chunks[chunk_ix];
- *out_size = strlen(chunk);
- chunk_ix++;
-
- return chunk;
-}
-
-int main() {
- NetworkInterface* network = connect_to_default_network_interface();
- if (!network) {
- printf("Cannot connect to the network, see serial output\n");
- return 1;
- }
-
- mbed_trace_init();
-
- // This example also logs the raw request, you can do this by calling 'set_request_log_buffer' on the request
- uint8_t *request_buffer = (uint8_t*)calloc(2048, 1);
-
- // POST request to reqres.in
- {
- HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://reqres.in/api/users");
- post_req->set_header("Content-Type", "application/json");
- post_req->set_request_log_buffer(request_buffer, 2048);
-
- // If you pass a callback here, the Transfer-Encoding header is automatically set to chunked
- HttpResponse* post_res = post_req->send(&get_chunk);
- if (!post_res) {
- printf("HttpsRequest failed (error code %d)\n", post_req->get_error());
- return 1;
- }
-
- // Log the raw request that went over the line (if you decode the hex you can see the chunked parts)
- // e.g. in Node.js (take the output from below):
- // '50 4f 53 54 20'.split(' ').map(c=>parseInt(c,16)).map(c=>String.fromCharCode(c)).join('')
- printf("\n----- Request buffer -----\n");
- for (size_t ix = 0; ix < post_req->get_request_log_buffer_length(); ix++) {
- printf("%02x ", request_buffer[ix]);
- }
- printf("\n");
-
- printf("\n----- HTTPS POST response -----\n");
- dump_response(post_res);
-
- delete post_req;
- }
-
- wait(osWaitForever);
-}
-
-#endif
--- a/source/main-https-socket-reuse.cpp Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-#include "select-demo.h"
-
-/**
- * This demo shows how to re-use sockets, so the TLS handshake only has to happen once
- */
-
-#if DEMO == DEMO_HTTPS_SOCKET_REUSE
-
-#include "mbed.h"
-#include "mbed_trace.h"
-#include "https_request.h"
-#include "network-helper.h"
-
-/* List of trusted root CA certificates
- * currently one: Let's Encrypt, the CA for httpbin.org
- *
- * To add more root certificates, just concatenate them.
- */
-const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
- "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n"
- "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n"
- "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n"
- "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n"
- "GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n"
- "AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n"
- "q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n"
- "SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n"
- "Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n"
- "a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n"
- "/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n"
- "AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n"
- "CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n"
- "bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n"
- "c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n"
- "VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n"
- "ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n"
- "MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n"
- "Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n"
- "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n"
- "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n"
- "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n"
- "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
- "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
- "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
- "-----END CERTIFICATE-----\n";
-
-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());
-}
-
-int main() {
- NetworkInterface* network = connect_to_default_network_interface();
- if (!network) {
- printf("Cannot connect to the network, see serial output\n");
- return 1;
- }
-
- mbed_trace_init();
-
- // Create a TLS socket (which holds a TCPSocket)
- printf("\n----- Setting up TLS connection -----\n");
-
- nsapi_error_t r;
-
- TLSSocket* socket = new TLSSocket();
- if ((r = socket->open(network)) != NSAPI_ERROR_OK) {
- printf("TLS socket open failed (%d)\n", r);
- return 1;
- }
- if ((r = socket->set_root_ca_cert(SSL_CA_PEM)) != NSAPI_ERROR_OK) {
- printf("TLS socket set_root_ca_cert failed (%d)\n", r);
- return 1;
- }
- if ((r = socket->connect("httpbin.org", 443)) != NSAPI_ERROR_OK) {
- printf("TLS socket connect failed (%d)\n", r);
- return 1;
- }
-
- // GET request to httpbin.org
- {
- HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://httpbin.org/status/418");
-
- HttpResponse* get_res = get_req->send();
- if (!get_res) {
- printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- return 1;
- }
- printf("\n----- HTTPS GET response -----\n");
- dump_response(get_res);
-
- delete get_req;
- }
-
- // POST request to httpbin.org
- {
- HttpsRequest* post_req = new HttpsRequest(socket, HTTP_POST, "https://httpbin.org/post");
- post_req->set_header("Content-Type", "application/json");
-
- const char body[] = "{\"hello\":\"world\"}";
-
- HttpResponse* post_res = post_req->send(body, strlen(body));
- if (!post_res) {
- printf("HttpRequest failed (error code %d)\n", post_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTPS POST response -----\n");
- dump_response(post_res);
-
- delete post_req;
- }
-
- socket->close();
- delete socket;
-
- wait(osWaitForever);
-}
-
-#endif
--- a/source/main-https.cpp Fri Jan 04 13:32:26 2019 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-#define MBED_CONF_MBED_TRACE_ENABLE 1
-
-#include "select-demo.h"
-
-#if DEMO == DEMO_HTTPS
-
-#include "mbed.h"
-#include "mbed_trace.h"
-#include "https_request.h"
-#include "network-helper.h"
-
-/* List of trusted root CA certificates
- * currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
- *
- * To add more root certificates, just concatenate them.
- */
-const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
- "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n"
- "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n"
- "b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n"
- "MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n"
- "b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n"
- "ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n"
- "9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n"
- "IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n"
- "VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n"
- "93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n"
- "jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n"
- "AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n"
- "A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\n"
- "U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n"
- "N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\n"
- "o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n"
- "5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n"
- "rqXRfboQnoZsG4q5WTP468SQvvG5\n"
- "-----END CERTIFICATE-----\n"
- "-----BEGIN CERTIFICATE-----\n"
- "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n"
- "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n"
- "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n"
- "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n"
- "GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n"
- "AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n"
- "q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n"
- "SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n"
- "Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n"
- "a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n"
- "/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n"
- "AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n"
- "CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n"
- "bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n"
- "c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n"
- "VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n"
- "ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n"
- "MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n"
- "Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n"
- "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n"
- "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n"
- "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n"
- "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
- "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
- "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
- "-----END CERTIFICATE-----\n";
-
-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 (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
-}
-
-int main() {
- NetworkInterface* network = connect_to_default_network_interface();
- if (!network) {
- printf("Cannot connect to the network, see serial output\n");
- return 1;
- }
-
- mbed_trace_init();
-
- // GET request to os.mbed.com
- {
- printf("\n----- HTTPS GET request -----\n");
-
- HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://os.mbed.com/media/uploads/mbed_official/hello.txt");
-
- HttpResponse* get_res = get_req->send();
- if (!get_res) {
- printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- return 1;
- }
- printf("\n----- HTTPS GET response -----\n");
- dump_response(get_res);
-
- delete get_req;
- }
-
- // POST request to httpbin.org
- {
- printf("\n----- HTTPS POST request -----\n");
-
- HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://httpbin.org/post");
- post_req->set_header("Content-Type", "application/json");
-
- const char body[] = "{\"hello\":\"world\"}";
-
- HttpResponse* post_res = post_req->send(body, strlen(body));
- if (!post_res) {
- printf("HttpRequest failed (error code %d)\n", post_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTPS POST response -----\n");
- dump_response(post_res);
-
- delete post_req;
- }
-
- wait(osWaitForever);
-}
-
-#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/main.cpp Thu Aug 01 03:43:28 2019 +0000
@@ -0,0 +1,325 @@
+
+#include "mbed.h"
+#include "MPU6050.h"
+#include "REF_VALUES.h"
+#include "CONSTANTS.h"
+#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
+*/
+DigitalOut myled(LED1);
+
+/**
+* Puerto serial
+*/
+Serial pc(USBTX, USBRX, BAUD_RATE);
+
+/**
+* Puntero hacia el puerto serial utilizado para la comunicacion entre el GPS y el Micro
+*/
+Serial * gps_Serial;
+
+/**
+* Objeto MPU6050
+*/
+MPU6050 mpu(PF_15, PF_14);
+
+/**
+* Threads
+*/
+Thread sampleAccelero;
+Thread printDebug;
+Thread sendAccelero;
+Thread getCoordinates;
+
+/**
+* Mutex
+*/
+Mutex semaforo;
+Mutex globalVar;
+
+/**
+* Mailboxes
+*/
+Mail<acceleration, 1> mail_box;
+Mail<acceleration, 1> mail_meass;
+
+/**
+* Variables de control
+*/
+bool earthquakeHappening = false;
+bool beenHere = false;
+
+
+
+/**
+* Handler para la utilizacion del GPS
+*/
+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");
+ while(true){
+ wait(1);
+ osEvent evt = mail_meass.get();
+ if (evt.status == osEventMail) {
+ acceleration *mail = (acceleration*)evt.value.p;
+ if (mail->x == 0 && mail->y == 0){
+ mail_meass.free(mail);
+ 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);
+
+ // POST request to httpbin.org
+ 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\"}";
+
+ 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;
+
+ }
+ }
+}
+
+
+/**
+* Interpreta la acceleracion sismica del terremoto a una escala de la intensidad del mismo.
+*/
+string compute_intensity(float xPGA, float yPGA){
+ float maxPGA;
+
+ xPGA >= yPGA ? maxPGA = xPGA : maxPGA = yPGA;
+
+ string result;
+
+ if (maxPGA >= moderate.lowBound && maxPGA <= moderate.highBound)
+ result = "Earthquake detected! \t Mercalli Scale: " + moderate.scale + "\t" + moderate.damage + " Damage";
+
+ else if (maxPGA >= strong.lowBound && maxPGA <= strong.highBound)
+ result = "Earthquake detected! \t Mercalli Scale: " + strong.scale + "\t" + strong.damage + " Damage";
+
+ else if (maxPGA >= veryStrong.lowBound && maxPGA <= veryStrong.highBound)
+ result = "Earthquake detected! \t Mercalli Scale: " + veryStrong.scale + "\t" + veryStrong.damage + " Damage";
+
+ else if (maxPGA >= severe.lowBound && maxPGA <= severe.highBound)
+ result = "Earthquake detected! \t Mercalli Scale: " + severe.scale + "\t" + severe.damage + " Damage";
+
+ else if (maxPGA >= violent.lowBound && maxPGA <= violent.highBound)
+ result = "Earthquake detected! \t Mercalli Scale: " + violent.scale + "\t" + violent.damage + " Damage";
+
+ else if (maxPGA >= extreme.lowBound && maxPGA <= extreme.highBound)
+ result = "Earthquake detected! \t Mercalli Scale: " + extreme.scale + "\t" + extreme.damage + " Damage";
+
+ else
+ result = "No Intensity recognized";
+
+ return result;
+}
+
+
+/**
+* Mide la data entregada por el acelerometro
+*/
+void measure() {
+
+ // Ajusta la sensibilidad del sensor
+ mpu.setAcceleroRange(MPU6050_ACCELERO_RANGE_2G);
+
+ // Configura la frecuencia de corte del filtro paso bajo
+ mpu.setBW(MPU6050_BW_5);
+
+ // Test the connection
+ if (mpu.testConnection())
+ pc.printf("MPU6050 test passed \r\n");
+ else
+ pc.printf("MPU6050 test failed \r\n");
+
+ /**
+ * Array que almacena la data Raw para la acceleracion en X, Y, Z
+ */
+ float acce[3];
+ /**
+ * Aceleracion en X
+ */
+ float xAcc;
+ /**
+ * Aceleracion en Y
+ */
+ float yAcc;
+
+
+ while(1) {
+ // Adecua el muestreo para una frecuencia determinada
+ wait(SAMPLE_RATE_MEASURE);
+
+ // Procesa la data obtenida del sensor de las aceleraciones en X, Y, Z
+ mpu.getAccelero(acce);
+
+ // Aceleracion sismica en XY (g)
+ xAcc = (float)acce[0] / (GRAVITY_CONSTANT);
+ yAcc = (float)acce[1] / (GRAVITY_CONSTANT);
+
+ acceleration* mailAcc = mail_box.alloc();
+
+ mailAcc->x = abs(xAcc);
+ mailAcc->y = abs(yAcc);
+ mail_box.put(mailAcc);
+
+ // Revisa la ocurrencia de un sismo
+ if (abs(xAcc) >= moderate.lowBound || abs(yAcc) >= moderate.lowBound && !beenHere){
+ globalVar.lock();
+ earthquakeHappening = true;
+ beenHere = true;
+ globalVar.unlock();
+ }
+
+ }
+
+}
+
+void send_meassure(){
+ Timer tick;
+ bool meassuring = false;
+ acceleration *data;
+ acceleration maxData;
+ maxData.x = 0;
+ maxData.y = 0;
+ while (true){
+ wait_ms(200);
+ globalVar.lock();
+ if (earthquakeHappening)
+ meassuring = true;
+ globalVar.unlock();
+ while (meassuring){
+ wait_ms(50);
+ osEvent evt = mail_box.get();
+ if (evt.status == osEventMail) {
+ acceleration *mail = (acceleration*)evt.value.p;
+ data = mail;
+ mail_box.free(mail);
+ }
+ if (data->x >= moderate.lowBound || data->y >= moderate.lowBound ){
+ tick.reset();
+ if (data->x > maxData.x || data->y > maxData.y){
+ maxData = *data;
+ }
+ }
+ else {
+ tick.start();
+ if (tick.read_ms() <= 200)
+ continue;
+ tick.stop();
+ meassuring = false;
+ }
+ }
+ globalVar.lock();
+ beenHere = false;
+ earthquakeHappening = false;
+ globalVar.unlock();
+ acceleration* mailAcc = mail_meass.alloc();
+ mailAcc->x = maxData.x;
+ mailAcc->y = maxData.y;
+ mail_meass.put(mailAcc);
+ maxData.x = 0;
+ maxData.y = 0;
+ }
+}
+
+/**
+* Se encarga de obtener la cordenadas del Thread
+*/
+void getGPSCoordinates(){
+
+ char c; // when read via Adafruit_GPS::read(), the class returns single character stored here
+ Timer refresh_Timer; // sets up a timer for use in loop; how often do we print GPS info?
+ const int refresh_Time = 2000; //refresh time in ms
+
+ myGPS.begin(9600); // sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *)
+ // a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf
+
+ myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //these commands are defined in MBed_Adafruit_GPS.h; a link is provided there for command creation
+ myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
+ myGPS.sendCommand(PGCMD_ANTENNA);
+
+ refresh_Timer.start(); // starts the clock on the timer
+
+ while(true){
+ c = myGPS.read(); // queries the GPS
+
+ // check if we recieved a new message from GPS, if so, attempt to parse it,
+ if ( myGPS.newNMEAreceived() )
+ if ( !myGPS.parse(myGPS.lastNMEA()) )
+ continue;
+ }
+}
+
+
+int main()
+{
+ sampleAccelero.start(measure);
+ sendAccelero.start(send_meassure);
+ printDebug.start(print_debug);
+ getCoordinates.start(getGPSCoordinates);
+}
--- a/source/select-demo.h Fri Jan 04 13:32:26 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#ifndef _SELECT_METHOD_H_ -#define _SELECT_METHOD_H_ - -#define DEMO_HTTP 1 -#define DEMO_HTTP_SOCKET_REUSE 2 -#define DEMO_HTTP_IPV6 3 -#define DEMO_HTTPS 4 -#define DEMO_HTTPS_SOCKET_REUSE 5 -#define DEMO_HTTPS_CHUNKED_REQUEST 6 -#define DEMO_TESTS 7 - -#define DEMO DEMO_HTTP - -#endif // _SELECT_METHOD_H_
