Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21 esp32 http support #23

Merged
merged 8 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}}
libraries: ${{env.GLOBAL_LIBS}}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Currently supports:

| | WiFi/WebSockets | WiFi/HTTP |
|--------------|------------------|-----------|
| ESP32 | ✅ | |
| Arduino WiFi | ❌ | ❌ |
| ESP32 | ✅ | |
| Arduino WiFi | ❌ | ❌ |
1 change: 1 addition & 0 deletions src/deploii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
32 changes: 32 additions & 0 deletions src/deploii_certs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
static const char* buypass_cert =
"-----BEGIN CERTIFICATE-----\n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iY8f93ZHsM+71bbRuMGjeyNYmsHVee7QHIJihdjK4TWxP\n"
"AgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFMmAd+BikoL1Rpzz\n"
"uvdMw964o605MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAgEAU18h\n"
"9bqwOlI5LJKwbADJ784g7wbylp7ppHR/ehb8t/W2+xUbP6umwHJdELFx7rxP462s\n"
"A20ucS6vxOOto70MEae0/0qyexAQH6dXQbLArvQsWdZHEIjzIVEpMMpghq9Gqx3t\n"
"OluwlN5E40EIosHsHdb9T7bWR9AUC8rmyrV7d35BH16Dx7aMOZawP5aBQW9gkOLo\n"
"+fsicdl9sz1Gv7SEr5AcD48Saq/v7h56rgJKihcrdv6sVIkkLE8/trKnToyokZf7\n"
"KcZ7XC25y2a2t6hbElGFtQl+Ynhw/qlqYLYdDnkM/crqJIByw5c/8nerQyIKx+u2\n"
"DISCLIBrQYoIwOula9+ZEsuK1V6ADJHgJgg2SMX6OBE1/yWDLfJ6v9r9jv6ly0Us\n"
"H8SIU653DtmadsWOLB2jutXsMq7Aqqz30XpN69QH4kj3Io6wpJ9qzo6ysmD0oyLQ\n"
"I+uUWnpp3Q+/QFesa1lQ2aOZ4W7+jQF5JyMV3pKdewlNWudLSDBaGOYKbeaP4NK7\n"
"5t98biGCwWg5TbSYWGZizEqQXsP6JwSxeRV0mcy+rSDeJmAc61ZRpqPq5KM/p/9h\n"
"3PFaTWwyI0PurKju7koSCTxdccK+efrCh2gdC/1cacwG0Jp9VJkqyTkaGa9LKkPz\n"
"Y11aWOIv4x3kqdbQCtCev9eBCfHJxyYNrJgWVqA=\n"
"-----END CERTIFICATE-----\n";
38 changes: 36 additions & 2 deletions src/handler/deploii_handler.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#ifndef Deploii_handler_h
#define Deploii_handler_h

#include "deploii_certs.h"

#include "Arduino.h"
#include <WiFi.h>
#if defined(ESP32)
#include <WebSocketsClient.h>
#include <HTTPClient.h>
#endif

/*
Expand All @@ -13,7 +16,11 @@

#define Deploii_HOST "deploii.no"
#define Deploii_PORT 443
#define Deploii_WS_URL "/ws"
#define Deploii_WS_URL "/mcu/ws"
#define Deploii_HTTP_URL "/mcu/data"
Bissas marked this conversation as resolved.
Show resolved Hide resolved

#define Deploii_WIFI_RECONNECT_TIME 1000
Bissas marked this conversation as resolved.
Show resolved Hide resolved
#define DEPLOII_WS_RECONNECT_TIME 2000

class DeploiiHandler {
public:
Expand Down Expand Up @@ -68,4 +75,31 @@ class DeploiiHandlerWiFiWS : public DeploiiHandler {
#endif
};

#endif
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
78 changes: 78 additions & 0 deletions src/handler/deploii_handler_WiFi_HTTP.cpp
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions src/handler/deploii_handler_WiFi_WS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading