Giter Club home page Giter Club logo

Comments (64)

mobizt avatar mobizt commented on May 27, 2024 2

OK it works. I think I found the error in your FIREBASE_HOST you wrote "........firebaseio.com/".
Slash behind .com is not valid, it should be "????????.firebaseio.com"

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024 1

This is not the Q&A forum which no one care about your questions and problems.

This is the place where I take my time to support you.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024 1

It's not the library issue.
It's your router and network configuration issue.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024 1

Library does not touch the network stacks, it plays with requests and responses.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Due to WiFi client library in ESP8266 Core SDK version 5.x is different and change from old version.

I need to notify or warn user to include file as state in this document and also in example sketch comment.
FirebaseESP8266.h must be included before ESP8266WiFi.h to let it works under ESP8266 Core SDK version 5.x.

For your case, include these 3 files as following.

#include <FirebaseESP8266.h> //include first
#include <ESP8266WiFi.h> //the second
#include <WiFiManager.h> 

Please let me know if you still get the error.

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

I did what you wrote and I still get the error :(.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

From your code, the format of path parameter you pass to function is not valid. Path must begin with slash (/)
Becase it is a relative path from your root to defined node.

Firebase.getInt(firebaseData, "number");

Should be

Firebase.getInt(firebaseData, "/number");

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

thanks but I still get the same error.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Please explain the error. Connection refuse?

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

I try your code, everything is ok.

#include <FirebaseESP8266.h>
#include <ESP8266WiFi.h>
#include <WiFiManager.h>

#define relayPin 5
#define statusLED 15
#define FIREBASE_HOST "xxxxxxxx.firebaseio.com"
#define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
FirebaseData firebaseData;
int SMID = 123;
void setup()
{
  //digitalWrite(WifiLED, HIGH);
  pinMode(relayPin, OUTPUT);
  pinMode(statusLED, OUTPUT);
  Serial.begin(115200);
  WiFiManager wifiManager;
  wifiManager.autoConnect("SSID", "PSWXXXXXXXXXX");
  digitalWrite(statusLED, HIGH);
  Serial.println("Det virker");

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  //wifiManager.autoConnect("SmartHomie");
}
void loop()
{
  // Check her på MCU'ens respektive path til databasen
  digitalWrite(relayPin, HIGH);
  delay(3000);
  digitalWrite(relayPin, LOW);
  delay(3000);
  int val = 0;
  Serial.println(Firebase.getInt(firebaseData, "/number"));
  if (Firebase.getInt(firebaseData, "/number"))
  {
    //Success, then read the payload value
    Serial.println("DET FUCKINGER VIRKER!!");
  }
  else
  {
    //Failed, then print out the error detail
    Serial.println("Error: " + firebaseData.errorReason());
  }
}

Please tell me which version of esp8266 Arduino core sdk you installed. This Firebase library supports version 2.4.x and higher.

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

I use 2.5

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

when I try to run the demo program it doesnt work either

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

connection refused

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Thank you for your information.

Connection refused returns directly from esp8266 core SDK which means it cannot establish network connection or cannot connect to internet even your AP is connected.

Try to reset the router, use different router, set soft AP or WiFi hotspot using your computer or mobile phone.

I'm not sure this related to this issue?

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

I already use a mobile hotspot but il try another :)

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Please try to change lwIP variant.
From Arduino IDE, go to menu Tools > lwIP Variant > v2 IPv6 Lower Memory or other options.

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

i havenow tried that, and it dosent work with any of the variants... i also tried switching to other networks and using a new NodeMCU

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

How about try to install Esp8266 Arduino core v 2.4.2?

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

