Gateway con agregar controles mediante firebase

Dependencies:   mbed mbed-http ESP01 Pulse RFDecoder

Committer:
Thrillex13
Date:
Sat May 25 04:59:06 2019 +0000
Revision:
1:cf6a75de25ce
Parent:
0:f4f503a32dca
Child:
2:bc3973471585
- Se realizo exitosamente la peticiones GET y POST a la base de datos de Firebase.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thrillex13 0:f4f503a32dca 1 #include "mbed.h"
Thrillex13 0:f4f503a32dca 2 #include <string>
Thrillex13 1:cf6a75de25ce 3 #include "ESP01.h"
Thrillex13 1:cf6a75de25ce 4 #include "https_request.h"
Thrillex13 1:cf6a75de25ce 5 #include "mbed_trace.h"
Thrillex13 1:cf6a75de25ce 6 //#include "network-helper.h"
Thrillex13 1:cf6a75de25ce 7 #include "TCPSocket.h"
Thrillex13 1:cf6a75de25ce 8 #include "ESP8266Interface.h"
Thrillex13 0:f4f503a32dca 9
Thrillex13 0:f4f503a32dca 10 // Objects
Thrillex13 0:f4f503a32dca 11 Serial pc(USBTX, USBRX);
Thrillex13 1:cf6a75de25ce 12 ESP01 wifi(PTC17, PTC16, 115200); //Con este objeto implementamos los metodos que requieren comandos AT del modulo de WIFI
Thrillex13 1:cf6a75de25ce 13 //ESP8266Interface net(PTC17, PTC16); //Con este objeto implementamos todas las funciones de red para la creacion de Sockets
Thrillex13 0:f4f503a32dca 14
Thrillex13 0:f4f503a32dca 15 DigitalOut led_rojo(LED_RED);
Thrillex13 0:f4f503a32dca 16 DigitalOut led_verde(LED_GREEN);
Thrillex13 0:f4f503a32dca 17 DigitalOut led_azul(LED_BLUE);
Thrillex13 0:f4f503a32dca 18
Thrillex13 0:f4f503a32dca 19 #define ON 0;
Thrillex13 0:f4f503a32dca 20 #define OFF 1;
Thrillex13 0:f4f503a32dca 21
Thrillex13 0:f4f503a32dca 22 // Global variables
Thrillex13 0:f4f503a32dca 23 char snd[255], rcv[1000]; // Strings for sending and receiving commands / data / replies
Thrillex13 0:f4f503a32dca 24
Thrillex13 0:f4f503a32dca 25 void wifiInit(void);
Thrillex13 0:f4f503a32dca 26 bool isConnectedToWifi(void);
Thrillex13 0:f4f503a32dca 27 void wifiConnect(void);
Thrillex13 1:cf6a75de25ce 28
Thrillex13 1:cf6a75de25ce 29 void http_demo(NetworkInterface *net);
Thrillex13 1:cf6a75de25ce 30
Thrillex13 1:cf6a75de25ce 31
Thrillex13 1:cf6a75de25ce 32 /* List of trusted root CA certificates
Thrillex13 1:cf6a75de25ce 33 * currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
Thrillex13 1:cf6a75de25ce 34 *
Thrillex13 1:cf6a75de25ce 35 * To add more root certificates, just concatenate them.
Thrillex13 1:cf6a75de25ce 36 */
Thrillex13 1:cf6a75de25ce 37 const char SSL_CA_PEM[] =
Thrillex13 1:cf6a75de25ce 38 "-----BEGIN CERTIFICATE-----\n"
Thrillex13 1:cf6a75de25ce 39 "MIIFmzCCBIOgAwIBAgIRAJRuZHok8dQjAQAAAAApJGwwDQYJKoZIhvcNAQELBQAw\n"
Thrillex13 1:cf6a75de25ce 40 "QjELMAkGA1UEBhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczET\n"
Thrillex13 1:cf6a75de25ce 41 "MBEGA1UEAxMKR1RTIENBIDFPMTAeFw0xOTAzMTMyMTMwNTdaFw0yMDAzMTEyMTMw\n"
Thrillex13 1:cf6a75de25ce 42 "NTdaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH\n"
Thrillex13 1:cf6a75de25ce 43 "Ew1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgTExDMRcwFQYDVQQDEw5m\n"
Thrillex13 1:cf6a75de25ce 44 "aXJlYmFzZWlvLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALkd\n"
Thrillex13 1:cf6a75de25ce 45 "/jeM+PrwIYmM6IE28iN7CjKnBWy+tqNrs5z2AJwM5iLgtgcbc+THuXGElTN7zAWB\n"
Thrillex13 1:cf6a75de25ce 46 "SKWv+ezAGe5NiTEEUiWgX1z1VFDj85xpz+Cysn/Oi8MtoN6h8yCmYPtXv8YPInw0\n"
Thrillex13 1:cf6a75de25ce 47 "JLkSM5e2uuWVwc/tR1Fh+awpiYQFqGm6DvMq6yAYB/nuL3Gyc4XFgRrxje+VQ+g3\n"
Thrillex13 1:cf6a75de25ce 48 "oWE+9NVfqu4smFCutSIGlEdRhGdr/m2u+sc+dnBZNoVOqwSyyFyjpAZvMMvuE5Ip\n"
Thrillex13 1:cf6a75de25ce 49 "3ovfA1tq57nl9eQw8fcKsdXOeeXYHc1KBUUC7Xb8F/1+upVML8a5GMULpYkClLXt\n"
Thrillex13 1:cf6a75de25ce 50 "OKRRfCJa53YynILJdPkCAwEAAaOCAmQwggJgMA4GA1UdDwEB/wQEAwIFoDATBgNV\n"
Thrillex13 1:cf6a75de25ce 51 "HSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBS03YhV70g6\n"
Thrillex13 1:cf6a75de25ce 52 "+7MUxtOiluRi1T2GAzAfBgNVHSMEGDAWgBSY0fhuEOvPm+xgnxiQG6DrfQn9KzBk\n"
Thrillex13 1:cf6a75de25ce 53 "BggrBgEFBQcBAQRYMFYwJwYIKwYBBQUHMAGGG2h0dHA6Ly9vY3NwLnBraS5nb29n\n"
Thrillex13 1:cf6a75de25ce 54 "L2d0czFvMTArBggrBgEFBQcwAoYfaHR0cDovL3BraS5nb29nL2dzcjIvR1RTMU8x\n"
Thrillex13 1:cf6a75de25ce 55 "LmNydDArBgNVHREEJDAigg5maXJlYmFzZWlvLmNvbYIQKi5maXJlYmFzZWlvLmNv\n"
Thrillex13 1:cf6a75de25ce 56 "bTAhBgNVHSAEGjAYMAgGBmeBDAECAjAMBgorBgEEAdZ5AgUDMC8GA1UdHwQoMCYw\n"
Thrillex13 1:cf6a75de25ce 57 "JKAioCCGHmh0dHA6Ly9jcmwucGtpLmdvb2cvR1RTMU8xLmNybDCCAQIGCisGAQQB\n"
Thrillex13 1:cf6a75de25ce 58 "1nkCBAIEgfMEgfAA7gB1ALIeBcyLos2KIE6HZvkruYolIGdr2vpw57JJUy3vi5Be\n"
Thrillex13 1:cf6a75de25ce 59 "AAABaXkuFzgAAAQDAEYwRAIgVssWhLEYItcpljMfJfkBhnxUrw32ik3C7IyBhkS6\n"
Thrillex13 1:cf6a75de25ce 60 "jQcCIAHzoq/0QsRXY8RITJ5z6pThPzJhiSeLhWb6v2MDs6+NAHUAXqdz+d9WwOe1\n"
Thrillex13 1:cf6a75de25ce 61 "Nkh90EngMnqRmgyEoRIShBh1loFxRVgAAAFpeS4XEQAABAMARjBEAiBgwY3jVuyU\n"
Thrillex13 1:cf6a75de25ce 62 "HTDrfXt7Hhq3AL9kD8hASq/qIXFvHAel1AIgV2DY0UI7PvVl2uHicvaL9BfUPQjP\n"
Thrillex13 1:cf6a75de25ce 63 "8/7b5W5jd6HEKbowDQYJKoZIhvcNAQELBQADggEBAAFG/f9zTyPTiYjjbPKpIC3T\n"
Thrillex13 1:cf6a75de25ce 64 "MMD8dWvny1DJpL2fQPMcpAkkduW7sFG8mLRh14mSBsWqAusj99nAKt6NJhxZewhp\n"
Thrillex13 1:cf6a75de25ce 65 "JKwbcawanW+w2DUzFr0FauVxNIs4xPxcgkCNAGeUj8ZI+cDcSaMOY4WxNrjOgbbI\n"
Thrillex13 1:cf6a75de25ce 66 "feOxHsCmIWxch6/vNVxh+54BZFCy723DL8Fo/tDRU73b+gxPJusJva4ABuXSqSFT\n"
Thrillex13 1:cf6a75de25ce 67 "EDaRGzdj8AKkoDmRkWLcEg/6a/2dfw8VV7fIAlqVxNQwZWZLtIsBGazxZ5xflrVz\n"
Thrillex13 1:cf6a75de25ce 68 "I5AHejNR7guDaWAimhkSOlG11W8BzPtdAo/xJ6JyI4K5kPGIXucniVRmQfmojxc=\n"
Thrillex13 1:cf6a75de25ce 69 "-----END CERTIFICATE-----\n"
Thrillex13 1:cf6a75de25ce 70 "-----BEGIN CERTIFICATE-----\n"
Thrillex13 1:cf6a75de25ce 71 "MIIESjCCAzKgAwIBAgINAeO0mqGNiqmBJWlQuDANBgkqhkiG9w0BAQsFADBMMSAw\n"
Thrillex13 1:cf6a75de25ce 72 "HgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMKR2xvYmFs\n"
Thrillex13 1:cf6a75de25ce 73 "U2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xNzA2MTUwMDAwNDJaFw0yMTEy\n"
Thrillex13 1:cf6a75de25ce 74 "MTUwMDAwNDJaMEIxCzAJBgNVBAYTAlVTMR4wHAYDVQQKExVHb29nbGUgVHJ1c3Qg\n"
Thrillex13 1:cf6a75de25ce 75 "U2VydmljZXMxEzARBgNVBAMTCkdUUyBDQSAxTzEwggEiMA0GCSqGSIb3DQEBAQUA\n"
Thrillex13 1:cf6a75de25ce 76 "A4IBDwAwggEKAoIBAQDQGM9F1IvN05zkQO9+tN1pIRvJzzyOTHW5DzEZhD2ePCnv\n"
Thrillex13 1:cf6a75de25ce 77 "UA0Qk28FgICfKqC9EksC4T2fWBYk/jCfC3R3VZMdS/dN4ZKCEPZRrAzDsiKUDzRr\n"
Thrillex13 1:cf6a75de25ce 78 "mBBJ5wudgzndIMYcLe/RGGFl5yODIKgjEv/SJH/UL+dEaltN11BmsK+eQmMF++Ac\n"
Thrillex13 1:cf6a75de25ce 79 "xGNhr59qM/9il71I2dN8FGfcddwuaej4bXhp0LcQBbjxMcI7JP0aM3T4I+DsaxmK\n"
Thrillex13 1:cf6a75de25ce 80 "FsbjzaTNC9uzpFlgOIg7rR25xoynUxv8vNmkq7zdPGHXkxWY7oG9j+JkRyBABk7X\n"
Thrillex13 1:cf6a75de25ce 81 "rJfoucBZEqFJJSPk7XA0LKW0Y3z5oz2D0c1tJKwHAgMBAAGjggEzMIIBLzAOBgNV\n"
Thrillex13 1:cf6a75de25ce 82 "HQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1Ud\n"
Thrillex13 1:cf6a75de25ce 83 "EwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFJjR+G4Q68+b7GCfGJAboOt9Cf0rMB8G\n"
Thrillex13 1:cf6a75de25ce 84 "A1UdIwQYMBaAFJviB1dnHB7AagbeWbSaLd/cGYYuMDUGCCsGAQUFBwEBBCkwJzAl\n"
Thrillex13 1:cf6a75de25ce 85 "BggrBgEFBQcwAYYZaHR0cDovL29jc3AucGtpLmdvb2cvZ3NyMjAyBgNVHR8EKzAp\n"
Thrillex13 1:cf6a75de25ce 86 "MCegJaAjhiFodHRwOi8vY3JsLnBraS5nb29nL2dzcjIvZ3NyMi5jcmwwPwYDVR0g\n"
Thrillex13 1:cf6a75de25ce 87 "BDgwNjA0BgZngQwBAgIwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly9wa2kuZ29vZy9y\n"
Thrillex13 1:cf6a75de25ce 88 "ZXBvc2l0b3J5LzANBgkqhkiG9w0BAQsFAAOCAQEAGoA+Nnn78y6pRjd9XlQWNa7H\n"
Thrillex13 1:cf6a75de25ce 89 "TgiZ/r3RNGkmUmYHPQq6Scti9PEajvwRT2iWTHQr02fesqOqBY2ETUwgZQ+lltoN\n"
Thrillex13 1:cf6a75de25ce 90 "FvhsO9tvBCOIazpswWC9aJ9xju4tWDQH8NVU6YZZ/XteDSGU9YzJqPjY8q3MDxrz\n"
Thrillex13 1:cf6a75de25ce 91 "mqepBCf5o8mw/wJ4a2G6xzUr6Fb6T8McDO22PLRL6u3M4Tzs3A2M1j6bykJYi8wW\n"
Thrillex13 1:cf6a75de25ce 92 "IRdAvKLWZu/axBVbzYmqmwkm5zLSDW5nIAJbELCQCZwMH56t2Dvqofxs6BBcCFIZ\n"
Thrillex13 1:cf6a75de25ce 93 "USpxu6x6td0V7SvJCCosirSmIatj/9dSSVDQibet8q/7UK4v4ZUN80atnZz1yg==\n"
Thrillex13 1:cf6a75de25ce 94 "-----END CERTIFICATE-----\n";
Thrillex13 1:cf6a75de25ce 95
Thrillex13 1:cf6a75de25ce 96
Thrillex13 1:cf6a75de25ce 97 void dump_response(HttpResponse* res) {
Thrillex13 1:cf6a75de25ce 98 printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
Thrillex13 1:cf6a75de25ce 99
Thrillex13 1:cf6a75de25ce 100 printf("Headers:\n");
Thrillex13 1:cf6a75de25ce 101 for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
Thrillex13 1:cf6a75de25ce 102 printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
Thrillex13 1:cf6a75de25ce 103 }
Thrillex13 1:cf6a75de25ce 104 printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
Thrillex13 1:cf6a75de25ce 105 }
Thrillex13 0:f4f503a32dca 106
Thrillex13 0:f4f503a32dca 107 int main() {
Thrillex13 0:f4f503a32dca 108 led_azul = OFF;
Thrillex13 0:f4f503a32dca 109 led_rojo = OFF;
Thrillex13 0:f4f503a32dca 110 led_verde = OFF;
Thrillex13 0:f4f503a32dca 111
Thrillex13 0:f4f503a32dca 112 pc.baud(115200);
Thrillex13 0:f4f503a32dca 113 wifi.Quit();
Thrillex13 0:f4f503a32dca 114 wifiInit();
Thrillex13 0:f4f503a32dca 115 wifiConnect();
Thrillex13 0:f4f503a32dca 116
Thrillex13 1:cf6a75de25ce 117 //NextToDo: Crear un servidor y a la vez hacer get y post
Thrillex13 1:cf6a75de25ce 118
Thrillex13 1:cf6a75de25ce 119 ESP8266Interface net(PTC17, PTC16); //Con este objeto implementamos todas las funciones de red para la creacion de Sockets
Thrillex13 1:cf6a75de25ce 120 http_demo(&net);
Thrillex13 1:cf6a75de25ce 121
Thrillex13 0:f4f503a32dca 122
Thrillex13 0:f4f503a32dca 123
Thrillex13 0:f4f503a32dca 124 while(1);
Thrillex13 0:f4f503a32dca 125 }
Thrillex13 0:f4f503a32dca 126
Thrillex13 0:f4f503a32dca 127 void wifiInit(void){
Thrillex13 0:f4f503a32dca 128 pc.printf("Gateway Sistema de Control de Cotos\r\n");
Thrillex13 0:f4f503a32dca 129 pc.printf("Resetting WiFi\r\n");
Thrillex13 0:f4f503a32dca 130 wifi.Reset();
Thrillex13 0:f4f503a32dca 131 wait(2);
Thrillex13 0:f4f503a32dca 132 wifi.DisableEcho();
Thrillex13 1:cf6a75de25ce 133 pc.printf("Set mode to Station+AP\r\n");
Thrillex13 1:cf6a75de25ce 134 wifi.SetMode(3);
Thrillex13 0:f4f503a32dca 135 wifi.RcvReply(rcv, 1000);
Thrillex13 0:f4f503a32dca 136 pc.printf("%s", rcv);
Thrillex13 0:f4f503a32dca 137 wait(2);
Thrillex13 1:cf6a75de25ce 138 pc.printf("Configure for multiple sockets\r\n");
Thrillex13 1:cf6a75de25ce 139 wifi.SetMultiple();
Thrillex13 1:cf6a75de25ce 140 wifi.RcvReply(rcv, 1000);
Thrillex13 1:cf6a75de25ce 141 pc.printf("%s", rcv);
Thrillex13 1:cf6a75de25ce 142 wait(2);
Thrillex13 1:cf6a75de25ce 143 pc.printf("Enable DHCP\r\n");
Thrillex13 1:cf6a75de25ce 144 wifi.EnableDHCP();
Thrillex13 1:cf6a75de25ce 145 wifi.RcvReply(rcv, 1000);
Thrillex13 1:cf6a75de25ce 146 pc.printf("%s", rcv);
Thrillex13 1:cf6a75de25ce 147 wait(2);
Thrillex13 0:f4f503a32dca 148 }
Thrillex13 0:f4f503a32dca 149
Thrillex13 0:f4f503a32dca 150 void wifiConnect(void){
Thrillex13 0:f4f503a32dca 151 Timer t;
Thrillex13 0:f4f503a32dca 152 if(isConnectedToWifi()){
Thrillex13 0:f4f503a32dca 153 pc.printf("Gateway is already connected to wifi with the following IP address\r\n");
Thrillex13 0:f4f503a32dca 154 wifi.GetIP(rcv);
Thrillex13 0:f4f503a32dca 155 pc.printf("%s", rcv);
Thrillex13 0:f4f503a32dca 156 led_azul = OFF;
Thrillex13 0:f4f503a32dca 157 led_verde = ON;
Thrillex13 0:f4f503a32dca 158 wait(2);
Thrillex13 0:f4f503a32dca 159 }else{
Thrillex13 0:f4f503a32dca 160 t.start();
Thrillex13 0:f4f503a32dca 161 pc.printf("Starting Smart Config\r\n");
Thrillex13 0:f4f503a32dca 162 led_azul = ON;
Thrillex13 0:f4f503a32dca 163 wifi.StartSmartConfig();
Thrillex13 1:cf6a75de25ce 164 wifi.RcvReply(rcv, 15000);
Thrillex13 0:f4f503a32dca 165 pc.printf("%s", rcv);
Thrillex13 0:f4f503a32dca 166 wait(5);
Thrillex13 0:f4f503a32dca 167 while(!isConnectedToWifi()){
Thrillex13 0:f4f503a32dca 168 if(t.read_ms() > 30000) {
Thrillex13 0:f4f503a32dca 169 led_azul = OFF;
Thrillex13 0:f4f503a32dca 170 led_rojo = ON;
Thrillex13 0:f4f503a32dca 171 pc.printf("No se pudo conectar al Wifi");
Thrillex13 0:f4f503a32dca 172 break;
Thrillex13 0:f4f503a32dca 173 }
Thrillex13 0:f4f503a32dca 174 }
Thrillex13 0:f4f503a32dca 175 }
Thrillex13 0:f4f503a32dca 176 }
Thrillex13 0:f4f503a32dca 177
Thrillex13 0:f4f503a32dca 178 bool isConnectedToWifi(void){
Thrillex13 0:f4f503a32dca 179 bool status;
Thrillex13 0:f4f503a32dca 180 wifi.GetConnStatus(rcv);
Thrillex13 0:f4f503a32dca 181 //pc.printf("%s", rcv);
Thrillex13 0:f4f503a32dca 182 if(strcmp(rcv,"STATUS:2\r")==0){
Thrillex13 0:f4f503a32dca 183 led_azul = OFF;
Thrillex13 0:f4f503a32dca 184 led_rojo = OFF;
Thrillex13 0:f4f503a32dca 185 led_verde = ON;
Thrillex13 0:f4f503a32dca 186 status=true;
Thrillex13 0:f4f503a32dca 187 }else{
Thrillex13 0:f4f503a32dca 188 status=false;
Thrillex13 0:f4f503a32dca 189 }
Thrillex13 0:f4f503a32dca 190 return status;
Thrillex13 0:f4f503a32dca 191
Thrillex13 1:cf6a75de25ce 192 }
Thrillex13 1:cf6a75de25ce 193
Thrillex13 1:cf6a75de25ce 194 void http_demo(NetworkInterface *network){
Thrillex13 1:cf6a75de25ce 195 TLSSocket* socket = new TLSSocket();
Thrillex13 1:cf6a75de25ce 196
Thrillex13 1:cf6a75de25ce 197 nsapi_error_t r;
Thrillex13 1:cf6a75de25ce 198 // make sure to check the return values for the calls below (should return NSAPI_ERROR_OK)
Thrillex13 1:cf6a75de25ce 199 r = socket->open(network);
Thrillex13 1:cf6a75de25ce 200 r = socket->set_root_ca_cert(SSL_CA_PEM);
Thrillex13 1:cf6a75de25ce 201 r = socket->connect("https://cotoceiba.firebaseio.com", 443);
Thrillex13 1:cf6a75de25ce 202
Thrillex13 1:cf6a75de25ce 203 printf("\n----- HTTPS GET request -----\n");
Thrillex13 1:cf6a75de25ce 204
Thrillex13 1:cf6a75de25ce 205 HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://cotoceiba.firebaseio.com/Condominos/94.json?auth=ZpXLLURU9KWmW5t1kzBYD2IuBE0V7wdv5vXwDgsH");
Thrillex13 1:cf6a75de25ce 206
Thrillex13 1:cf6a75de25ce 207 HttpResponse* get_res = get_req->send();
Thrillex13 1:cf6a75de25ce 208 if (!get_res) {
Thrillex13 1:cf6a75de25ce 209 printf("HttpRequest failed (error code %d)\n", get_req->get_error());
Thrillex13 1:cf6a75de25ce 210 //return 1;
Thrillex13 1:cf6a75de25ce 211 }
Thrillex13 1:cf6a75de25ce 212 printf("\n----- HTTPS GET response -----\n");
Thrillex13 1:cf6a75de25ce 213 dump_response(get_res);
Thrillex13 1:cf6a75de25ce 214 delete get_req;
Thrillex13 1:cf6a75de25ce 215
Thrillex13 1:cf6a75de25ce 216 printf("\n----- HTTPS POST request -----\n");
Thrillex13 1:cf6a75de25ce 217
Thrillex13 1:cf6a75de25ce 218 HttpsRequest* post_req = new HttpsRequest(socket, HTTP_POST, "https://cotoceiba.firebaseio.com/Condominos/52.json?auth=ZpXLLURU9KWmW5t1kzBYD2IuBE0V7wdv5vXwDgsH");
Thrillex13 1:cf6a75de25ce 219 post_req->set_header("Content-Type", "application/json");
Thrillex13 1:cf6a75de25ce 220
Thrillex13 1:cf6a75de25ce 221 const char body[] = "{\"nombre\":\"Posteado por Wifi Perros\",\"numcasa\":\"64\"}";
Thrillex13 1:cf6a75de25ce 222
Thrillex13 1:cf6a75de25ce 223 HttpResponse* post_res = post_req->send(body, strlen(body));
Thrillex13 1:cf6a75de25ce 224 if (!post_res) {
Thrillex13 1:cf6a75de25ce 225 printf("HttpRequest failed (error code %d)\n", post_req->get_error());
Thrillex13 1:cf6a75de25ce 226 //return 1;
Thrillex13 1:cf6a75de25ce 227 }
Thrillex13 1:cf6a75de25ce 228
Thrillex13 1:cf6a75de25ce 229 printf("\n----- HTTPS POST response -----\n");
Thrillex13 1:cf6a75de25ce 230 dump_response(post_res);
Thrillex13 1:cf6a75de25ce 231 delete post_req;
Thrillex13 0:f4f503a32dca 232 }