Skip to content

Commit

Permalink
http-channel-sender added
Browse files Browse the repository at this point in the history
  • Loading branch information
dexif committed Jan 23, 2024
1 parent 65d6f5e commit b6f179b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "YOUR_WIFI";
const char* password = "PASSWORD";

const char* serverName = "http://gw.flespi.io:00000";

void setup() {
Serial.begin(115200);

WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected IP Address: ");
Serial.println(WiFi.localIP());
}

void loop() {
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;

http.begin(client, serverName);
http.addHeader("Content-Type", "application/json");
String httpRequestData = "[{\"ident\":\"123\"}]";
int httpResponseCode = http.POST(httpRequestData);

Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
delay(5000);
}
35 changes: 35 additions & 0 deletions http-channel-sender/esp/esp-https-channel-sender/credentials.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#define WIFI_SSID "YOUR_WIFI"
#define WIFI_PASSWORD "PASSWORD"

#define HTTPS_SERVER "https://gw.flespi.io:00000/"
#if defined(ESP32)
#include <WiFi.h>

// Root CA (GlobalSign Root CA)
const static char* root_ca PROGMEM = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\n" \
"A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\n" \
"b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\n" \
"MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBg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
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
//SHA1 FINGERPRINT (flespi.io domain)
const static char fingerprint[] PROGMEM = "35 BB 03 10 B4 2B EE F8 CB BE 2C D8 45 8D C2 D5 D0 F8 2D 5B";
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include "credentials.h" // WIFI/MQTT credentials, certs

#if defined(ESP32) || defined(ESP8266)
WiFiClientSecure wifiClient;
#endif


void setup() {
Serial.begin(115200);
Serial.println("Ready");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(">");
}
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}

void loop() {
WiFiClientSecure *client = new WiFiClientSecure;
if(client) {
#if defined(ESP32)
client->setCACert(root_ca);
#elif defined(ESP8266)
client->setFingerprint(fingerprint);
#endif

HTTPClient https;
Serial.print("HTTPS begin\n");
if (https.begin(*client, HTTPS_SERVER)) { // HTTPS
Serial.print("HTTPS POST send\n");
https.addHeader("Content-Type", "application/json");
int httpCode = https.POST("[{\"ident\":\"123\"}]");
if (httpCode > 0) {
Serial.printf("HTTPS POST code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
}
}
else {
Serial.printf("HTTPS POST failed: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
}
}
else {
Serial.printf("HTTPS failed to connect\n");
}
Serial.println();

delay(5000);
}
2 changes: 2 additions & 0 deletions message-converter/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json

0 comments on commit b6f179b

Please sign in to comment.