Skip to content

Commit

Permalink
Add supports all Arduino devices except for AVR.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Aug 12, 2023
1 parent aa35c12 commit cc5148c
Show file tree
Hide file tree
Showing 358 changed files with 82,874 additions and 1,671 deletions.
78 changes: 67 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Service Account credentials i.e. project_id, client_email and private_key wh

See [How to Create Service Account Private Key](#how-to-create-service-account-private-key) below.

This library supports ESP8266, ESP32 and Raspberry Pi Pico (RP2040).
This library supports most Arduino devices except for AVR platform.

This library supports native ethernet for ESP8266 and ESP32 and SPI Ethernet for Raspberry Pi Pico.

Expand All @@ -24,7 +24,12 @@ And other network interface clients e.g., WiFiClient, EthernetClient and GSMClie
* NodeMCU-32
* WEMOS LOLIN32
* TTGO T8 V1.8
* Raspberry Pi Pico W
* Arduino MKR WiFi 1010
* Arduino MKR 1000 WIFI
* Arduino Nano 33 IoT
* Arduino MKR Vidor 4000
* Raspberry Pi Pico (RP2040)
* Arduino UNO R4 WiFi (Renesas).



Expand Down Expand Up @@ -167,6 +172,12 @@ const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----\n...\n-----END P
#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 <ESPSigner.h>
Expand Down Expand Up @@ -266,7 +277,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, ");
Expand All @@ -279,14 +290,14 @@ 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)
erial.printf("Token: %s\n", Signer.accessToken().c_str());
Signer.printf("Token: %s\n", Signer.accessToken().c_str());
}
}
Expand Down Expand Up @@ -387,16 +398,27 @@ void setExternalClient(Client *client, ESP_Signer_NetworkConnectionRequestCallba
ESP_Signer_NetworkStatusRequestCallback networkStatusCB);
```
#### Assign UDP client and gmt offset for NTP time synching when using external SSL client
param **`client`** The pointer to UDP client based on the network type.
#### Assign TinyGsm Clients.
param **`gmtOffset`** The GMT time offset.
param **`client`** The pointer to TinyGsmClient.
param **`modem`** The pointer to TinyGsm modem object. Modem should be initialized and/or set mode before transfering data.
param **`pin`** The SIM pin.
param **`apn`** The GPRS APN (Access Point Name).
param **`user`** The GPRS user.
param **`password`** The GPRS password.
```cpp
void setUDPClient(UDP *client, float gmtOffset = 0);
void setGSMClient(Client *client, void *modem, const char *pin, const char *apn, const char *user, const char *password);
```
#### Set the network status acknowledgement.
param **`status`** The network status.
Expand Down Expand Up @@ -472,6 +494,15 @@ unsigned long getExpiredTimestamp();
```
#### Get the current timestamp.
return **`timestamp`**
```cpp
uint64_t getCurrentTimestamp();
```
#### Refresh the access token
```cpp
Expand Down Expand Up @@ -582,6 +613,31 @@ bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool
```
#### Initiate SD card with SdFat SDIO configuration (with SdFat included only).
param **`sdFatSDIOConfig`** The pointer to SdioConfig object for SdFat SDIO configuration.
return **`boolean`** The boolean value indicates the success of operation.
```cpp
bool sdBegin(SdioConfig *sdFatSDIOConfig);
```
#### Formatted printing on Serial.
```cpp
void printf(const char *format, ...);
```
#### Get free Heap memory.
return **`Free memory amount in byte`**
```cpp
int getFreeHeap();
```
## License
The MIT License (MIT)
Expand Down
68 changes: 58 additions & 10 deletions examples/Basic/Basic.ino
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>
Expand All @@ -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"
"CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU\n"
"MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw\n"
"MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp\n"
"Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUj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88/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
Expand Down Expand Up @@ -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 */
Expand All @@ -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, ");
Expand All @@ -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());
}
}
10 changes: 5 additions & 5 deletions examples/Ethernet/ESP32/ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,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();

Serial.print("Remaining seconds to refresh the token, ");
Serial.println(t);
Expand All @@ -189,13 +189,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());
}
}
10 changes: 5 additions & 5 deletions examples/Ethernet/ESP8266/ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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();

Serial.print("Remaining seconds to refresh the token, ");
Serial.println(t);
Expand All @@ -151,13 +151,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());
}
}
Loading

0 comments on commit cc5148c

Please sign in to comment.