that dosent work either... :(

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

i have been trying to get this to work for days now, i really hope you can help me find a solution

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

I will reply you back within an hour.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Ok, I try to install esp8266 Arduino core back to v 2.5.0 and test with this example
Go to menu File > Examples > ESP8266WiFi > HTTPSRequestAxTLS
And post the serial printed text from it.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

First I need to make sure you install the latest version of Firebase library (v 1.0.3) which updates to work with ESP8266 Arduino Core 2.5.0.

This is how I clean install everything to test the library.

  • Clean install Arduino 1.8.9 by uninstall old version and delete folder \AppData\Local\Arduino15 to delete old sdk.
  • Create new libraries folder.
  • Install ESP8266 Arduino core SDK by provide this url in Settings http://arduino.esp8266.com/stable/package_esp8266com_index.json
  • Install ESP8266 Arduino Core version 2.5.0 from Boards Manager.
  • Install Firebase ESP8266 Arduino library v 1.0.3 from Library Manager.
  • Use your code to test.

Everything works fine.

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

image

This is the log from HTTPSRequestAxTLS

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

..............
WiFi connected.
IP address:
192.168.43.141

Connect to Firebase failed!

from firebase-esp8266.

frederik0312 avatar frederik0312 commented on May 27, 2024

ok now it dosent return a error!

hwhat code should i use to read something from a path at the database

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

What do you mean?

If you want to khow how to use, the examples or read me on the main page will provide complete usages.

For path parameter, you need to add slash at its beginning e.g. "/Room/Node1/Senor1".

For FIREBASE_HOST that pass to Firebase.begin function should be valid in form "xxxx.firebaseio.com", no http:// or https:// or slash at beginning or at the end.

from firebase-esp8266.

lc998 avatar lc998 commented on May 27, 2024

OK it works. I think I found the error in your FIREBASE_HOST you wrote "........firebaseio.com/".
Slash behind .com is not valid, it should be "????????.firebaseio.com"

This was the problem for me :P

from firebase-esp8266.

lc998 avatar lc998 commented on May 27, 2024

What do you mean?

If you want to khow how to use, the examples or read me on the main page will provide complete usages.

For path parameter, you need to add slash at its beginning e.g. "/Room/Node1/Senor1".

For FIREBASE_HOST that pass to Firebase.begin function should be valid in form "xxxx.firebaseio.com", no http:// or https:// or slash at beginning or at the end.

And this was useful!

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

I have the same issue, did as you suggested. still having the connection refused error. I am just setting up a sensor value.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@xpertcrush

Please post your code here.
The issue is too old and the library updates so far.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
  //Set the size of WiFi rx/tx buffers in the case where we want to work with large data.
  firebaseData.setBSSLBufferSize(1024, 1024);

  //Set the size of HTTP response buffers in the case where we want to work with large data.
  firebaseData.setResponseSize(1024);

  //Set database read timeout to 1 minute (max 15 minutes)
  Firebase.setReadTimeout(firebaseData, 1000 * 60);
  //tiny, small, medium, large and unlimited.
  //Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s).
  Firebase.setwriteSizeLimit(firebaseData, "tiny");

 /*
  This option allows get and delete functions (PUT and DELETE HTTP requests) works for device connected behind the
  Firewall that allows only GET and POST requests.
  
  Firebase.enableClassicRequest(firebaseData, true);
  */

  String path = "/";
 
  Serial.println("------------------------------------");
  Serial.println("Set double test...");

    Serial.println ("beginning to send data to firebase");
    //Also can use Firebase.set instead of Firebase.setDouble
    if (Firebase.setString(firebaseData, path + "/roof/level" , WaterLevel().c_str()))
    {
      Serial.println("PASSED");
      Serial.println("PATH: " + firebaseData.dataPath());
      Serial.println("TYPE: " + firebaseData.dataType());
      Serial.println("ETag: " + firebaseData.ETag());
      Serial.print("VALUE: ");
      Serial.println("------------------------------------");
      Serial.println();
    }
    else
    {
      Serial.println("FAILED");
      Serial.println("REASON: " + firebaseData.errorReason());
      Serial.println("------------------------------------");
      Serial.println();
    }

very basic code`

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@xpertcrush

Can't see WiFi connection.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

#include <FirebaseESP8266.h> //include first
#include <ESP8266WiFi.h> //the second
//#include <WiFiManager.h>
#include <ArduinoOTA.h>
#include <hcsr04.h>
#include "FirebaseESP8266.h"

//DECLARE THE CREDENTIALS
#ifndef STASSID
#define STASSID "Virut"
#define STAPSK "Wro23456"
#endif

#define FIREBASE_HOST "AC?????.firebaseio.com"
#define FIREBASE_AUTH "hidden"

//Define FirebaseESP8266 data object
FirebaseData firebaseData;

FirebaseJson json;

bool ota_flag = true;
uint16_t timer_start = 0;
// Time to sleep (in seconds):
const int sleepTimeS = 60;
int analogInput = A0;
float correctionFactor = 0;
float Vout = 0.0;
float Vin = 0.0;
float R1 = 98190;
float R2 = 10150;
int value = 0;

const char* ssid = STASSID;
const char* password = STAPSK;
const char* deviceName = "findmylevel.com";

//ATTACH THE TRIGGER AND ECHO TO PINS
#define TRIG_PIN 5
#define ECHO_PIN 4

//Static IP address configuration
IPAddress staticIP(192, 168, 1, 150); //ESP static ip
IPAddress gateway(192, 168, 1, 1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask
IPAddress dns(8, 8, 8, 8); //DNS

void setup() {

pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.begin(115200);
Serial.println("Booting");
//WIFI MODE SETTINGS
WiFi.disconnect(); //Prevent connecting to wifi based on previous configuration
WiFi.hostname(deviceName); // DHCP Hostname (useful for finding device for static lease)
WiFi.config(staticIP, subnet, gateway, dns);
WiFi.mode(WIFI_STA);

//CONNECTION INITIALIZATION

WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(100);
}

here they are

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@xpertcrush

The problem is your device can't connect to internet.

You need to test the basic WiFi Client or HTTPClient connection to some server e.g. google.com.

The issue is not related to library.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

I see, its connected to router which has connectivity. and dns is set to google. let me check with HTTPSrequest example and report back here.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Ok, that's the way you should do before anything.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

14:02:48.066 -> .
14:02:48.066 -> WiFi connected
14:02:48.066 -> IP address:
14:02:48.066 -> 192.168.1.180
14:02:48.066 -> connecting to api.github.com
14:02:48.492 -> cert FP: 59 74 61 88 13 CA 12 34 15 4D 11 0A C1 7F E6 67 07 69 42 F5
14:02:48.532 -> test FP: 5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76
14:02:48.532 -> certificate doesn't match
14:02:48.532 -> requesting URL: /repos/esp8266/Arduino/commits/master/status
14:02:48.532 -> request sent
14:02:48.836 -> headers received

its fine

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@xpertcrush
May be you provide something wrong with FIREBASE_HOST and FIREBASE_AUTH.
You should check or recreate the new database secret.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

even uncommented Firebase.enableClassicRequest(firebaseData, true);

still same error, let me try new database secret and see what happens

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

is it related to new feature of firebase?

Firebase Admin SDK
Your Firebase service account can be used to authenticate multiple Firebase features, such as Database, Storage and Auth, programmatically via the unified Admin SDK. Learn more

Firebase service account
[email protected]

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@xpertcrush
No, it's not related to the SDK.

This is the REST API client, internet capable device can communicate to Firebase without SDK installed.

Just follow this for the Firebase project setup

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

tried with completely new account and database still connection refused error, it freezes serial data for 12-16 seconds and through that error.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@xpertcrush

Tell me about your device or board model, ESP8266 Core SDK version, IDE version, board, flash and lwIp settings in IDE.

Post your complete sketch not just some code portion like this.

Complete serial debug message.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

image
see i am getting connection on firebase database

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

device is esp8266 12f core skd version is latest, everything is latest already

here is the flash setting screenshot

image

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

image

I tried pinging outside my network and its fine as well.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

You don't provide what exactly I asked then I don't know you are understand my request.

Don't conclude with latest. No code nothing to verify.

I can't provide any further help

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024
/*
 * Created by K. Suwatchai (Mobizt)
 * 
 * Email: [email protected]
 * 
 * Github: https://github.com/mobizt
 * 
 * Copyright (c) 2020 mobizt
 *
*/

//This example shows how to set and push timestamp (server time) which is the server variable that suopported by Firebase

//FirebaseESP8266.h must be included before ESP8266WiFi.h
#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>

#define FIREBASE_HOST "xxxxxxxxx.firebaseio.com"
#define FIREBASE_AUTH "xxxxxxxxxxx"
#define WIFI_SSID "VirusAlert"
#define WIFI_PASSWORD "WrongEnd123456"

//Define Firebase Data object
FirebaseData firebaseData;

void setup()
{

  Serial.begin(115200);
  Serial.println();
  Serial.println();

  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();

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  //Set the size of WiFi rx/tx buffers in the case where we want to work with large data.
  firebaseData.setBSSLBufferSize(1024, 1024);

  //Set the size of HTTP response buffers in the case where we want to work with large data.
  firebaseData.setResponseSize(1024);

  /*
  This option allows get and delete functions (PUT and DELETE HTTP requests) works for device connected behind the
  Firewall that allows only GET and POST requests.
  
  Firebase.enableClassicRequest(firebaseData, true);
  */

  String path = "/Test";

  Serial.println("------------------------------------");
  Serial.println("Set Timestamp test...");

  if (Firebase.setTimestamp(firebaseData, path + "/Set/Timestamp"))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.println("TYPE: " + firebaseData.dataType());

    //Timestamp saved in millisecond, get its seconds from intData()
    Serial.print("TIMESTAMP (Seconds): ");
    Serial.println(firebaseData.intData());

    //Or print the total milliseconds from doubleData()
    //Due to bugs in Serial.print in Arduino library, use printf to print double instead.
    printf("TIMESTAMP (milliSeconds): %.0lf\n", firebaseData.doubleData());

    //Or print it from payload directly
    Serial.print("TIMESTAMP (milliSeconds): ");
    Serial.println(firebaseData.payload());

    //Due to some internal server error, ETag cannot get from setTimestamp
    //Try to get ETag manually
    Serial.println("ETag: " + Firebase.getETag(firebaseData, path + "/Set/Timestamp"));
    Serial.println("------------------------------------");
    Serial.println();
  }
  else
  {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }

  Serial.println("------------------------------------");
  Serial.println("Get Timestamp (double of milliseconds) test...");

  if (Firebase.getDouble(firebaseData, path + "/Set/Timestamp"))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.println("TYPE: " + firebaseData.dataType());

    printf("TIMESTAMP: %.0lf\n", firebaseData.doubleData());
    Serial.println("------------------------------------");
    Serial.println();
  }
  else
  {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }

  Serial.println("------------------------------------");
  Serial.println("Push Timestamp test...");

  if (Firebase.pushTimestamp(firebaseData, path + "/Push/Timestamp"))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.print("PUSH NAME: ");
    Serial.println(firebaseData.pushName());

    //Due to some internal server error, ETag cannot get from pushTimestamp
    //Try to get ETag manually
    Serial.println("ETag: " + Firebase.getETag(firebaseData, path + "/Push/Timestamp/" + firebaseData.pushName()));
    Serial.println("------------------------------------");
    Serial.println();
  }
  else
  {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }
}

void loop()
{
}

this is the example which is included in library and here is the output.

Sorry about not posting code earlier, totally overlooked. Sorry again.

image

surprisingly it worked. Thank you for your time.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

Dear mobizt

image

everything is fine if I do not set IP address as static. here is the code.

if I setup static IP address it refuses connection with firebase.

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

if i setup dns to 192.168.1.1 it works fine but then it doesn't setup static Ip and choose one from DHCP.

image

from firebase-esp8266.

xpertcrush avatar xpertcrush commented on May 27, 2024

Library does not touch the network stacks, it plays with requests and responses.

you are right. it is a router issue, I will try with another router or a hotspot. thank you once again for the response. you did brilliant work on this library. Thank you so much.

from firebase-esp8266.

fqhzz avatar fqhzz commented on May 27, 2024

Hello, I have a problem with "read Timeout"

image

The value in my Firebase Database changed just fine.
and the first 10seconds after reset the wemos, I can turn on/off the led no problem. after that first 10seconds, "read Timeout"

#include <FirebaseESP8266.h>
#include <ESP8266WiFi.h>

#define FIREBASE_HOST ".firebaseio.com"
#define FIREBASE_AUTH "x"
#define WIFI_SSID "x"
#define WIFI_PASSWORD "x"
#define LED D13
FirebaseData firebaseData;
String c;

void setup()
{
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  
  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 ...");
  //Serial.println(WiFi.localIP());
  //Serial.println();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  if (Firebase.setString(firebaseData, "LED", "0"))
  {
    //Success
    Serial.println("Set int data success");

  } else {
    //Failed?, get the error reason from firebaseData
    Serial.print("Error in setString, ");
    Serial.println(firebaseData.errorReason());
  }
}

void loop()
{
  if (Firebase.get(firebaseData, "/LED"))
  {
    //Success
    Serial.print("Get int data success, int = ");
    Serial.println(firebaseData.stringData());
    c = firebaseData.stringData();
    digitalWrite(LED, (c.toInt()));

  } else {
    //Failed?, get the error reason from firebaseData
    Serial.print("Error in getInt, ");
    Serial.println(firebaseData.errorReason());
  }
  delay(2000);
}

Thank You in advance

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@N3utral03 your router or AP that your device connected is not response, no internet or unstable internet or connect trough some login portal of ISP or your router hang.

You should test with the Arduino examples to make https request using BearSSL WiFiClientSecure and running repeatedly in the loop, you will get the similar results.

from firebase-esp8266.

fqhzz avatar fqhzz commented on May 27, 2024

@N3utral03 your router or AP that your device connected is not response, no internet or unstable internet or connect trough some login portal of ISP or your router hang.

You should test with the Arduino examples to make https request using BearSSL WiFiClientSecure and running repeatedly in the loop, you will get the similar results.

right. turns out it's my unstable connection. try using another connection today and works just fine.
thank you!

from firebase-esp8266.

nuraisa29 avatar nuraisa29 commented on May 27, 2024

I have the same problem. When i try to read from the firebase realtime database, all it returnes is connection refused.

this is my code, anyone can help me?

#include <SoftwareSerial.h>

// for WiFi
#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>
#define WIFI_SSID "xxxxx"
#define WIFI_PASSWORD "xxxxx"

//for FireBase
#define FIREBASE_HOST "xxxxx"
#define FIREBASE_AUTH "xxxxx"

FirebaseData firebaseData;

//buat variabel untuk software serial (Rx, Tx)
SoftwareSerial DataSerial(12, 13);

//millis sebagai pengganti delay
unsigned long previousMillis = 0;
const long interval = 1000;

//variabel array untuk data parsing
String arrData[3];

void setup()
{
// 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());

//ke firebase
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Serial.begin(9600);
DataSerial.begin(9600);
}

void loop()
{
//konfigurasi millis
unsigned long currentMillis = millis(); //baca waktu millis saat ini
if(currentMillis - previousMillis >= interval)
{
//update previousMillis
previousMillis = currentMillis;

//prioritaskan pembacaan data dari arduino uno (hasil kiriman data)
//baca data serial
String Data = ""; //variabel yang menampung pembacaan DataSerial
while(DataSerial.available()>0)
{
Data += char (DataSerial.read());
}
//buang spasi datanya
Data.trim();

//uji data
if(Data != "")
{
//format data "10#200#1" = array
//parsing data (pecah data)
int index = 0;
for(int i=0; i<= Data.length(); i++)
{
char delimiter = '#';
if(Data[i] != delimiter)
arrData[index] += Data[i];
else
index++; //variabel index bertambah 1
}

//pastikan bahwa data yang dikirim lengkap (LDR, HUJAN, PJEMURAN)
//urutannya 0 = LDR, 1 = Hujan, 2 = PJemuran
if(index == 2)
{
  //tampilkan nilai sensor ke serial monitor 
  Serial.println("LDR : " + arrData[0]);                                                //LDR                                                                       
  Serial.println("Hujan : " + arrData[1]);                                           //Hujan                                     
  Serial.println("Posisi Jemuran [1]Di dalam / [0]Di luar : " + arrData[2]);        //PJemuran
  Serial.println();
  delay(2000);

}


arrData[0] = "";
arrData[1] = "";
arrData[2] = "";

}

//minta data ke arduino uno
DataSerial.println("Ya");

}

// set value LDR di FireBase
if (Firebase.setString(firebaseData,"/Hasil_Pembacaan/LDR", arrData[0]))
{
Serial.println("Data LDR terkirim");
}
else
{
Serial.println("Data LDR tidak terkirim");
Serial.println("Karena: " + firebaseData.errorReason());
return;
}

if (Firebase.setString(firebaseData,"/Hasil_Pembacaan/Hujan", arrData[1]))
{
Serial.println("Data Hujan terkirim");
}
else
{
Serial.println("Data Hujan tidak terkirim");
Serial.println("Karena: " + firebaseData.errorReason());
return;
}

if (Firebase.setString(firebaseData,"/Hasil_Pembacaan/Posisi Jemuran : ", arrData[2]))
{
Serial.println("Data Posisi Jemuran terkirim");
}
else
{
Serial.println("Data LDR tidak terkirim");
Serial.println("Karena: " + firebaseData.errorReason());
return;
}
delay(1000);
}

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@nuraisa29

Change the AP or reset router. Connection refused error is the internet connection problem.

Use your cell phone to share WiFi hotspot.

from firebase-esp8266.

nuraisa29 avatar nuraisa29 commented on May 27, 2024

the advice you gave did not work, is there any other way?

@nuraisa29

Change the AP or reset router. Connection refused error is the internet connection problem.

Use your cell phone to share WiFi hotspot.

thx for ur suggestion, but the advice you gave did not work, is there any other way?

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@nuraisa29
Check your database URL, it should valid.
Otherwise change usb cable (voltage drop issue), or try another board.

from firebase-esp8266.

nuraisa29 avatar nuraisa29 commented on May 27, 2024

@nuraisa29
Check your database URL, it should valid.
Otherwise change usb cable (voltage drop issue), or try another board.

it does not work, still displays the same error "data not sent , bcs connection refused"

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@nuraisa29

I will check the currently bug I've found in the latest version which may related to this issue or not.

I will inform you to update and retest soon.

from firebase-esp8266.

nuraisa29 avatar nuraisa29 commented on May 27, 2024

‎Saya akan memeriksa bug yang saat ini saya temukan di versi terbaru yang mungkin terkait dengan masalah ini atau tidak.‎

‎Saya akan memberi tahu Anda untuk memperbarui dan menguji ulang segera.‎

oke thx

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

@nuraisa29

Please update the library to v3.3.5.

If you still get the error, try the following.

Renew your database secret.

Or test your internet connection with example sketch, in Arduino IDE go to File -> Examples -> ESP8266WiFi -> HTTPSRequest.

If you test the HTTPSRequest.ino example and get the internet connection error, your WiFi AP is the problem.
If test is ok, library should be ok too.

You should update ESP8266 Core SDK to latest v3.0.1 (update via Boards Manager).

from firebase-esp8266.

mechasif avatar mechasif commented on May 27, 2024

What do you mean?

If you want to khow how to use, the examples or read me on the main page will provide complete usages.

For path parameter, you need to add slash at its beginning e.g. "/Room/Node1/Senor1".

For FIREBASE_HOST that pass to Firebase.begin function should be valid in form "xxxx.firebaseio.com", no http:// or https:// or slash at beginning or at the end.

This fixed my issue. Thanks!

from firebase-esp8266.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.