<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Core 2 connecting with W5500 LAN to Firebase RTDB]]></title><description><![CDATA[<p dir="auto">I have a Core 2 with W5500 LAN module. For 10 days I have been trying in vain to connect to Firebase RTDB.</p>
<p dir="auto">With WLAN I managed it 5 days ago... but that doesn't work now either! No idea why.</p>
<p dir="auto">Both WIFI and Ethernet I tried the following templates: <a href="https://github.com/mobizt/Firebase-ESP-Client" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/mobizt/Firebase-ESP-Client</a></p>
<p dir="auto">Ethernet and WIFI work in simple tests.</p>
]]></description><link>https://community.m5stack.com/topic/4866/core-2-connecting-with-w5500-lan-to-firebase-rtdb</link><generator>RSS for Node</generator><lastBuildDate>Tue, 05 May 2026 12:33:41 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/4866.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Dec 2022 17:31:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Core 2 connecting with W5500 LAN to Firebase RTDB on Fri, 09 Dec 2022 16:29:30 GMT]]></title><description><![CDATA[<p dir="auto">Thanks to your steep pass it IT finally WORKS !!!</p>
<p dir="auto">Here are a few more stumbling blocks to be aware of:</p>
<ol>
<li>
<p dir="auto">#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.</p>
</li>
<li>
<p dir="auto">you need to define the GPIO´s for Core 2 as following in the code</p>
</li>
<li>
<p dir="auto">trust_anchors URL =&gt; <a href="http://www.google.com" target="_blank" rel="noopener noreferrer nofollow ugc">www.google.com</a> seems to work as Firebase is a google product</p>
</li>
<li>
<p dir="auto">#include &lt;M5Core2.h&gt; is NOT necessary =&gt; if you use it with M5.begin you need to delete Serial.begin(115200) =&gt; otherwise your CPU will crash =&gt; known issue also thanks to felmue</p>
</li>
<li>
<p dir="auto">NTP server is not working =&gt; always returns 0 =&gt; seems to work without NTP</p>
</li>
</ol>
<p dir="auto">Here is the working code i use:</p>
<p dir="auto">/**</p>
<ul>
<li>Created by K. Suwatchai (Mobizt)</li>
<li></li>
<li>Email: <a href="mailto:k_suwatchai@hotmail.com" target="_blank" rel="noopener noreferrer nofollow ugc">k_suwatchai@hotmail.com</a></li>
<li></li>
<li>Github: <a href="https://github.com/mobizt/Firebase-ESP-Client" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/mobizt/Firebase-ESP-Client</a></li>
<li></li>
<li>Copyright (c) 2022 mobizt</li>
<li></li>
</ul>
<p dir="auto">*/</p>
<p dir="auto">/** This example shows the basic RTDB usage with external Client.</p>
<ul>
<li>This example used your Arduino device and WIZnet W5500 (Ethernet) device which SSLClient <a href="https://github.com/OPEnSLab-OSU/SSLClient" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/OPEnSLab-OSU/SSLClient</a></li>
<li>will be used as the external Client.</li>
<li></li>
<li>This SSLClient, <a href="https://github.com/OPEnSLab-OSU/SSLClient" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/OPEnSLab-OSU/SSLClient</a> can't use in ESP8266 device due to wdt reset error.</li>
<li></li>
<li>Don't gorget to define this in FirebaseFS.h</li>
<li>#define FB_ENABLE_EXTERNAL_CLIENT<br />
*/</li>
</ul>
<p dir="auto">#include &lt;Firebase_ESP_Client.h&gt;</p>
<p dir="auto">// Provide the token generation process info.<br />
#include &lt;addons/TokenHelper.h&gt;</p>
<p dir="auto">// Provide the RTDB payload printing info and other helper functions.<br />
#include &lt;addons/RTDBHelper.h&gt;</p>
<p dir="auto">#include &lt;Ethernet.h&gt;</p>
<p dir="auto">/* 1. Install SSLClient library */<br />
// <a href="https://github.com/OPEnSLab-OSU/SSLClient" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/OPEnSLab-OSU/SSLClient</a><br />
#include &lt;SSLClient.h&gt;</p>
<p dir="auto">/* 2. Create Trus anchors for the server i.e. <a href="http://www.google.com" target="_blank" rel="noopener noreferrer nofollow ugc">www.google.com</a> */<br />
// <a href="https://github.com/OPEnSLab-OSU/SSLClient/blob/master/TrustAnchors.md" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/OPEnSLab-OSU/SSLClient/blob/master/TrustAnchors.md</a><br />
// or generate using this site <a href="https://openslab-osu.github.io/bearssl-certificate-utility/" target="_blank" rel="noopener noreferrer nofollow ugc">https://openslab-osu.github.io/bearssl-certificate-utility/</a><br />
#include "trust_anchors.h"</p>
<p dir="auto">// For NTP time client<br />
#include "MB_NTP.h"</p>
<p dir="auto">// For the following credentials, see examples/Authentications/SignInAsUser/EmailPassword/EmailPassword.ino</p>
<p dir="auto">/* 3. Define the API Key */<br />
#define API_KEY "Key"</p>
<p dir="auto">/* 4. Define the RTDB URL */<br />
#define DATABASE_URL "URL"  //&lt;databaseName&gt;.firebaseio.com or &lt;databaseName&gt;.&lt;region&gt;.firebasedatabase.app</p>
<p dir="auto">/* 5. Define the user Email and password that alreadey registerd or added in your project */<br />
#define USER_EMAIL "Email"<br />
#define USER_PASSWORD "password"</p>
<p dir="auto">/* 6. Defined the Ethernet module connection */<br />
#define WIZNET_RESET_PIN 19  // Connect W5500 Reset pin to GPIO 19 for Core 2<br />
#define WIZNET_CS_PIN 26     // Connect W5500 CS pin to GPIO 26 for Core 2<br />
#define WIZNET_MISO_PIN 38   // Connect W5500 MISO pin to GPIO 38 for Core 2<br />
#define WIZNET_MOSI_PIN 23   // Connect W5500 MOSI pin to GPIO 23 for Core 2<br />
#define WIZNET_SCLK_PIN 18   // Connect W5500 SCLK pin to GPIO 18 for Core 2</p>
<p dir="auto">/* 7. Define the analog GPIO pin to pull random bytes from, used in seeding the RNG for SSLClient */<br />
const int analog_pin = 27;  // Core 2 =&gt; GPIO 27 (Analog pin)</p>
<p dir="auto">/* 8. Define MAC */<br />
uint8_t mac[] = { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 };</p>
<p dir="auto">/* 9. Define IP (Optional) */<br />
IPAddress ip(192, 168, 1, 50);<br />
IPAddress myDns(8, 8, 8, 8);</p>
<p dir="auto">// Define Firebase Data object<br />
FirebaseData fbdo;</p>
<p dir="auto">FirebaseAuth auth;<br />
FirebaseConfig config;</p>
<p dir="auto">unsigned long sendDataPrevMillis = 0;</p>
<p dir="auto">int count = 0;</p>
<p dir="auto">volatile bool dataChanged = false;</p>
<p dir="auto">EthernetClient basic_client;</p>
<p dir="auto">SSLClient ssl_client(basic_client, TAs, (size_t)TAs_NUM, analog_pin);</p>
<p dir="auto">// For NTP client<br />
EthernetUDP udpClient;</p>
<p dir="auto">MB_NTP ntpClient(&amp;udpClient, "<a href="http://pool.ntp.org" target="_blank" rel="noopener noreferrer nofollow ugc">pool.ntp.org</a>" /* NTP host <em>/, 123 /</em> NTP port <em>/, 0 /</em> timezone offset in seconds */);</p>
<p dir="auto">uint32_t timestamp = 0;</p>
<p dir="auto">void ResetEthernet() {<br />
Serial.println("Resetting WIZnet W5500 Ethernet Board...  ");<br />
pinMode(WIZNET_RESET_PIN, OUTPUT);<br />
digitalWrite(WIZNET_RESET_PIN, HIGH);<br />
delay(200);<br />
digitalWrite(WIZNET_RESET_PIN, LOW);<br />
delay(50);<br />
digitalWrite(WIZNET_RESET_PIN, HIGH);<br />
delay(200);<br />
}</p>
<p dir="auto">void networkConnection() {</p>
<p dir="auto">Ethernet.init(WIZNET_CS_PIN);</p>
<p dir="auto">ResetEthernet();</p>
<p dir="auto">Serial.println("Starting Ethernet connection...");</p>
<p dir="auto">Ethernet.begin(mac);</p>
<p dir="auto">unsigned long to = millis();</p>
<p dir="auto">while (Ethernet.linkStatus() == LinkOFF || millis() - to &lt; 2000) {<br />
delay(100);<br />
}</p>
<p dir="auto">if (Ethernet.linkStatus() == LinkON) {<br />
Serial.print("Connected with IP ");<br />
Serial.println(Ethernet.localIP());<br />
} else {<br />
Serial.println("Can't connect");<br />
}<br />
}</p>
<p dir="auto">// Define the callback function to handle server status acknowledgement<br />
void networkStatusRequestCallback() {<br />
// Set the network status</p>
<p dir="auto">fbdo.setNetworkStatus(Ethernet.linkStatus() == LinkON);<br />
}</p>
<p dir="auto">// Define the callback function to handle server connection<br />
void tcpConnectionRequestCallback(const char *host, int port) {</p>
<p dir="auto">// You may need to set the system timestamp to use for<br />
// auth token expiration checking.</p>
<p dir="auto">if (timestamp == 0) {<br />
timestamp = ntpClient.getTime(2000 /* wait 2000 ms */);<br />
Serial.print("timestamp from NTP: ");<br />
Serial.println(timestamp);</p>
<pre><code>if (timestamp &gt; 0) { 
  Firebase.setSystemTime(timestamp);
  Serial.print("Firebase =&gt; setSystemTime done");
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Serial.print("Connecting to server via external Client... ");<br />
if (!ssl_client.connect(host, port)) {<br />
Serial.println("failed.");<br />
return;<br />
}<br />
Serial.println("success.");<br />
}</p>
<p dir="auto">void setup() {</p>
<p dir="auto">SPI.begin(WIZNET_SCLK_PIN, WIZNET_MISO_PIN, WIZNET_MOSI_PIN, -1);<br />
Serial.begin(115200);</p>
<p dir="auto">networkConnection();</p>
<p dir="auto">Serial_Printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);</p>
<p dir="auto">/* Assign the api key (required) */<br />
config.api_key = API_KEY;</p>
<p dir="auto">/* Assign the user sign in credentials */<br />
auth.user.email = USER_EMAIL;<br />
auth.user.password = USER_PASSWORD;</p>
<p dir="auto">/* Assign the RTDB URL (required) */<br />
config.database_url = DATABASE_URL;</p>
<p dir="auto">/* Assign the callback function for the long running token generation task */<br />
config.token_status_callback = tokenStatusCallback;  // see addons/TokenHelper.h</p>
<p dir="auto">/* fbdo.setExternalClient and fbdo.setExternalClientCallbacks must be called before Firebase.begin */</p>
<p dir="auto">/* Assign the pointer to global defined external SSL Client object */<br />
fbdo.setExternalClient(&amp;ssl_client);</p>
<p dir="auto">/* Assign the required callback functions */<br />
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback, networkConnection, networkStatusRequestCallback);</p>
<p dir="auto">Firebase.setDoubleDigits(5);</p>
<p dir="auto">Firebase.begin(&amp;config, &amp;auth);<br />
}</p>
<p dir="auto">void loop() {</p>
<p dir="auto">// Firebase.ready() should be called repeatedly to handle authentication tasks.</p>
<p dir="auto">if (Firebase.ready() &amp;&amp; (millis() - sendDataPrevMillis &gt; 15000 || sendDataPrevMillis == 0)) {<br />
sendDataPrevMillis = millis();</p>
<pre><code>Serial_Printf("Set bool... %s\n", Firebase.RTDB.setBool(&amp;fbdo, F("/test/bool"), count % 2 == 0) ? "ok" : fbdo.errorReason().c_str());

count++;
</code></pre>
<p dir="auto">}<br />
}</p>
]]></description><link>https://community.m5stack.com/post/19495</link><guid isPermaLink="true">https://community.m5stack.com/post/19495</guid><dc:creator><![CDATA[gzahh]]></dc:creator><pubDate>Fri, 09 Dec 2022 16:29:30 GMT</pubDate></item><item><title><![CDATA[Reply to Core 2 connecting with W5500 LAN to Firebase RTDB on Thu, 08 Dec 2022 17:31:43 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/gzahh" aria-label="Profile: gzahh">@<bdi>gzahh</bdi></a></p>
<p dir="auto">this Ethernet <a href="https://github.com/mobizt/Firebase-ESP-Client/tree/main/examples/ExternalClient/RTDB/Ethernet/Others/Basic" target="_blank" rel="noopener noreferrer nofollow ugc">example</a> works for me. It uses an external library for the SSL connection instead of the built in SSL client.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/19483</link><guid isPermaLink="true">https://community.m5stack.com/post/19483</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Thu, 08 Dec 2022 17:31:43 GMT</pubDate></item><item><title><![CDATA[Reply to Core 2 connecting with W5500 LAN to Firebase RTDB on Wed, 07 Dec 2022 22:59:53 GMT]]></title><description><![CDATA[<p dir="auto">I have downloaded again the above code for a WLAN connection. It did not work!<br />
The following error message appeared:<br />
Token info: type = id token (GITKit token), status = on request<br />
Token info: type = id token (GITKit token), status = error<br />
Token error: code: -105, message: Client is not yet initialized</p>
<p dir="auto">After that i downgraded the library "Firebase Arduino Client Library for ESP8266 and ESP32" to 2.3.7 and after that i reinstalled 4.2.7 and it worked again. Why do i need to reinstall the lib to get it working?</p>
]]></description><link>https://community.m5stack.com/post/19473</link><guid isPermaLink="true">https://community.m5stack.com/post/19473</guid><dc:creator><![CDATA[gzahh]]></dc:creator><pubDate>Wed, 07 Dec 2022 22:59:53 GMT</pubDate></item><item><title><![CDATA[Reply to Core 2 connecting with W5500 LAN to Firebase RTDB on Wed, 07 Dec 2022 22:18:21 GMT]]></title><description><![CDATA[<p dir="auto">Ethernet still not working. I used the following code:</p>
<p dir="auto">/**</p>
<ul>
<li>Created by K. Suwatchai (Mobizt)</li>
<li></li>
<li>Email: <a href="mailto:k_suwatchai@hotmail.com" target="_blank" rel="noopener noreferrer nofollow ugc">k_suwatchai@hotmail.com</a></li>
<li></li>
<li>Github: <a href="https://github.com/mobizt/Firebase-ESP-Client" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/mobizt/Firebase-ESP-Client</a></li>
<li></li>
<li>Copyright (c) 2022 mobizt</li>
<li></li>
</ul>
<p dir="auto">*/</p>
<p dir="auto">/** This example shows the basic RTDB usage with external Client.</p>
<ul>
<li>This example used ESP32 and WIZnet W5500 (Etherner) devices which built-in SSL Client will be used as the external Client.</li>
<li></li>
<li>For other non-espressif (ESP32 and ESP8266) devices, this SSL Client library can be used</li>
<li><a href="https://github.com/OPEnSLab-OSU/SSLClient" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/OPEnSLab-OSU/SSLClient</a></li>
<li></li>
<li>Don't gorget to define this in FirebaseFS.h</li>
<li>#define FB_ENABLE_EXTERNAL_CLIENT<br />
*/</li>
</ul>
<p dir="auto">#include &lt;WiFi.h&gt;<br />
#include &lt;M5Core2.h&gt;<br />
#include &lt;Firebase_ESP_Client.h&gt;<br />
#include "time.h"<br />
#include &lt;ESP32Time.h&gt;</p>
<p dir="auto">//ESP32Time rtc;<br />
ESP32Time rtc(3600);  // offset in seconds GMT+1</p>
<p dir="auto">// Provide the token generation process info.<br />
#include &lt;addons/TokenHelper.h&gt;</p>
<p dir="auto">// Provide the RTDB payload printing info and other helper functions.<br />
#include &lt;addons/RTDBHelper.h&gt;</p>
<p dir="auto">//<a href="https://github.com/arduino-libraries/Ethernet" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/arduino-libraries/Ethernet</a><br />
#include &lt;Ethernet.h&gt;</p>
<p dir="auto">// Include built-in SSL Client which supports other network interfaces<br />
#include "sslclient/esp32/MB_ESP32_SSLClient.h"</p>
<p dir="auto">// You can use MB_ESP32_SSLClient.h in your ESP32 project in the same way as normal WiFiClientSecure</p>
<p dir="auto">// For NTP time client<br />
#include "MB_NTP.h"</p>
<p dir="auto">// For the following credentials, see examples/Authentications/SignInAsUser/EmailPassword/EmailPassword.ino</p>
<p dir="auto">/* 1. Define the API Key */<br />
#define API_KEY "KEY"</p>
<p dir="auto">/* 2. Define the RTDB URL */<br />
#define DATABASE_URL "URL"  //&lt;databaseName&gt;.firebaseio.com or &lt;databaseName&gt;.&lt;region&gt;.firebasedatabase.app</p>
<p dir="auto">/* 3. Define the user Email and password that alreadey registerd or added in your project */<br />
#define USER_EMAIL "EMAIL"<br />
#define USER_PASSWORD "PASSWORD"</p>
<p dir="auto">/* 4. Defined the Ethernet module connection */<br />
//#define WIZNET_RESET_PIN 26   // Connect W5500 Reset pin to GPIO 26 of ESP32<br />
#define WIZNET_CS_PIN 26        // Connect W5500 CS pin to GPIO 5 of ESP32<br />
#define WIZNET_MISO_PIN 38      // Connect W5500 MISO pin to GPIO 19 of ESP32<br />
#define WIZNET_MOSI_PIN 23      // Connect W5500 MOSI pin to GPIO 23 of ESP32<br />
#define WIZNET_SCLK_PIN 18      // Connect W5500 SCLK pin to GPIO 18 of ESP32</p>
<p dir="auto">//WLAN<br />
const char* ssid = "ssid";<br />
const char* password = "password";</p>
<p dir="auto">/* 5. Define MAC */<br />
uint8_t MAC[] = { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 };</p>
<p dir="auto">/* 6. Define IP (Optional) */<br />
IPAddress IP(192, 168, 1, 233);<br />
IPAddress DNS(8, 8, 8, 8);</p>
<p dir="auto">// Define Firebase Data object<br />
FirebaseData fbdo;</p>
<p dir="auto">FirebaseAuth auth;<br />
FirebaseConfig config;</p>
<p dir="auto">unsigned long sendDataPrevMillis = 0;</p>
<p dir="auto">int count = 0;</p>
<p dir="auto">volatile bool dataChanged = false;</p>
<p dir="auto">EthernetClient basic_client;<br />
MB_ESP32_SSLClient ssl_client;</p>
<p dir="auto">// For NTP client<br />
EthernetUDP udpClient;</p>
<p dir="auto">MB_NTP ntpClient(&amp;udpClient, "<a href="http://ch.pool.ntp.org" target="_blank" rel="noopener noreferrer nofollow ugc">ch.pool.ntp.org</a>" /* NTP host <em>/, 123 /</em> NTP port <em>/, 0 /</em> timezone offset in seconds */);</p>
<p dir="auto">uint32_t timestamp = 0;</p>
<p dir="auto">const char* ntpServer = "<a href="http://ch.pool.ntp.org" target="_blank" rel="noopener noreferrer nofollow ugc">ch.pool.ntp.org</a>";<br />
const long gmtOffset_sec = 3600;<br />
const int daylightOffset_sec = 3600;<br />
int second;<br />
int minute;<br />
int hour;<br />
int day;<br />
int month;<br />
int year;<br />
struct tm timeinfo;</p>
<p dir="auto">void printLocalTime() {<br />
if (!getLocalTime(&amp;timeinfo)) {<br />
Serial.println("Failed to obtain time");<br />
M5.Lcd.print("Failed to obtain time");<br />
return;<br />
}<br />
second = timeinfo.tm_sec;<br />
minute = timeinfo.tm_min;<br />
hour = timeinfo.tm_hour;<br />
day = timeinfo.tm_mday;<br />
month = timeinfo.tm_mon + 1;<br />
year = timeinfo.tm_year + 1900;<br />
weekday = timeinfo.tm_wday + 1;<br />
rtc.setTime(second, minute, hour, day, month, year);<br />
}</p>
<p dir="auto">void wifiNtpSetup() {<br />
M5.Lcd.setTextSize(2);  //Set the font size to 2.  设置字号大小为2<br />
M5.Lcd.printf("\nConnecting to %s", ssid);<br />
WiFi.begin(<br />
ssid,<br />
password);                             //Connect wifi and return connection status.  连接wifi并返回连接状态<br />
while (WiFi.status() != WL_CONNECTED) {  //If the wifi connection fails.  若wifi未连接成功<br />
delay(500);                            //delay 0.5s.  延迟0.5s<br />
M5.Lcd.print(".");<br />
}<br />
M5.Lcd.println("\nCONNECTED!");<br />
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);  //init and get the time.  初始化并设置NTP<br />
printLocalTime();</p>
<p dir="auto">if (timestamp == 0) {<br />
timestamp = ntpClient.getTime(2000 /* wait 2000 ms */);</p>
<pre><code>if (timestamp &gt; 0) {
  Serial.print("timestamp:");
  Serial.print(timestamp);
} else {
  Serial.println("NTP Server via Ethernet nicht erreichbar !");
}
</code></pre>
<p dir="auto">}<br />
WiFi.disconnect(true);  //Disconnect wifi.  断开wifi连接<br />
WiFi.mode(WIFI_OFF);    //Set the wifi mode to off.  设置wifi模式为关闭<br />
delay(20);<br />
M5.Lcd.println("\nWIFI OFF!");<br />
}</p>
<p dir="auto">/*<br />
void ResetEthernet()<br />
{<br />
Serial.println("Resetting WIZnet W5500 Ethernet Board...  ");<br />
pinMode(WIZNET_RESET_PIN, OUTPUT);<br />
digitalWrite(WIZNET_RESET_PIN, HIGH);<br />
delay(200);<br />
digitalWrite(WIZNET_RESET_PIN, LOW);<br />
delay(50);<br />
digitalWrite(WIZNET_RESET_PIN, HIGH);<br />
delay(200);<br />
}<br />
*/</p>
<p dir="auto">void networkConnection() {</p>
<p dir="auto">SPI.begin(WIZNET_SCLK_PIN, WIZNET_MISO_PIN, WIZNET_MOSI_PIN, -1);</p>
<p dir="auto">Ethernet.init(WIZNET_CS_PIN);<br />
<a href="//Serial.begin" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.begin</a>(115200);</p>
<p dir="auto">//ResetEthernet();</p>
<p dir="auto">Serial.println("Starting Ethernet connection...");<br />
Ethernet.begin(MAC, IP, DNS);</p>
<p dir="auto">unsigned long to = millis();</p>
<p dir="auto">while (Ethernet.linkStatus() == LinkOFF || millis() - to &lt; 2000) {<br />
delay(100);<br />
}</p>
<p dir="auto">if (Ethernet.linkStatus() == LinkON) {<br />
Serial.print("Connected with IP ");<br />
Serial.println(Ethernet.localIP());<br />
} else {<br />
Serial.println("Can't connect");<br />
}<br />
}</p>
<p dir="auto">// Define the callback function to handle server status acknowledgement<br />
void networkStatusRequestCallback() {</p>
<p dir="auto">// Set the network status<br />
fbdo.setNetworkStatus(Ethernet.linkStatus() == LinkON);<br />
}</p>
<p dir="auto">// Define the callback function to handle server connection<br />
void tcpConnectionRequestCallback(const char* host, int port) {</p>
<p dir="auto">// You may need to set the system timestamp to use for<br />
// auth token expiration checking.<br />
Firebase.setSystemTime(rtc.getLocalEpoch());</p>
<p dir="auto">Serial.print("Connecting to server via external Client... ");<br />
if (!ssl_client.connect(host, port)) {<br />
Serial.println("Connection failed !");<br />
return;<br />
}<br />
Serial.println("Connection established !");<br />
}</p>
<p dir="auto">void setup() {</p>
<p dir="auto">M5.begin();<br />
wifiNtpSetup();<br />
networkConnection();</p>
<p dir="auto">Serial_Printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);</p>
<p dir="auto">/* Assign the basic Client (Ethernet) pointer to the basic Client */<br />
ssl_client.setClient(&amp;basic_client);</p>
<p dir="auto">/* Similar to WiFiClientSecure */<br />
ssl_client.setInsecure();</p>
<p dir="auto">config.cert.file = "/gtsr1.pem";<br />
config.cert.file_storage = mem_storage_type_flash;</p>
<p dir="auto">/* Assign the api key (required) */<br />
config.api_key = API_KEY;</p>
<p dir="auto">/* Assign the user sign in credentials */<br />
auth.user.email = USER_EMAIL;<br />
auth.user.password = USER_PASSWORD;</p>
<p dir="auto">/* Assign the RTDB URL (required) */<br />
config.database_url = DATABASE_URL;</p>
<p dir="auto">/* Assign the callback function for the long running token generation task */<br />
config.token_status_callback = tokenStatusCallback;  // see addons/TokenHelper.h</p>
<p dir="auto">/* fbdo.setExternalClient and fbdo.setExternalClientCallbacks must be called before Firebase.begin */</p>
<p dir="auto">/* Assign the pointer to global defined external SSL Client object */<br />
fbdo.setExternalClient(&amp;ssl_client);</p>
<p dir="auto">/* Assign the required callback functions */<br />
fbdo.setExternalClientCallbacks(tcpConnectionRequestCallback, networkConnection, networkStatusRequestCallback);</p>
<p dir="auto">Firebase.setDoubleDigits(5);</p>
<p dir="auto">Firebase.begin(&amp;config, &amp;auth);</p>
<p dir="auto">// Comment or pass false value when WiFi reconnection will control by your code or third party library<br />
<a href="//Firebase.reconnectWiFi" target="_blank" rel="noopener noreferrer nofollow ugc">//Firebase.reconnectWiFi</a>(true);<br />
}</p>
<p dir="auto">void loop() {</p>
<p dir="auto">// Firebase.ready() should be called repeatedly to handle authentication tasks.</p>
<p dir="auto">if (Firebase.ready() &amp;&amp; (millis() - sendDataPrevMillis &gt; 15000 || sendDataPrevMillis == 0)) {<br />
sendDataPrevMillis = millis();</p>
<pre><code>Serial_Printf("Set bool... %s\n", Firebase.RTDB.setBool(&amp;fbdo, F("/test/bool"), count % 2 == 0) ? "ok" : fbdo.errorReason().c_str());

count++;
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">Excerpt from Serial Monitor:<br />
"<br />
Token info: type = id token (GITKit token), status = on request<br />
[V][ESP32_SSL_Client.cpp:402] stop_tcp_connection(): Cleaning SSL connection.<br />
Connecting to server via external Client... [V][ESP32_SSL_Client.cpp:173] connect_ssl(): Seeding the random number generator<br />
[V][ESP32_SSL_Client.cpp:185] connect_ssl(): Setting up the SSL/TLS structure...<br />
[I][ESP32_SSL_Client.cpp:201] connect_ssl(): WARNING: Skipping SSL Verification. INSECURE!<br />
[V][ESP32_SSL_Client.cpp:313] connect_ssl(): Setting hostname for TLS session...<br />
[V][ESP32_SSL_Client.cpp:334] connect_ssl(): Performing the SSL/TLS handshake...<br />
[E][ESP32_SSL_Client.cpp:61] _esp32_ssl_handle_error(): [connect_ssl():341]: (-1) UNKNOWN ERROR CODE (0001)<br />
[E][MB_ESP32_SSLClient.cpp:217] connect(): MB_ESP32_SSLClient Error: upgrade connection, -1<br />
[V][ESP32_SSL_Client.cpp:402] stop_tcp_connection(): Cleaning SSL connection.<br />
Connection failed !<br />
"</p>
<p dir="auto">This error indicates that there was an issue with the SSL/TLS handshake when trying to connect to an external server. The exact cause of this error is unknown, but it could be due to an incorrect SSL configuration, an expired/invalid certificate, or an issue with the network connection.<br />
The NTP server is also not accessible via Ethernet. Therefore I connected the NTP with WLAN and synchronized timestamp with Firebase. The SSL/TLS connection still failed. I am running out of ideas.</p>
]]></description><link>https://community.m5stack.com/post/19472</link><guid isPermaLink="true">https://community.m5stack.com/post/19472</guid><dc:creator><![CDATA[gzahh]]></dc:creator><pubDate>Wed, 07 Dec 2022 22:18:21 GMT</pubDate></item><item><title><![CDATA[Reply to Core 2 connecting with W5500 LAN to Firebase RTDB on Wed, 07 Dec 2022 22:51:08 GMT]]></title><description><![CDATA[<p dir="auto">WIFI works now again.. Firebase.reconnectWiFi(true); must be called AFTER Firebase.begin(&amp;config, &amp;auth);. With me this was somehow suddenly no longer so... probably because of a copy/paste error..`</p>
<p dir="auto">so here my working WIFI code:</p>
<p dir="auto">/**</p>
<ul>
<li>Created by K. Suwatchai (Mobizt)</li>
<li></li>
<li>Email: <a href="mailto:k_suwatchai@hotmail.com" target="_blank" rel="noopener noreferrer nofollow ugc">k_suwatchai@hotmail.com</a></li>
<li></li>
<li>Github: <a href="https://github.com/mobizt/Firebase-ESP-Client" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/mobizt/Firebase-ESP-Client</a></li>
<li></li>
<li>Copyright (c) 2022 mobizt</li>
<li></li>
</ul>
<p dir="auto">*/</p>
<p dir="auto">/** This example will show how to authenticate as a user with Email and password.<br />
*</p>
<ul>
<li>You need to enable Email/Password provider.</li>
<li>In Firebase console, select Authentication, select Sign-in method tab,</li>
<li>under the Sign-in providers list, enable Email/Password provider.</li>
<li></li>
<li>From this example, the user will be granted to access the specific location that matches</li>
<li>the user uid.</li>
<li></li>
<li>This example will modify the database rules to set up the security rule which need to</li>
<li>guard the unauthorized access with the user Email.<br />
*/</li>
</ul>
<p dir="auto">#include &lt;M5Core2.h&gt;<br />
#include &lt;WiFi.h&gt;<br />
#include &lt;Firebase_ESP_Client.h&gt;</p>
<p dir="auto">// Provide the token generation process info.<br />
#include &lt;addons/TokenHelper.h&gt;</p>
<p dir="auto">// Provide the RTDB payload printing info and other helper functions.<br />
#include &lt;addons/RTDBHelper.h&gt;</p>
<p dir="auto">/* 1. Define the WiFi credentials */<br />
#define WIFI_SSID "WIFI_SSID"<br />
#define WIFI_PASSWORD "WIFI_PASSWORD"</p>
<p dir="auto">/** 2. Define the API key<br />
*</p>
<ul>
<li>The API key (required) can be obtained since you created the project and set up</li>
<li>the Authentication in Firebase console. Then you will get the API key from</li>
<li>Firebase project Web API key in Project settings, on General tab should show the</li>
<li>Web API Key.</li>
<li></li>
<li>You may need to enable the Identity provider at <a href="https://console.cloud.google.com/customer-identity/providers" target="_blank" rel="noopener noreferrer nofollow ugc">https://console.cloud.google.com/customer-identity/providers</a></li>
<li>Select your project, click at ENABLE IDENTITY PLATFORM button.</li>
<li>The API key also available by click at the link APPLICATION SETUP DETAILS.</li>
<li></li>
</ul>
<p dir="auto">*/<br />
#define API_KEY "API_KEY"</p>
<p dir="auto">/* 3. Define the user Email and password that already registerd or added in your project */<br />
#define USER_EMAIL "USER_EMAIL"<br />
#define USER_PASSWORD "USER_PASSWORD"</p>
<p dir="auto">/* 4. If work with RTDB, define the RTDB URL */<br />
#define DATABASE_URL "DATABASE_URL" //&lt;databaseName&gt;.firebaseio.com or &lt;databaseName&gt;.&lt;region&gt;.firebasedatabase.app</p>
<p dir="auto">/** 5. Define the database secret (optional)<br />
*</p>
<ul>
<li>This database secret needed only for this example to modify the database rules</li>
<li></li>
<li>If you edit the database rules yourself, this is not required.<br />
*/<br />
#define DATABASE_SECRET "DATABASE_SECRET"</li>
</ul>
<p dir="auto">/* 6. Define the Firebase Data object */<br />
FirebaseData fbdo;</p>
<p dir="auto">/* 7. Define the FirebaseAuth data for authentication data */<br />
FirebaseAuth auth;</p>
<p dir="auto">/* 8. Define the FirebaseConfig data for config data */<br />
FirebaseConfig config;</p>
<p dir="auto">unsigned long dataMillis = 0;<br />
int count = 0;</p>
<p dir="auto">void setup()<br />
{<br />
<a href="//M5.begin" target="_blank" rel="noopener noreferrer nofollow ugc">//M5.begin</a>();<br />
Serial.begin(115200);</p>
<pre><code>WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
    Serial.print(".");
    delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

//config.signer.test_mode = true;
/* 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 */
config.database_url = DATABASE_URL;

/* In case the certificate data was used  */
//config.cert.data = rootCACert;

// Or custom set the root certificate for each FirebaseData object
//fbdo.setCert(rootCACert);

/* Or assign the certificate file */

/** From the test as of July 2021, GlobalSign Root CA was missing from Google server
* as described above, GTS Root R1 (gsr1.pem or gsr1.der) can be used instead.
* ESP32 Arduino SDK supports PEM format only even mBedTLS supports DER format too.
* ESP8266 SDK supports both PEM and DER format certificates.
*/
//config.cert.file = "/gtsr1.pem";
//config.cert.file_storage = mem_storage_type_flash; // or mem_storage_type_sd


fbdo.setResponseSize(4096);

String base_path = "/UsersData/";

/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h

/* Initialize the library with the Firebase authen and config */
Firebase.begin(&amp;config, &amp;auth);

Firebase.reconnectWiFi(true);

/** Now modify the database rules (if not yet modified)
 *
 * The user, &lt;user uid&gt; in this case will be granted to read and write
 * at the certain location i.e. "/UsersData/&lt;user uid&gt;".
 *
 * If you database rules has been modified, please comment this code out.
 *
 * The character $ is to make a wildcard variable (can be any name) represents any node key
 * which located at some level in the rule structure and use as reference variable
 * in .read, .write and .validate rules
 *
 * For this case $userId represents any &lt;user uid&gt; node that places under UsersData node i.e.
 * /UsersData/&lt;user uid&gt; which &lt;user uid&gt; is user UID.
 *
 * Please check your the database rules to see the changes after run the below code.
 */
String var = "$userId";
String val = "($userId === auth.uid)";
Firebase.RTDB.setReadWriteRules(&amp;fbdo, base_path, var, val, val, DATABASE_SECRET);

/** path for user data is now "/UsersData/&lt;user uid&gt;"
 * 
 * The id token can be accessed from Firebase.getToken().
 * 
 * The refresh token can be accessed from Firebase.getRefreshToken().
 */
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void loop()<br />
{</p>
<pre><code>// Firebase.ready() should be called repeatedly to handle authentication tasks.

if (millis() - dataMillis &gt; 5000 &amp;&amp; Firebase.ready())
{
    dataMillis = millis();
    String path = "/UsersData/";
    path += auth.token.uid.c_str(); //&lt;- user uid of current user that sign in with Emal/Password
    path += "/test/int";
    Serial.printf("Set int... %s\n", Firebase.RTDB.setInt(&amp;fbdo, path, count++) ? "ok" : fbdo.errorReason().c_str());

    // You can use refresh token from Firebase.getRefreshToken() to sign in next time without providing Email and Password.
    // See SignInWithRefreshIDToken example.
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Now i will try again to connect with Ethernet W5500.. i come back later with more infos..</p>
]]></description><link>https://community.m5stack.com/post/19461</link><guid isPermaLink="true">https://community.m5stack.com/post/19461</guid><dc:creator><![CDATA[gzahh]]></dc:creator><pubDate>Wed, 07 Dec 2022 22:51:08 GMT</pubDate></item></channel></rss>