-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
http-channel-sender/esp/esp-http-channel-sender/esp-http-channel-sender.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
http-channel-sender/esp/esp-https-channel-sender/credentials.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" \ | ||
"MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\n" \ | ||
"YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT\n" \ | ||
"aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ\n" \ | ||
"jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp\n" \ | ||
"xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp\n" \ | ||
"1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG\n" \ | ||
"snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ\n" \ | ||
"U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8\n" \ | ||
"9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E\n" \ | ||
"BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B\n" \ | ||
"AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz\n" \ | ||
"yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE\n" \ | ||
"38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP\n" \ | ||
"AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad\n" \ | ||
"DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME\n" \ | ||
"HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==\n" \ | ||
"-----END CERTIFICATE-----\n"; | ||
#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 |
57 changes: 57 additions & 0 deletions
57
http-channel-sender/esp/esp-https-channel-sender/esp-https-channel-sender.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |