Yonariel Hernandez / Mbed OS Proyecto-Final_copy_petey

Dependencies:   mbed-http

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main-http.cpp Source File

main-http.cpp

00001 #include "select-demo.h"
00002 #if DEMO == DEMO_HTTP
00003 #include "mbed.h"
00004 #include "http_request.h"
00005 #include "network-helper.h"
00006 #include "mbed_mem_trace.h"
00007 #include <iostream>
00008 #include <cstring>
00009 #include <Thread.h>
00010 #include <stdio.h>
00011 #include "EthernetInterface.h"
00012 
00013 
00014 
00015 //MAHER WAS HERE 
00016 
00017 DigitalOut PUERTA1(PG_9);
00018 DigitalOut PUERTA2(PG_14);
00019 DigitalOut PUERTA3(PF_15);
00020 DigitalOut PUERTA4(PE_13);
00021 
00022 Serial      sim808(PD_5, PD_6,9600);
00023 int         onetime = 0, i=0, j=0, onedbquery[4];
00024 const int   kMaxBufferSize = 100;
00025 char        buffer[kMaxBufferSize];
00026 string      opendoors = "http://192.168.1.10/ws/ws.php?op=micopendoors&telefono=";
00027 string      closedoors = "http://192.168.1.10/ws/ws.php?op=micclosedoors&telefono=";
00028 string      registers = "http://192.168.1.10/ws/ws.php?op=create-register&telefono=";
00029 char        linkdoors[40]= "http://192.168.1.10/ws/ws.php?op=doors";
00030 string      linkregister01 = "";
00031 string      linkregister02;
00032 string      linkregister03;
00033 string      linkregister04;
00034 char        char_linkregister01[55];
00035 char        char_linkregister02[55];
00036 char        char_linkregister03[55];
00037 char        char_linkregister04[55];
00038 char        linkopendoors[100];
00039 char        linkclosedoors[100];
00040 char        linkregisters[100];
00041 string      link_string;
00042 string      http_response = "";
00043 int         len = 0;
00044 char        telbuf[11];
00045 int         mensaje=0;
00046 Timer       t;
00047 
00048 void dump_response(HttpResponse* res) {
00049     http_response = res->get_body_as_string().c_str();
00050 }
00051 
00052 string petname = "señormajer"
00053 
00054 int main() {
00055     
00056 //-------------------------------------------------------------------- INICIALIZACION DE PINES -------------------------------------------------------------------------------------------
00057 
00058 
00059  // string  linkregister01 = "http://192.168.100.204/post.php?name=SOYMBED&submit=send";
00060 
00061 //-------------------------------------------------------------------- INICIALIZACION DE TARJETA DE RED -------------------------------------------------------------------------------------------
00062 
00063 
00064     NetworkInterface* network = connect_to_default_network_interface();
00065     if (!network) {
00066         printf("Cannot connect to the network, see serial output\n");
00067         return 1;
00068     }
00069     
00070     //-------------------------------------------------------------------- CREACION DE PET--------------------------------------------------------------------------------------------------
00071   // Do a GET request to httpbin.org
00072     {
00073         // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
00074         // To receive chunked response, pass in a callback as last parameter to the constructor.
00075         HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "http://192.168.100.204:8443/post.php?name=%petname%");
00076 
00077         HttpResponse* get_res = get_req->send();
00078         if (!get_res) {
00079             printf("HttpRequest failed (error code %d)\n", get_req->get_error());
00080             return 1;
00081         }
00082         dump_response(get_res);
00083         printf("\n----- HTTP GET response -----\n", get_res);
00084         
00085 
00086         delete get_req;
00087     }
00088 
00089     }
00090     #endif