-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add supports all Arduino devices except for AVR.
- Loading branch information
Showing
358 changed files
with
82,874 additions
and
1,671 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
/** | ||
* Created by K. Suwatchai (Mobizt) | ||
* | ||
* | ||
* Email: [email protected] | ||
* | ||
* | ||
* Github: https://github.com/mobizt | ||
* | ||
* | ||
* Copyright (c) 2023 mobizt | ||
* | ||
*/ | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) | ||
#include <WiFi.h> | ||
#elif defined(ESP8266) | ||
#include <ESP8266WiFi.h> | ||
#elif __has_include(<WiFiNINA.h>) | ||
#include <WiFiNINA.h> | ||
#elif __has_include(<WiFi101.h>) | ||
#include <WiFi101.h> | ||
#elif __has_include(<WiFiS3.h>) | ||
#include <WiFiS3.h> | ||
#endif | ||
|
||
#include <ESP_Signer.h> | ||
|
@@ -30,6 +36,38 @@ | |
#define CLIENT_EMAIL "Client Email" // Taken from "client_email" key in JSON file. | ||
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----\\n-----END PRIVATE KEY-----\n"; // Taken from "private_key" key in JSON file. | ||
|
||
const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n" | ||
"MIIFVzCCAz+gAwIBAgINAgPlk28xsBNJiGuiFzANBgkqhkiG9w0BAQwFADBHMQsw\n" | ||
"CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExM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BAUwAwEB/zAdBgNVHQ4E\n" | ||
"FgQU5K8rJnEaK0gnhS9SZizv8IkTcT4wDQYJKoZIhvcNAQEMBQADggIBAJ+qQibb\n" | ||
"C5u+/x6Wki4+omVKapi6Ist9wTrYggoGxval3sBOh2Z5ofmmWJyq+bXmYOfg6LEe\n" | ||
"QkEzCzc9zolwFcq1JKjPa7XSQCGYzyI0zzvFIoTgxQ6KfF2I5DUkzps+GlQebtuy\n" | ||
"h6f88/qBVRRiClmpIgUxPoLW7ttXNLwzldMXG+gnoot7TiYaelpkttGsN/H9oPM4\n" | ||
"7HLwEXWdyzRSjeZ2axfG34arJ45JK3VmgRAhpuo+9K4l/3wV3s6MJT/KYnAK9y8J\n" | ||
"ZgfIPxz88NtFMN9iiMG1D53Dn0reWVlHxYciNuaCp+0KueIHoI17eko8cdLiA6Ef\n" | ||
"MgfdG+RCzgwARWGAtQsgWSl4vflVy2PFPEz0tv/bal8xa5meLMFrUKTX5hgUvYU/\n" | ||
"Z6tGn6D/Qqc6f1zLXbBwHSs09dR2CQzreExZBfMzQsNhFRAbd03OIozUhfJFfbdT\n" | ||
"6u9AWpQKXCBfTkBdYiJ23//OYb2MI3jSNwLgjt7RETeJ9r/tSQdirpLsQBqvFAnZ\n" | ||
"0E6yove+7u7Y/9waLd64NnHi/Hm3lCXRSHNboTXns5lndcEZOitHTtNCjv0xyBZm\n" | ||
"2tIMPNuzjsmhDYAPexZ3FL//2wmUspO8IFgV6dtxQ/PeEMMA3KgqlbbC1j+Qa3bb\n" | ||
"bP6MvPJwNQzcmRk13NfIRmPVNnGuV/u3gm3c\n" | ||
"-----END CERTIFICATE-----\n"; | ||
|
||
#if defined(ARDUINO_RASPBERRY_PI_PICO_W) | ||
WiFiMulti multi; | ||
#endif | ||
|
@@ -101,7 +139,17 @@ void setup() | |
/** Assign the callback function for token ggeneration status (optional) */ | ||
config.token_status_callback = tokenStatusCallback; | ||
|
||
// To set the device time without NTP time acquisition. | ||
/** If Google Root certificate data provided */ | ||
// config.cert.data = rootCACert; | ||
|
||
/** If Google Root certificate data provided */ | ||
// config.cert.file = "/path/to/pem/file"; | ||
// config.cert.file_storage = esp_signer_mem_storage_type_sd; | ||
|
||
/** Mount SD card if SD was used to store certificate. */ | ||
// SD_Card_Mounting(); // See src/ESP_Signer_SD_helper.h | ||
|
||
/** To set the device time without NTP time acquisition. */ | ||
// Signer.setSystemTime(<timestamp>); | ||
|
||
/* Create token */ | ||
|
@@ -121,7 +169,7 @@ void loop() | |
bool ready = Signer.tokenReady(); | ||
if (ready) | ||
{ | ||
int t = Signer.getExpiredTimestamp() - config.signer.preRefreshSeconds - time(nullptr); | ||
int t = Signer.getExpiredTimestamp() - config.signer.preRefreshSeconds - Signer.getCurrentTimestamp(); | ||
// Token will be refreshed automatically | ||
|
||
Serial.print("Remaining seconds to refresh the token, "); | ||
|
@@ -134,13 +182,13 @@ void tokenStatusCallback(TokenInfo info) | |
{ | ||
if (info.status == esp_signer_token_status_error) | ||
{ | ||
Serial.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str()); | ||
Serial.printf("Token error: %s\n", Signer.getTokenError(info).c_str()); | ||
Signer.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str()); | ||
Signer.printf("Token error: %s\n", Signer.getTokenError(info).c_str()); | ||
} | ||
else | ||
{ | ||
Serial.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str()); | ||
Signer.printf("Token info: type = %s, status = %s\n", Signer.getTokenType(info).c_str(), Signer.getTokenStatus(info).c_str()); | ||
if (info.status == esp_signer_token_status_ready) | ||
Serial.printf("Token: %s\n", Signer.accessToken().c_str()); | ||
Signer.printf("Token: %s\n", Signer.accessToken().c_str()); | ||
} | ||
} |
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
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
Oops, something went wrong.