Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Serial data gets stucked sometimes when using Firebase #324

Closed
Sv4nstaygeR opened this issue Mar 22, 2018 · 1 comment
Closed

Serial data gets stucked sometimes when using Firebase #324

Sv4nstaygeR opened this issue Mar 22, 2018 · 1 comment
Labels

Comments

@Sv4nstaygeR
Copy link

Sv4nstaygeR commented Mar 22, 2018

Hi guys, my first issue here, here's my context.

Im sending data from an Arduino Mega to NodeMCU through Serial port which arrives in the correct way. The problem comes when i try to send that info that im receiving to Firebase, which in some cases the serial read gets stucked and read the same byte again. The conection to with Firebase is working fine.

This passes randomly every 10 - 15 seconds (not exact the same time per iteration). Here's the code:

#include <FirebaseArduino.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

// Datos del modulo
String ID = "X";

// Datos de la conexion
char ssid[] = "X";   // Nombre (SSID)
char pass[] = "X";         // Contraseña

// Datos Firebase
#define firebaseURL "X"  // BASE DE DATOS FIREBASE
#define authCode "X"  // SECRETO FIREBASE

// Variables Firebase
int testInt = 0;
bool sendFire = false;

// Variables globales
SoftwareSerial MegaSerial (4, 5);
String RxBuffer;             // Resultado del comando enviado al sensor  “=result [name1=arg1]... \r\n”

void setup() {
  Serial.begin(9600);
  MegaSerial.begin(9600);
  delay(100);

  // Desconectamos cualquier conexion anterior
  WiFi.disconnect();

  // Inicializamos el WiFi
  WiFi.begin(ssid, pass);

  // Esperamos a que el NodeMCU se conecte correctamente a la red
  Serial.print("\nConectando a red wifi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("\nConexión establecida");

  // Una vez conectados iniciamos Firebase
  Firebase.begin(firebaseURL, authCode);

  delay(50);
  sendDataFirebase();
  delay(1000);

}

void loop() {

  // Actualizamos las variables desde Firebase

  while (MegaSerial.available() > 0) {
    testInt = MegaSerial.read();
    sendFire = true;
  }

  if (MegaSerial.available() <= 0) {
    if (sendFire) {
      sendDataFirebase();
      Serial.println(testInt);
      sendFire = false;
    }
  }

void sendDataFirebase() {
  Firebase.setInt(ID + "/testInt", testInt);
}

}

I have checked that if i delete sendDataFirebase in the if statement the serial read works fine.
Can anybody help me?

@proppy
Copy link
Contributor

proppy commented Jun 15, 2018

Sorry for the late reply.

Do you try to write back the data to MegaSerial?

We should have a better example that show how to do connect with an external chip, tracking this here:
#340

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants