Gateway con agregar controles mediante firebase
Dependencies: mbed mbed-http ESP01 Pulse RFDecoder
Diff: main.h
- Revision:
- 3:5dceee1c49fc
- Child:
- 4:8fed3705384e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Tue Jun 11 00:24:59 2019 +0000 @@ -0,0 +1,120 @@ +#ifndef MAIN_H +#define MAIN_H + +#include "mbed.h" +#include <string> +#include "ESP01.h" +#include "https_request.h" +#include "ESP8266Interface.h" +#include "RFDecoder.h" + +#define ON 0 +#define OFF 1 + +#define LEDAMARILLO_ON led_azul = OFF; led_verde = ON; led_rojo = ON; +#define LEDVERDE_ON led_azul = OFF; led_verde = ON; led_rojo = OFF; + +#define LEDS_OFF led_azul = OFF; led_verde = OFF; led_rojo = OFF; + +#define SERVER_PORT 5558 +#define MAX_NUM_OF_CONNECTIONS 2 +#define TCPCOMMSBYTESMAX 10 +#define TCPSTATSBYTESMAX 5 +#define MAXTIMERXCONTROL 30000 //Tiempo maximo para recibir el codigo del control de 433MHz en milisegundos + +//Codigos de Status de TCP +#define COMMANDREC 0x01 //Se recibio un comando valido por TCP + +//Comandos de TCP +#define NEW_CONTROL_REGISTER 0x10 +#define CONTROL_REGISTER_INFO 0x11 + +//Otros TCP +#define HEARBEAT_REQUEST 0xFA +#define HEARBEAT_RESPONSE 0xFB + + + +/* 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" + "MIIFmzCCBIOgAwIBAgIRAJRuZHok8dQjAQAAAAApJGwwDQYJKoZIhvcNAQELBQAw\n" + "QjELMAkGA1UEBhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczET\n" + "MBEGA1UEAxMKR1RTIENBIDFPMTAeFw0xOTAzMTMyMTMwNTdaFw0yMDAzMTEyMTMw\n" + "NTdaMGgxCzAJBgNVBAYTAl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QIGCisGAQQB\n" + "1nkCBAIEgfMEgfAA7gB1ALIeBcyLos2KIE6HZvkruYolIGdr2vpw57JJUy3vi5Be\n" + "AAABaXkuFzgAAAQDAEYwRAIgVssWhLEYItcpljMfJfkBhnxUrw32ik3C7IyBhkS6\n" + "jQcCIAHzoq/0QsRXY8RITJ5z6pThPzJhiSeLhWb6v2MDs6+NAHUAXqdz+d9WwOe1\n" + "Nkh90EngMnqRmgyEoRIShBh1loFxRVgAAAFpeS4XEQAABAMARjBEAiBgwY3jVuyU\n" + "HTDrfXt7Hhq3AL9kD8hASq/qIXFvHAel1AIgV2DY0UI7PvVl2uHicvaL9BfUPQjP\n" + "8/7b5W5jd6HEKbowDQYJKoZIhvcNAQELBQADggEBAAFG/f9zTyPTiYjjbPKpIC3T\n" + "MMD8dWvny1DJpL2fQPMcpAkkduW7sFG8mLRh14mSBsWqAusj99nAKt6NJhxZewhp\n" + "JKwbcawanW+w2DUzFr0FauVxNIs4xPxcgkCNAGeUj8ZI+cDcSaMOY4WxNrjOgbbI\n" + "feOxHsCmIWxch6/vNVxh+54BZFCy723DL8Fo/tDRU73b+gxPJusJva4ABuXSqSFT\n" + "EDaRGzdj8AKkoDmRkWLcEg/6a/2dfw8VV7fIAlqVxNQwZWZLtIsBGazxZ5xflrVz\n" + "I5AHejNR7guDaWAimhkSOlG11W8BzPtdAo/xJ6JyI4K5kPGIXucniVRmQfmojxc=\n" + "-----END CERTIFICATE-----\n" + "-----BEGIN CERTIFICATE-----\n" + "MIIESjCCAzKgAwIBAgINAeO0mqGNiqmBJWlQuDANBgkqhkiG9w0BAQsFADBMMSAw\n" + "HgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMKR2xvYmFs\n" + "U2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xNzA2MTUwMDAwNDJaFw0yMTEy\n" + "MTUwMDAwNDJaMEIxCzAJBgNVBAYTAlVTMR4wHAYDVQQKExVHb29nbGUg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9tvBCOIazpswWC9aJ9xju4tWDQH8NVU6YZZ/XteDSGU9YzJqPjY8q3MDxrz\n" + "mqepBCf5o8mw/wJ4a2G6xzUr6Fb6T8McDO22PLRL6u3M4Tzs3A2M1j6bykJYi8wW\n" + "IRdAvKLWZu/axBVbzYmqmwkm5zLSDW5nIAJbELCQCZwMH56t2Dvqofxs6BBcCFIZ\n" + "USpxu6x6td0V7SvJCCosirSmIatj/9dSSVDQibet8q/7UK4v4ZUN80atnZz1yg==\n" + "-----END CERTIFICATE-----\n"; + +//Port Definition +DigitalOut led_rojo(LED_RED); +DigitalOut led_verde(LED_GREEN); +DigitalOut led_azul(LED_BLUE); + +//Function Prototypes +void wifiInit(void); +bool isConnectedToWifi(void); +void wifiConnect(void); +void startServer(int port); +int getTCPContent(char *espdata, char *command, char *status); +void convertToCharArray(char *arr, unsigned long number); + +void dump_response(HttpResponse* res); +void http_demo(NetworkInterface *net); + + + +#endif //MAIN_H \ No newline at end of file