Replies: 3 comments 2 replies
-
You should read the issue template before open the issue. If this is not issue it should go to discussion. |
Beta Was this translation helpful? Give feedback.
-
The library supports ethernet modules both MAC and PHY which supported by ESP32 and ESP8266 Core SDK which the supported ethernet modules you can read this on the readme. Your ethernet module is not natively supported by ESP32 core. In this case you need to setup the external basic Client (EthernetClient) to work with other SSL client libraries and use it with this library. The "basic Client" means Network Interface Clients that work without SSL encryption/decryption e.g. WiFiClient, GSMClient and EthernetClient. The Firebase server accepts only SSL protocol connection via port 443 which you can't use your Ethernet Client to connect to Firebase server without SSL engine library. SSL library was used to handle SSL encryption/decryption your data from basic Client before sending and after receiving to/from server. This Firebase library allows you to use external SSL Client to work with your ESP32 and ESP8266. This example showed how to use external SSL Client (WiFiClient with SSL) with this Firebase library. For your case I recommend this SSL Client library which is just WiFiClientSecure ESP32 Core library modification version to use with network interfaces Clients. The Arduino Ethernet.h library has limited buffer for data transmission and cannot work properly with SSL Client which required larger buffer. You must install Ethernet library that provided large buffer as this EthernetLarge library. To setup SSL Client to ready to use with this Firebase library, you can define the basic Client and SSL Client in your sketch as. // If you're already installed EthernetLarge library, you can include Ethernet.h as usual
#include "Ethernet.h"
// If you're already installed SSLClient library
#include "SSLClient.h"
EthernetClient basic_client;
SSLClient ssl_client(&basic_client);
After you initiate the Ethernet with The complete example code #include "Ethernet.h"
#include "SSLClient.h"
#include <Firebase_ESP_Client.h>
EthernetClient basic_client;
SSLClient ssl_client(&basic_client);
#include <addons/TokenHelper.h>
#include <addons/RTDBHelper.h>
#define API_KEY "API_KEY"
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
#define USER_EMAIL "USER_EMAIL"
#define USER_PASSWORD "USER_PASSWORD"
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
unsigned long count = 0;
void ethernet_setup()
{
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(ETHERNET_CS); // CCU ESP32 to match potential CCU CS pin
if (Ethernet.begin(mac) == 0)
{
Serial.printf("Failed to configure Ethernet using DHCP\n");
delay(20);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
delay(20);
// while (true) {
// delay(1); // do nothing, no point running without Ethernet hardware
// }
}
if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println("Ethernet cable is not connected.");
}
// try to congifure using ethernet_ip_address address instead of DHCP:
Ethernet.begin(mac, ethernet_ip_address, my_ethernet_DNS);
}
else
{
Serial.print("DHCP assigned ethernet_ip_address: ");
delay(20);
Serial.println(Ethernet.localIP());
delay(20);
}
}
// 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)
{
Serial.print("Connecting to server via external Client... ");
if (!ssl_client.connect(host, port))
{
Serial.println("failed.");
return;
}
Serial.println("success.");
}
void setup()
{
Serial.begin(115200);
ethernet_setup();
Serial_Printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
config.api_key = API_KEY;
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
config.database_url = DATABASE_URL;
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
fbdo.setExternalClient(&ssl_client);
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback, ethernet_setup, networkStatusRequestCallback);
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++;
}
}
|
Beta Was this translation helpful? Give feedback.
-
I have checked later that Adafruit recommend Ethernet2 library, but EthernetLarge library works with WiZnet W5500 in your ethernet module too. |
Beta Was this translation helpful? Give feedback.
-
Your previous suggests were helpful. I believe the source of my problems was that the heap was dropping too low and causing problems... Since freeing up memory everything has been running great for over a week on WiFi... Thanks.
This isn't necessarily a bug, but I would like to know if there are limitations using Ethernet that you are aware of so I am not chasing problems I simply can't fix...
Then next stage for me is to move from Wifi to wired Ethernet, however I am having problems. I don't know if
With Wifi I get no Token error and everything works great.
I expected a relatively simple replacement of Wifi with Ethernet... I would like your advice/opinion if there is a something I should know about.
I am using a Adafruit Ethernet Feather, which gets an ipaddress, http get's which does confirm connection to the Adafruit website, but seems to disconnect and not make a proper connection to Firebase RTDB?
The entire code in my program is large, but I have tried to include the relevant stuff... Your advice and help is much appreciated!
Serial Ouput:
2022-08-31 16:44:23 --> INITALIZE ETHERNET...
2022-08-31 16:44:24 --> DHCP assigned ethernet_ip_address:
2022-08-31 16:44:24 --> 192.168.86.15
2022-08-31 16:44:24 --> ---------
2022-08-31 16:44:24 --> Ethernet ip: 192.168.86.15
2022-08-31 16:44:24 --> WIFI ip:0.0.0.0
2022-08-31 16:44:24 --> Token info: type = id token, status = on request
2022-08-31 16:44:24 --> Token info: type = id token, status = error
2022-08-31 16:44:24 --> Token error: code: -4, message: connection lost
2022-08-31 16:44:24 --> USING FIREBASE CALLBACK FUNCTION
2022-08-31 16:44:24 --> stream begin error, connection lost
2022-08-31 16:44:24 -->
2022-08-31 16:44:24 --> Firebase Setup Complete!
2022-08-31 16:44:24 --> Use Firebase Callback: True!
2022-08-31 16:44:24 --> Free Heap Space: 275092
2022-08-31 16:44:27 --> BOOT TIME: 3 seconds
2022-08-31 16:44:27 --> Set data with timestamp... connection lost
2022-08-31 16:44:27 --> Setup Complete...
Beta Was this translation helpful? Give feedback.
All reactions