espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.63k stars 7.41k forks source link

Connect Firebase with shield W5500 (lan) #4136

Closed rafaelzuckerberg closed 4 years ago

rafaelzuckerberg commented 4 years ago

I'm using this library Firebase (https://github.com/ioxhop/IOXhop_FirebaseESP32)

// Library Wifi
#include <WiFi.h>

// Library Firebase
#include <IOXhop_FirebaseESP32.h>

// Libraties Ethernet
#include <Ethernet.h>
#include <EthernetUdp.h>

// Libraries Blynk
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <BlynkSimpleEnergiaEthernet.h>

// Credentials of Firebase to connect
#define FIREBASE_HOST "...."   
#define FIREBASE_AUTH "..."

// Credentials to connect Wifi
#define WIFI_SSID "...."               
#define WIFI_PASSWORD "..."

// Connect Local
EthernetUDP Udp;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char ReplyBuffer[] = "acknowledged";
byte mac[] = { 0x70, 0x69, 0x69, 0x2D, 0x30, 0x31 };
unsigned int localPort = 3001;

// LEDs
int ledVermelho = 21;
int ledAzul = 2;

char auth[] = ".....";

void setup() {

    Serial.begin(115200);

     // Initialize Ethernet method
    initializeEthernet();

    //  Initialize Wi-fi method
    //  connectWifi();

    pinMode(ledVermelho, OUTPUT);
    digitalWrite(ledVermelho, 1);
    pinMode(ledAzul, OUTPUT);
    digitalWrite(ledAzul, 1);
}

void loop() {
    runConnectLocal();
}

void connectWifi() {
    // connect to wifi.
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print("connecting");
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }
    Serial.println();
    Serial.print("connected: ");
    Serial.println(WiFi.localIP());
    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

// Methods to initialize ethernet services
void initializeEthernet() {
    Ethernet.init(33);// CS pin 33
    Ethernet.begin(mac);// use DHCP

    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
         Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
        while (true) {
             delay(1); // do nothing, no point running without Ethernet hardware
        }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
          Serial.println("Ethernet cable is not connected.");
    }

    Serial.print("IP: ");
    Serial.println(Ethernet.localIP());

    Udp.begin(localPort);

    // Begin Blynk services
    Blynk.begin(auth);

    // Initialize Firebase Services
   //  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void runConnectLocal() {
    int packetSize = Udp.parsePacket();
    if (packetSize) {
        Serial.println("Passou conexão local " + packetSize);
        Serial.print("Received packet of size ");
        Serial.println(packetSize);
        Serial.print("From ");
        IPAddress remote = Udp.remoteIP();
        for (int i=0; i < 4; i++) {
              Serial.print(remote[i], DEC);
            if (i < 3) {
                Serial.print(".");
            }
       }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.print("Contents: ");
    Serial.println(packetBuffer);

    // send a reply to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
}
delay(10);

// Run Blynk
Blynk.run();

// run power method
//    powerLed();
}

void powerLed() {
     int ledStatus = Firebase.getInt("power");
     Serial.println(ledStatus);
     digitalWrite(ledVermelho, ledStatus);
     digitalWrite(ledAzul, ledStatus); 
}

So, I have this code that I use to connect with Firebase, when I use connection wi-fi method using firebase, its work perfeclty

But, when trying the same firebase library and connection with lan cable with W5500 shield, its no work

more a details, when I use app blynk using connection cabe, its work, if I try use firebase library, show the following message when debug:

/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:1442 (xQueueGenericReceive)- assert failed! abort() was called at PC 0x400880c1 on core 1

GeorgeHumanBot commented 4 years ago

It does not work bro, Ethernet don't have support for this!

stale[bot] commented 4 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.