diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ca56f7c..78fbf2e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v4 - uses: arduino/arduino-lint-action@v1 with: - library-manager: submit + library-manager: update compliance: strict build-for-arduino: @@ -58,4 +58,4 @@ jobs: source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json cli-compile-flags: | - --warnings="none" - libraries: ${{env.GLOBAL_LIBS}} \ No newline at end of file + libraries: ${{env.GLOBAL_LIBS}} diff --git a/README.md b/README.md index ac50a4c..82ad473 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,5 @@ Currently supports: | | WiFi/WebSockets | WiFi/HTTP | |--------------|------------------|-----------| -| ESP32 | ✅ | ❌ | -| Arduino WiFi | ❌ | ❌ | \ No newline at end of file +| ESP32 | ✅ | ✅ | +| Arduino WiFi | ❌ | ❌ | diff --git a/src/deploii.cpp b/src/deploii.cpp index cca1cf5..cb6991b 100644 --- a/src/deploii.cpp +++ b/src/deploii.cpp @@ -34,6 +34,7 @@ void Deploii::loop() { DeploiiHandler* Deploii::selectHandler() { if (_medium == Medium::WiFi && _protocol == Protocol::WebSockets) return new DeploiiHandlerWiFiWS(_debug); + if (_medium == Medium::WiFi && _protocol == Protocol::HTTP) return new DeploiiHandlerWiFiHTTP(_debug); return new DeploiiHandler(_debug); } diff --git a/src/deploii.h b/src/deploii.h index 64852cd..3f712dc 100644 --- a/src/deploii.h +++ b/src/deploii.h @@ -1,5 +1,5 @@ -#ifndef Deploii_h -#define Deploii_h +#ifndef DEPLOII_h +#define DEPLOII_h #include "Arduino.h" #include @@ -39,9 +39,9 @@ class Deploii { void connect(); void connect(char* ssid, const char* pwd, - const char* host = Deploii_HOST, - const int port = Deploii_PORT, - const char* url = Deploii_WS_URL, + const char* host = DEPLOII_HOST, + const int port = DEPLOII_PORT, + const char* url = DEPLOII_WS_URL, bool ssl = true); void interval(int intervalLength, void (*cb)(void)); @@ -61,4 +61,4 @@ class Deploii { #include "deploii.tpp" -#endif \ No newline at end of file +#endif diff --git a/src/deploii_certs.h b/src/deploii_certs.h new file mode 100644 index 0000000..68474ac --- /dev/null +++ b/src/deploii_certs.h @@ -0,0 +1,32 @@ +static const char* buypass_cert = + "-----BEGIN CERTIFICATE-----\n" + "MIIFWTCCA0GgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJOTzEd\n" + "MBsGA1UECgwUQnV5cGFzcyBBUy05ODMxNjMzMjcxIDAeBgNVBAMMF0J1eXBhc3Mg\n" + "Q2xhc3MgMiBSb290IENBMB4XDTEwMTAyNjA4MzgwM1oXDTQwMTAyNjA4MzgwM1ow\n" + "TjELMAkGA1UEBhMCTk8xHTAbBgNVBAoMFEJ1eXBhc3MgQVMtOTgzMTYzMzI3MSAw\n" + "HgYDVQQDDBdCdXlwYXNzIENsYXNzIDIgUm9vdCBDQTCCAiIwDQYJKoZIhvcNAQEB\n" + "BQADggIPADCCAgoCggIBANfHXvfBB9R3+0Mh9PT1aeTuMgHbo4Yf5FkNuud1g1Lr\n" + "6hxhFUi7HQfKjK6w3Jad6sNgkoaCKHOcVgb/S2TwDCo3SbXlzwx87vFKu3MwZfPV\n" + "L4O2fuPn9Z6rYPnT8Z2SdIrkHJasW4DptfQxh6NR/Md+oW+OU3fUl8FVM5I+GC91\n" + "1K2GScuVr1QGbNgGE41b/+EmGVnAJLqBcXmQRFBoJJRfuLMR8SlBYaNByyM21cHx\n" + "MlAQTn/0hpPshNOOvEu/XAFOBz3cFIqUCqTqc/sLUegTBxj6DvEr0VQVfTzh97QZ\n" + "QmdiXnfgolXsttlpF9U6r0TtSsWe5HonfOV116rLJeffawrbD02TTqigzXsu8lkB\n" + "arcNuAeBfos4GzjmCleZPe4h6KP1DBbdi+w0jpwqHAAVF41og9JwnxgIzRFo1clr\n" + "Us3ERo/ctfPYV3Me6ZQ5BL/T3jjetFPsaRyifsSP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4x3kqdbQCtCev9eBCfHJxyYNrJgWVqA=\n" + "-----END CERTIFICATE-----\n"; \ No newline at end of file diff --git a/src/handler/deploii_handler.h b/src/handler/deploii_handler.h index e287315..08ccb74 100644 --- a/src/handler/deploii_handler.h +++ b/src/handler/deploii_handler.h @@ -1,19 +1,26 @@ -#ifndef Deploii_handler_h -#define Deploii_handler_h +#ifndef DEPLOII_handler_h +#define DEPLOII_handler_h + +#include "deploii_certs.h" #include "Arduino.h" #include #if defined(ESP32) #include +#include #endif /* Constants for connection */ -#define Deploii_HOST "deploii.no" -#define Deploii_PORT 443 -#define Deploii_WS_URL "/ws" +#define DEPLOII_HOST "deploii.no" +#define DEPLOII_PORT 443 +#define DEPLOII_WS_URL "/mcu/ws" +#define DEPLOII_HTTP_URL "/mcu/data" + +#define DEPLOII_WIFI_RECONNECT_TIME 1000 +#define DEPLOII_WS_RECONNECT_TIME 2000 class DeploiiHandler { public: @@ -26,9 +33,9 @@ class DeploiiHandler { virtual void connect(char* boardID, char* ssid, const char* pwd, - const char* host = Deploii_HOST, - const int port = Deploii_PORT, - const char* url = Deploii_WS_URL, + const char* host = DEPLOII_HOST, + const int port = DEPLOII_PORT, + const char* url = DEPLOII_WS_URL, bool ssl = true); private: @@ -68,4 +75,31 @@ class DeploiiHandlerWiFiWS : public DeploiiHandler { #endif }; -#endif \ No newline at end of file +class DeploiiHandlerWiFiHTTP : public DeploiiHandler { + public: + DeploiiHandlerWiFiHTTP(bool debug = false); + ~DeploiiHandlerWiFiHTTP(); + + virtual void send(const uint8_t* data, size_t size); + virtual void loop(); + virtual void connect(char* boardID, + char* ssid, + const char* pwd, + const char* host, + const int port, + const char* url, + bool ssl); + + private: + bool _debug; + void connectWiFi(char* ssid, const char* pwd); + +#if defined(ESP32) + HTTPClient _http; +#elif defined(ARDUINO) + +#else + +#endif +}; +#endif diff --git a/src/handler/deploii_handler_WiFi_HTTP.cpp b/src/handler/deploii_handler_WiFi_HTTP.cpp new file mode 100644 index 0000000..eba8094 --- /dev/null +++ b/src/handler/deploii_handler_WiFi_HTTP.cpp @@ -0,0 +1,78 @@ +#include "deploii_handler.h" + +DeploiiHandlerWiFiHTTP::DeploiiHandlerWiFiHTTP(bool debug) +#if defined(ESP32) + : _http(), _debug(debug) +#elif defined(ARDUINO) + : _debug(debug) +#else + : _debug(debug) +#endif +{ +} + +DeploiiHandlerWiFiHTTP::~DeploiiHandlerWiFiHTTP() { +#if defined(ESP32) +#elif defined(ARDUINO) +#else +#endif +} + +void DeploiiHandlerWiFiHTTP::connect( + char* boardID, + char* ssid, + const char* pwd, + const char* host, + const int port, + const char* url, + bool ssl) { + connectWiFi(ssid, pwd); +#if defined(ESP32) + if (ssl) + _http.begin(host, port, url, buypass_cert); + else + _http.begin(host, port, url); + + _http.addHeader("Authorization", boardID, false, false); +#elif defined(ARDUINO) +#else +#endif +} + +void DeploiiHandlerWiFiHTTP::loop() { +} + +void DeploiiHandlerWiFiHTTP::send(const uint8_t* data, size_t size) { +#if defined(ESP32) + _http.POST((uint8_t*)data, size); +#elif defined(ARDUINO) +#else +#endif +} + +#if defined(ESP32) + +void DeploiiHandlerWiFiHTTP::connectWiFi(char* ssid, const char* pwd) { + if (_debug) Serial.println("Connecting to WiFi"); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, pwd); + while (WiFi.status() != WL_CONNECTED) { + delay(DEPLOII_WIFI_RECONNECT_TIME); + if (_debug) { + Serial.println("Connecting to WiFi"); + } + } + if (_debug) { + Serial.println("WiFi connected"); + Serial.println(WiFi.localIP()); + } + if (_debug) Serial.println(WiFi.localIP()); +} +#elif defined(ARDUINO) + +void DeploiiHandlerWiFiHTTP::connectWiFi(char* ssid, const char* pwd) { + while (WiFi.begin(ssid, pwd) != WL_CONNECTED) delay(DEPLOII_WIFI_RECONNECT_TIME); +} +#else +void DeploiiHandlerWiFiHTTP::connectWiFi(char* ssid, const char* pwd) {} +#endif diff --git a/src/handler/deploii_handler_WiFi_WS.cpp b/src/handler/deploii_handler_WiFi_WS.cpp index feae884..743edf8 100644 --- a/src/handler/deploii_handler_WiFi_WS.cpp +++ b/src/handler/deploii_handler_WiFi_WS.cpp @@ -4,12 +4,6 @@ Deploii handler for communication using WiFI and WebSockets */ -/* - Constants -*/ -#define Deploii_WIFI_RECONNECT_TIME 1000 -#define DEPLOII_WS_RECONNECT_TIME 2000 - /* Class definitions */ @@ -85,7 +79,7 @@ void DeploiiHandlerWiFiWS::connectWiFi(char* ssid, const char* pwd) { WiFi.mode(WIFI_STA); WiFi.begin(ssid, pwd); while (WiFi.status() != WL_CONNECTED) { - delay(Deploii_WIFI_RECONNECT_TIME); + delay(DEPLOII_WIFI_RECONNECT_TIME); if (_debug) { Serial.println("Connecting to WiFi"); } @@ -113,7 +107,7 @@ void DeploiiHandlerWiFiWS::connectWS(char* boardID, const char* host, const int #elif defined(ARDUINO) void DeploiiHandlerWiFiWS::connectWiFi(char* ssid, const char* pwd) { - while (WiFi.begin(ssid, pwd) != WL_CONNECTED) delay(Deploii_WIFI_RECONNECT_TIME); + while (WiFi.begin(ssid, pwd) != WL_CONNECTED) delay(DEPLOII_WIFI_RECONNECT_TIME); } void DeploiiHandlerWiFiWS::connectWS(char* boardID, const char* host, const int port, const char* url, bool ssl) { @@ -125,4 +119,4 @@ void DeploiiHandlerWiFiWS::connectWiFi(char* ssid, const char* pwd) {} void DeploiiHandlerWiFiWS::connectWS(char* boardID, const char* host, const int port, const char* url, bool ssl) { } -#endif \ No newline at end of file +#endif