Gateway con agregar controles mediante firebase migracion a OS5
Dependencies: mbed-http ESP01 Pulse RFDecoder
main.h@3:5dceee1c49fc, 2019-06-11 (annotated)
- Committer:
- Thrillex13
- Date:
- Tue Jun 11 00:24:59 2019 +0000
- Revision:
- 3:5dceee1c49fc
- Child:
- 4:8fed3705384e
Se implemento y probo Registro de Controles y Heartbeat
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Thrillex13 | 3:5dceee1c49fc | 1 | #ifndef MAIN_H |
Thrillex13 | 3:5dceee1c49fc | 2 | #define MAIN_H |
Thrillex13 | 3:5dceee1c49fc | 3 | |
Thrillex13 | 3:5dceee1c49fc | 4 | #include "mbed.h" |
Thrillex13 | 3:5dceee1c49fc | 5 | #include <string> |
Thrillex13 | 3:5dceee1c49fc | 6 | #include "ESP01.h" |
Thrillex13 | 3:5dceee1c49fc | 7 | #include "https_request.h" |
Thrillex13 | 3:5dceee1c49fc | 8 | #include "ESP8266Interface.h" |
Thrillex13 | 3:5dceee1c49fc | 9 | #include "RFDecoder.h" |
Thrillex13 | 3:5dceee1c49fc | 10 | |
Thrillex13 | 3:5dceee1c49fc | 11 | #define ON 0 |
Thrillex13 | 3:5dceee1c49fc | 12 | #define OFF 1 |
Thrillex13 | 3:5dceee1c49fc | 13 | |
Thrillex13 | 3:5dceee1c49fc | 14 | #define LEDAMARILLO_ON led_azul = OFF; led_verde = ON; led_rojo = ON; |
Thrillex13 | 3:5dceee1c49fc | 15 | #define LEDVERDE_ON led_azul = OFF; led_verde = ON; led_rojo = OFF; |
Thrillex13 | 3:5dceee1c49fc | 16 | |
Thrillex13 | 3:5dceee1c49fc | 17 | #define LEDS_OFF led_azul = OFF; led_verde = OFF; led_rojo = OFF; |
Thrillex13 | 3:5dceee1c49fc | 18 | |
Thrillex13 | 3:5dceee1c49fc | 19 | #define SERVER_PORT 5558 |
Thrillex13 | 3:5dceee1c49fc | 20 | #define MAX_NUM_OF_CONNECTIONS 2 |
Thrillex13 | 3:5dceee1c49fc | 21 | #define TCPCOMMSBYTESMAX 10 |
Thrillex13 | 3:5dceee1c49fc | 22 | #define TCPSTATSBYTESMAX 5 |
Thrillex13 | 3:5dceee1c49fc | 23 | #define MAXTIMERXCONTROL 30000 //Tiempo maximo para recibir el codigo del control de 433MHz en milisegundos |
Thrillex13 | 3:5dceee1c49fc | 24 | |
Thrillex13 | 3:5dceee1c49fc | 25 | //Codigos de Status de TCP |
Thrillex13 | 3:5dceee1c49fc | 26 | #define COMMANDREC 0x01 //Se recibio un comando valido por TCP |
Thrillex13 | 3:5dceee1c49fc | 27 | |
Thrillex13 | 3:5dceee1c49fc | 28 | //Comandos de TCP |
Thrillex13 | 3:5dceee1c49fc | 29 | #define NEW_CONTROL_REGISTER 0x10 |
Thrillex13 | 3:5dceee1c49fc | 30 | #define CONTROL_REGISTER_INFO 0x11 |
Thrillex13 | 3:5dceee1c49fc | 31 | |
Thrillex13 | 3:5dceee1c49fc | 32 | //Otros TCP |
Thrillex13 | 3:5dceee1c49fc | 33 | #define HEARBEAT_REQUEST 0xFA |
Thrillex13 | 3:5dceee1c49fc | 34 | #define HEARBEAT_RESPONSE 0xFB |
Thrillex13 | 3:5dceee1c49fc | 35 | |
Thrillex13 | 3:5dceee1c49fc | 36 | |
Thrillex13 | 3:5dceee1c49fc | 37 | |
Thrillex13 | 3:5dceee1c49fc | 38 | /* List of trusted root CA certificates |
Thrillex13 | 3:5dceee1c49fc | 39 | * currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org |
Thrillex13 | 3:5dceee1c49fc | 40 | * |
Thrillex13 | 3:5dceee1c49fc | 41 | * To add more root certificates, just concatenate them. |
Thrillex13 | 3:5dceee1c49fc | 42 | */ |
Thrillex13 | 3:5dceee1c49fc | 43 | const char SSL_CA_PEM[] = |
Thrillex13 | 3:5dceee1c49fc | 44 | "-----BEGIN CERTIFICATE-----\n" |
Thrillex13 | 3:5dceee1c49fc | 45 | "MIIFmzCCBIOgAwIBAgIRAJRuZHok8dQjAQAAAAApJGwwDQYJKoZIhvcNAQELBQAw\n" |
Thrillex13 | 3:5dceee1c49fc | 46 | "QjELMAkGA1UEBhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczET\n" |
Thrillex13 | 3:5dceee1c49fc | 47 | "MBEGA1UEAxMKR1RTIENBIDFPMTAeFw0xOTAzMTMyMTMwNTdaFw0yMDAzMTEyMTMw\n" |
Thrillex13 | 3:5dceee1c49fc | 48 | "NTdaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH\n" |
Thrillex13 | 3:5dceee1c49fc | 49 | "Ew1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgTExDMRcwFQYDVQQDEw5m\n" |
Thrillex13 | 3:5dceee1c49fc | 50 | "aXJlYmFzZWlvLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALkd\n" |
Thrillex13 | 3:5dceee1c49fc | 51 | "/jeM+PrwIYmM6IE28iN7CjKnBWy+tqNrs5z2AJwM5iLgtgcbc+THuXGElTN7zAWB\n" |
Thrillex13 | 3:5dceee1c49fc | 52 | "SKWv+ezAGe5NiTEEUiWgX1z1VFDj85xpz+Cysn/Oi8MtoN6h8yCmYPtXv8YPInw0\n" |
Thrillex13 | 3:5dceee1c49fc | 53 | "JLkSM5e2uuWVwc/tR1Fh+awpiYQFqGm6DvMq6yAYB/nuL3Gyc4XFgRrxje+VQ+g3\n" |
Thrillex13 | 3:5dceee1c49fc | 54 | "oWE+9NVfqu4smFCutSIGlEdRhGdr/m2u+sc+dnBZNoVOqwSyyFyjpAZvMMvuE5Ip\n" |
Thrillex13 | 3:5dceee1c49fc | 55 | "3ovfA1tq57nl9eQw8fcKsdXOeeXYHc1KBUUC7Xb8F/1+upVML8a5GMULpYkClLXt\n" |
Thrillex13 | 3:5dceee1c49fc | 56 | "OKRRfCJa53YynILJdPkCAwEAAaOCAmQwggJgMA4GA1UdDwEB/wQEAwIFoDATBgNV\n" |
Thrillex13 | 3:5dceee1c49fc | 57 | "HSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBS03YhV70g6\n" |
Thrillex13 | 3:5dceee1c49fc | 58 | "+7MUxtOiluRi1T2GAzAfBgNVHSMEGDAWgBSY0fhuEOvPm+xgnxiQG6DrfQn9KzBk\n" |
Thrillex13 | 3:5dceee1c49fc | 59 | "BggrBgEFBQcBAQRYMFYwJwYIKwYBBQUHMAGGG2h0dHA6Ly9vY3NwLnBraS5nb29n\n" |
Thrillex13 | 3:5dceee1c49fc | 60 | "L2d0czFvMTArBggrBgEFBQcwAoYfaHR0cDovL3BraS5nb29nL2dzcjIvR1RTMU8x\n" |
Thrillex13 | 3:5dceee1c49fc | 61 | "LmNydDArBgNVHREEJDAigg5maXJlYmFzZWlvLmNvbYIQKi5maXJlYmFzZWlvLmNv\n" |
Thrillex13 | 3:5dceee1c49fc | 62 | "bTAhBgNVHSAEGjAYMAgGBmeBDAECAjAMBgorBgEEAdZ5AgUDMC8GA1UdHwQoMCYw\n" |
Thrillex13 | 3:5dceee1c49fc | 63 | "JKAioCCGHmh0dHA6Ly9jcmwucGtpLmdvb2cvR1RTMU8xLmNybDCCAQIGCisGAQQB\n" |
Thrillex13 | 3:5dceee1c49fc | 64 | "1nkCBAIEgfMEgfAA7gB1ALIeBcyLos2KIE6HZvkruYolIGdr2vpw57JJUy3vi5Be\n" |
Thrillex13 | 3:5dceee1c49fc | 65 | "AAABaXkuFzgAAAQDAEYwRAIgVssWhLEYItcpljMfJfkBhnxUrw32ik3C7IyBhkS6\n" |
Thrillex13 | 3:5dceee1c49fc | 66 | "jQcCIAHzoq/0QsRXY8RITJ5z6pThPzJhiSeLhWb6v2MDs6+NAHUAXqdz+d9WwOe1\n" |
Thrillex13 | 3:5dceee1c49fc | 67 | "Nkh90EngMnqRmgyEoRIShBh1loFxRVgAAAFpeS4XEQAABAMARjBEAiBgwY3jVuyU\n" |
Thrillex13 | 3:5dceee1c49fc | 68 | "HTDrfXt7Hhq3AL9kD8hASq/qIXFvHAel1AIgV2DY0UI7PvVl2uHicvaL9BfUPQjP\n" |
Thrillex13 | 3:5dceee1c49fc | 69 | "8/7b5W5jd6HEKbowDQYJKoZIhvcNAQELBQADggEBAAFG/f9zTyPTiYjjbPKpIC3T\n" |
Thrillex13 | 3:5dceee1c49fc | 70 | "MMD8dWvny1DJpL2fQPMcpAkkduW7sFG8mLRh14mSBsWqAusj99nAKt6NJhxZewhp\n" |
Thrillex13 | 3:5dceee1c49fc | 71 | "JKwbcawanW+w2DUzFr0FauVxNIs4xPxcgkCNAGeUj8ZI+cDcSaMOY4WxNrjOgbbI\n" |
Thrillex13 | 3:5dceee1c49fc | 72 | "feOxHsCmIWxch6/vNVxh+54BZFCy723DL8Fo/tDRU73b+gxPJusJva4ABuXSqSFT\n" |
Thrillex13 | 3:5dceee1c49fc | 73 | "EDaRGzdj8AKkoDmRkWLcEg/6a/2dfw8VV7fIAlqVxNQwZWZLtIsBGazxZ5xflrVz\n" |
Thrillex13 | 3:5dceee1c49fc | 74 | "I5AHejNR7guDaWAimhkSOlG11W8BzPtdAo/xJ6JyI4K5kPGIXucniVRmQfmojxc=\n" |
Thrillex13 | 3:5dceee1c49fc | 75 | "-----END CERTIFICATE-----\n" |
Thrillex13 | 3:5dceee1c49fc | 76 | "-----BEGIN CERTIFICATE-----\n" |
Thrillex13 | 3:5dceee1c49fc | 77 | "MIIESjCCAzKgAwIBAgINAeO0mqGNiqmBJWlQuDANBgkqhkiG9w0BAQsFADBMMSAw\n" |
Thrillex13 | 3:5dceee1c49fc | 78 | "HgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMKR2xvYmFs\n" |
Thrillex13 | 3:5dceee1c49fc | 79 | "U2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xNzA2MTUwMDAwNDJaFw0yMTEy\n" |
Thrillex13 | 3:5dceee1c49fc | 80 | "MTUwMDAwNDJaMEIxCzAJBgNVBAYTAlVTMR4wHAYDVQQKExVHb29nbGUgVHJ1c3Qg\n" |
Thrillex13 | 3:5dceee1c49fc | 81 | "U2VydmljZXMxEzARBgNVBAMTCkdUUyBDQSAxTzEwggEiMA0GCSqGSIb3DQEBAQUA\n" |
Thrillex13 | 3:5dceee1c49fc | 82 | "A4IBDwAwggEKAoIBAQDQGM9F1IvN05zkQO9+tN1pIRvJzzyOTHW5DzEZhD2ePCnv\n" |
Thrillex13 | 3:5dceee1c49fc | 83 | "UA0Qk28FgICfKqC9EksC4T2fWBYk/jCfC3R3VZMdS/dN4ZKCEPZRrAzDsiKUDzRr\n" |
Thrillex13 | 3:5dceee1c49fc | 84 | "mBBJ5wudgzndIMYcLe/RGGFl5yODIKgjEv/SJH/UL+dEaltN11BmsK+eQmMF++Ac\n" |
Thrillex13 | 3:5dceee1c49fc | 85 | "xGNhr59qM/9il71I2dN8FGfcddwuaej4bXhp0LcQBbjxMcI7JP0aM3T4I+DsaxmK\n" |
Thrillex13 | 3:5dceee1c49fc | 86 | "FsbjzaTNC9uzpFlgOIg7rR25xoynUxv8vNmkq7zdPGHXkxWY7oG9j+JkRyBABk7X\n" |
Thrillex13 | 3:5dceee1c49fc | 87 | "rJfoucBZEqFJJSPk7XA0LKW0Y3z5oz2D0c1tJKwHAgMBAAGjggEzMIIBLzAOBgNV\n" |
Thrillex13 | 3:5dceee1c49fc | 88 | "HQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1Ud\n" |
Thrillex13 | 3:5dceee1c49fc | 89 | "EwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFJjR+G4Q68+b7GCfGJAboOt9Cf0rMB8G\n" |
Thrillex13 | 3:5dceee1c49fc | 90 | "A1UdIwQYMBaAFJviB1dnHB7AagbeWbSaLd/cGYYuMDUGCCsGAQUFBwEBBCkwJzAl\n" |
Thrillex13 | 3:5dceee1c49fc | 91 | "BggrBgEFBQcwAYYZaHR0cDovL29jc3AucGtpLmdvb2cvZ3NyMjAyBgNVHR8EKzAp\n" |
Thrillex13 | 3:5dceee1c49fc | 92 | "MCegJaAjhiFodHRwOi8vY3JsLnBraS5nb29nL2dzcjIvZ3NyMi5jcmwwPwYDVR0g\n" |
Thrillex13 | 3:5dceee1c49fc | 93 | "BDgwNjA0BgZngQwBAgIwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly9wa2kuZ29vZy9y\n" |
Thrillex13 | 3:5dceee1c49fc | 94 | "ZXBvc2l0b3J5LzANBgkqhkiG9w0BAQsFAAOCAQEAGoA+Nnn78y6pRjd9XlQWNa7H\n" |
Thrillex13 | 3:5dceee1c49fc | 95 | "TgiZ/r3RNGkmUmYHPQq6Scti9PEajvwRT2iWTHQr02fesqOqBY2ETUwgZQ+lltoN\n" |
Thrillex13 | 3:5dceee1c49fc | 96 | "FvhsO9tvBCOIazpswWC9aJ9xju4tWDQH8NVU6YZZ/XteDSGU9YzJqPjY8q3MDxrz\n" |
Thrillex13 | 3:5dceee1c49fc | 97 | "mqepBCf5o8mw/wJ4a2G6xzUr6Fb6T8McDO22PLRL6u3M4Tzs3A2M1j6bykJYi8wW\n" |
Thrillex13 | 3:5dceee1c49fc | 98 | "IRdAvKLWZu/axBVbzYmqmwkm5zLSDW5nIAJbELCQCZwMH56t2Dvqofxs6BBcCFIZ\n" |
Thrillex13 | 3:5dceee1c49fc | 99 | "USpxu6x6td0V7SvJCCosirSmIatj/9dSSVDQibet8q/7UK4v4ZUN80atnZz1yg==\n" |
Thrillex13 | 3:5dceee1c49fc | 100 | "-----END CERTIFICATE-----\n"; |
Thrillex13 | 3:5dceee1c49fc | 101 | |
Thrillex13 | 3:5dceee1c49fc | 102 | //Port Definition |
Thrillex13 | 3:5dceee1c49fc | 103 | DigitalOut led_rojo(LED_RED); |
Thrillex13 | 3:5dceee1c49fc | 104 | DigitalOut led_verde(LED_GREEN); |
Thrillex13 | 3:5dceee1c49fc | 105 | DigitalOut led_azul(LED_BLUE); |
Thrillex13 | 3:5dceee1c49fc | 106 | |
Thrillex13 | 3:5dceee1c49fc | 107 | //Function Prototypes |
Thrillex13 | 3:5dceee1c49fc | 108 | void wifiInit(void); |
Thrillex13 | 3:5dceee1c49fc | 109 | bool isConnectedToWifi(void); |
Thrillex13 | 3:5dceee1c49fc | 110 | void wifiConnect(void); |
Thrillex13 | 3:5dceee1c49fc | 111 | void startServer(int port); |
Thrillex13 | 3:5dceee1c49fc | 112 | int getTCPContent(char *espdata, char *command, char *status); |
Thrillex13 | 3:5dceee1c49fc | 113 | void convertToCharArray(char *arr, unsigned long number); |
Thrillex13 | 3:5dceee1c49fc | 114 | |
Thrillex13 | 3:5dceee1c49fc | 115 | void dump_response(HttpResponse* res); |
Thrillex13 | 3:5dceee1c49fc | 116 | void http_demo(NetworkInterface *net); |
Thrillex13 | 3:5dceee1c49fc | 117 | |
Thrillex13 | 3:5dceee1c49fc | 118 | |
Thrillex13 | 3:5dceee1c49fc | 119 | |
Thrillex13 | 3:5dceee1c49fc | 120 | #endif //MAIN_H |