Thanks to your steep pass it IT finally WORKS !!!
Here are a few more stumbling blocks to be aware of:
#define FB_ENABLE_EXTERNAL_CLIENT must be set for Ethernet connection. For WLAN it must be deactivated. Therefore WLAN worked again after reinstalling the lib as described above.
you need to define the GPIO´s for Core 2 as following in the code
trust_anchors URL => www.google.com seems to work as Firebase is a google product
#include <M5Core2.h> is NOT necessary => if you use it with M5.begin you need to delete Serial.begin(115200) => otherwise your CPU will crash => known issue also thanks to felmue
NTP server is not working => always returns 0 => seems to work without NTP
Here is the working code i use:
/**
Created by K. Suwatchai (Mobizt)
Email:
k_suwatchai@hotmail.com
Github:
https://github.com/mobizt/Firebase-ESP-Client
Copyright (c) 2022 mobizt
*/
/** This example shows the basic RTDB usage with external Client.
This example used your Arduino device and WIZnet W5500 (Ethernet) device which SSLClient
https://github.com/OPEnSLab-OSU/SSLClient
will be used as the external Client.
This SSLClient,
https://github.com/OPEnSLab-OSU/SSLClient can't use in ESP8266 device due to wdt reset error.
Don't gorget to define this in FirebaseFS.h
#define FB_ENABLE_EXTERNAL_CLIENT
*/
#include <Firebase_ESP_Client.h>
// Provide the token generation process info.
#include <addons/TokenHelper.h>
// Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>
#include <Ethernet.h>
/* 1. Install SSLClient library */
// https://github.com/OPEnSLab-OSU/SSLClient
#include <SSLClient.h>
/* 2. Create Trus anchors for the server i.e. www.google.com */
// https://github.com/OPEnSLab-OSU/SSLClient/blob/master/TrustAnchors.md
// or generate using this site https://openslab-osu.github.io/bearssl-certificate-utility/
#include "trust_anchors.h"
// For NTP time client
#include "MB_NTP.h"
// For the following credentials, see examples/Authentications/SignInAsUser/EmailPassword/EmailPassword.ino
/* 3. Define the API Key */
#define API_KEY "Key"
/* 4. Define the RTDB URL */
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
/* 5. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "Email"
#define USER_PASSWORD "password"
/* 6. Defined the Ethernet module connection */
#define WIZNET_RESET_PIN 19 // Connect W5500 Reset pin to GPIO 19 for Core 2
#define WIZNET_CS_PIN 26 // Connect W5500 CS pin to GPIO 26 for Core 2
#define WIZNET_MISO_PIN 38 // Connect W5500 MISO pin to GPIO 38 for Core 2
#define WIZNET_MOSI_PIN 23 // Connect W5500 MOSI pin to GPIO 23 for Core 2
#define WIZNET_SCLK_PIN 18 // Connect W5500 SCLK pin to GPIO 18 for Core 2
/* 7. Define the analog GPIO pin to pull random bytes from, used in seeding the RNG for SSLClient */
const int analog_pin = 27; // Core 2 => GPIO 27 (Analog pin)
/* 8. Define MAC */
uint8_t mac[] = { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 };
/* 9. Define IP (Optional) */
IPAddress ip(192, 168, 1, 50);
IPAddress myDns(8, 8, 8, 8);
// Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
int count = 0;
volatile bool dataChanged = false;
EthernetClient basic_client;
SSLClient ssl_client(basic_client, TAs, (size_t)TAs_NUM, analog_pin);
// For NTP client
EthernetUDP udpClient;
MB_NTP ntpClient(&udpClient, "pool.ntp.org" /* NTP host /, 123 / NTP port /, 0 / timezone offset in seconds */);
uint32_t timestamp = 0;
void ResetEthernet() {
Serial.println("Resetting WIZnet W5500 Ethernet Board... ");
pinMode(WIZNET_RESET_PIN, OUTPUT);
digitalWrite(WIZNET_RESET_PIN, HIGH);
delay(200);
digitalWrite(WIZNET_RESET_PIN, LOW);
delay(50);
digitalWrite(WIZNET_RESET_PIN, HIGH);
delay(200);
}
void networkConnection() {
Ethernet.init(WIZNET_CS_PIN);
ResetEthernet();
Serial.println("Starting Ethernet connection...");
Ethernet.begin(mac);
unsigned long to = millis();
while (Ethernet.linkStatus() == LinkOFF || millis() - to < 2000) {
delay(100);
}
if (Ethernet.linkStatus() == LinkON) {
Serial.print("Connected with IP ");
Serial.println(Ethernet.localIP());
} else {
Serial.println("Can't connect");
}
}
// Define the callback function to handle server status acknowledgement
void networkStatusRequestCallback() {
// Set the network status
fbdo.setNetworkStatus(Ethernet.linkStatus() == LinkON);
}
// Define the callback function to handle server connection
void tcpConnectionRequestCallback(const char *host, int port) {
// You may need to set the system timestamp to use for
// auth token expiration checking.
if (timestamp == 0) {
timestamp = ntpClient.getTime(2000 /* wait 2000 ms */);
Serial.print("timestamp from NTP: ");
Serial.println(timestamp);
if (timestamp > 0) {
Firebase.setSystemTime(timestamp);
Serial.print("Firebase => setSystemTime done");
}
}
Serial.print("Connecting to server via external Client... ");
if (!ssl_client.connect(host, port)) {
Serial.println("failed.");
return;
}
Serial.println("success.");
}
void setup() {
SPI.begin(WIZNET_SCLK_PIN, WIZNET_MISO_PIN, WIZNET_MOSI_PIN, -1);
Serial.begin(115200);
networkConnection();
Serial_Printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the user sign in credentials */
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
/* fbdo.setExternalClient and fbdo.setExternalClientCallbacks must be called before Firebase.begin */
/* Assign the pointer to global defined external SSL Client object */
fbdo.setExternalClient(&ssl_client);
/* Assign the required callback functions */
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback, networkConnection, networkStatusRequestCallback);
Firebase.setDoubleDigits(5);
Firebase.begin(&config, &auth);
}
void loop() {
// Firebase.ready() should be called repeatedly to handle authentication tasks.
if (Firebase.ready() && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)) {
sendDataPrevMillis = millis();
Serial_Printf("Set bool... %s\n", Firebase.RTDB.setBool(&fbdo, F("/test/bool"), count % 2 == 0) ? "ok" : fbdo.errorReason().c_str());
count++;
}
}