Git Product home page Git Product logo

firebase-arduino-wifi101's Introduction

Google Firebase Realtime Database Arduino Library based on WiFi101 library

GitHub Sponsors

The library supports Arduino WiFi Shield 101 and Arduino MKR1000 WIFI Boards.

This library aims to keep support low memory and flash space device like WiFi Shield 101 with simple Firebase RTDB functions.

We're moving to the new library

Warning

Due to the issues that cannot be fixed, this This library is now obsoleted and replaced by the new FirebaseClient library.

The new async FirebaseClient library is now availavle in Arduino IDE and PlatformIO's Library Manager.

The new library provides simpler APIs interface, faster and more reliable operations. It can use in both sync and async operations.

All old Firebase libraries will be deprecated soon this year and we recommended to upgrade your current code to work with new async FirebaseClient library instead.

License

The MIT License (MIT)

Copyright (c) 2024 K. Suwatchai (Mobizt)

Permission is hereby granted, free of charge, to any person returning a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

firebase-arduino-wifi101's People

Contributors

mobizt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

firebase-arduino-wifi101's Issues

stream not Working

so have had code that worked for a long time then out of the blue it just stopped. from my troubleshooting i connects to the internet and the connects to the domain. but when it goes to read data from the stream it does not work i get
Can't read stream data
REASON: not connected
Stream timeout, resume streaming...

i find very odd. as this code worked two weeks ago.

`#include <Firebase_Arduino_WiFi101.h>
#include <Firebase_Arduino_WiFi101_HTTPClient.h>
#include <WiFi101.h>
#include <Adafruit_NeoPixel.h>
#include <ArduinoJson.h>
#include <SPI.h>

#define FIREBASE_HOST "homecontrol-2fa6a-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "FIv2CkgS0NToGu5nW5kOt9kZWi0KTiddZFVnR0vZ"
#define WIFI_SSID "NestieFi"
#define WIFI_PASSWORD "This1$mypassword"

FirebaseData firebaseData;

String parentPath = "/MagTagDisplay/3";

#define PIN 13

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);

String msgs[6];
bool latch = false;
bool other = true;
int l = 0;
uint8_t fR, fG, fB, bR, bG, bB;
int fadeColor;
int colorCounter;

const char* message = "";
String messageBuffer = "";

const char* led1Char;
String led1Temp = "";
uint32_t led1 = 0x000000;
uint32_t led1Buffer = 0x000000;

const char* led2Char;
String led2Temp = "";
uint32_t led2 = 0x000000;
uint32_t led2Buffer = 0x000000;

DynamicJsonDocument jsonDoc(1024);

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial);
Serial.println("hello");

WiFi.setPins(8,7,4,2);

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}

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, WIFI_SSID, WIFI_PASSWORD);
Firebase.reconnectWiFi(true);

if (!Firebase.beginStream(firebaseData, parentPath))
{
Serial.println("Could not begin stream");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println();
}

strip.begin();
strip.setBrightness(30); //adjust brightness here
strip.show(); // Initialize all pixels to 'off'
}

void loop() {
// Your code here

if (!Firebase.readStream(firebaseData))
{
Serial.println("Can't read stream data");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println();
}

if (firebaseData.streamTimeout())
{
Serial.println("Stream timeout, resume streaming...");
Serial.println();
}

if (firebaseData.streamAvailable())
{
if (firebaseData.dataType() == "json") {
deserializeJson(jsonDoc, firebaseData.jsonData());
JsonObject data1 = jsonDoc.as();
latch = true;
if (data1.containsKey("message")) {
message = data1["message"];
msgs[1] = String(message);
}
if (data1.containsKey("led1")) {
led1Char = data1["led1"];
led1Temp = String(led1Char);
led1Temp.replace("#", "0x");
led1 = strtoul(led1Temp.c_str(), NULL, 16);
}if (data1.containsKey("led2")) {
led2Char = data1["led2"];
led2Temp = String(led2Char);
led2Temp.replace("#", "0x");
led2 = strtoul(led2Temp.c_str(), NULL, 16);
}
}
}

if (msgs[1] == "Off") {
Serial.println("Off");

strip.clear();
strip.show();
msgs[1] = 100;

} else if (msgs[1] == "Rainbow") {
Serial.println("Rainbow");
if (latch) {

}
rainbowCycle();

} else if (msgs[1] == "Solid") {
Serial.println("solid");
if (latch) {

  solidColor();
}

} else if (msgs[1] == "Color Chase") {
Serial.println("Color Chase");
if (latch) {

}
colorChase();

} else if (msgs[1] == "Two Color Blink") {
Serial.println("two color blink");
if (latch) {

}
colorBlink();

} else if (msgs[1] == "Colors Wipe") {
Serial.println("colors wipe");
if (latch) {

}
colorsWipe();

} else if (msgs[1] == "Random Colors") {
Serial.println("random colors");
if (latch) {

}
randomColors();

} else if (msgs[1] == "Two Color Chase") {
Serial.println("Two Color Chase");
if (latch) {

}
twoColorChase();

} else if (msgs[1] == "Colors Fade") {
Serial.println("Colors Fade");
if (latch) {

  fadeColor = 0;
}
colorFade();

}
}

void colorWipe(uint32_t c) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(50);
}
}

void colorsWipe() {
latch = false;
colorWipe(colorPicker(colorCounter));
colorCounter++;
if (colorCounter > 15) {
colorCounter = 0;
}
}

void rainbowCycle() {
latch = false;
uint16_t i;

for (i = 0; i < strip.numPixels(); i++) {
  strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + colorCounter) & 255));
}
colorCounter++;
if (colorCounter > 256) {
  colorCounter = 0;
}
strip.show();
delay(20);

}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

void solidColor() {
latch = false;
colorWipe(led1);
strip.show();

}

uint32_t colorPicker(int color) {
uint32_t colorPicked;
if (color == 15) { //"white"
colorPicked = strip.Color(255, 255, 255);
} else if (color == 0) {
colorPicked = strip.Color(255, 0, 0);
} else if (color == 1) {
colorPicked = strip.Color(255, 128, 0);
} else if (color == 2) {//"green"
colorPicked = strip.Color(255, 255, 0);
} else if (color == 3) {
colorPicked = strip.Color(128, 255, 0);
} else if (color == 4) {
colorPicked = strip.Color(0, 255, 0);
} else if (color == 5) {
colorPicked = strip.Color(0, 255, 128);
} else if (color == 6) {
colorPicked = strip.Color(0, 255, 255);
} else if (color == 7) {
colorPicked = strip.Color(0, 128, 255);
} else if (color == 8) {
colorPicked = strip.Color(0, 0, 255);
} else if (color == 9) {
colorPicked = strip.Color(128, 0, 255);
} else if (color == 10) {
colorPicked = strip.Color(255, 0, 255);
} else if (color == 11) {
colorPicked = strip.Color(255, 0, 128);
} else if (color == 12) {
colorPicked = strip.Color(128, 255, 255);
} else if (color == 13) {
colorPicked = strip.Color(255, 128, 255);
} else if (color == 14) {
colorPicked = strip.Color(255, 255, 128);
}
return (colorPicked);
}

void colorChase() {
latch = false;
uint32_t forgroundColor;
uint32_t backgroundColor;

int li = 0;
int gi = 0;

forgroundColor = led1;
backgroundColor = led2;
li = colorCounter - 1;
gi = colorCounter + 1;
strip.fill(backgroundColor);
strip.show();

if (li >= 0) {
  strip.setPixelColor(li, forgroundColor);
}
if (gi <= strip.numPixels()) {
  strip.setPixelColor(gi, forgroundColor);
}
strip.setPixelColor(colorCounter, forgroundColor);
colorCounter++;
if(colorCounter>strip.numPixels()){colorCounter=0;}
strip.show();
delay(200);

}

void colorBlink() {
latch = false;
uint32_t forgroundColor;
uint32_t backgroundColor;

forgroundColor = led1;
backgroundColor = led2;

for (int i = 0; i < strip.numPixels(); i++) {
if (other) {
strip.setPixelColor(i, forgroundColor);
i++;
strip.setPixelColor(i, backgroundColor);

} else {
  strip.setPixelColor(i, backgroundColor);
  i++;
  strip.setPixelColor(i, forgroundColor);

}

}

if (other) {
other = false;
}
else {
other = true;
}
strip.show();
delay(200);
}

void randomColors()
{
latch = false;
for (int i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, colorPicker(random(0, 15)));
}
strip.show();
delay(200);
}

void twoColorChase() {
latch = false;
uint32_t forgroundColor;
uint32_t backgroundColor;

forgroundColor = led1;
backgroundColor = led2;
strip.fill(backgroundColor);

if (l > 5) {
l = 0;
}

for (int i = l; i < strip.numPixels(); i++) {

for (int j = 0; j < 3; j++)
{
  if (l > 3) {
    strip.setPixelColor(0, forgroundColor);
  }
  if (l > 4) {
    strip.setPixelColor(1, forgroundColor);
  }
  if (i <= strip.numPixels()) {
    strip.setPixelColor(i, forgroundColor);
  }
  i++;
}
i = i + 2;

}
l++;
strip.show();
delay(200);
}

uint32_t fadeColorPicker(int color, int f) {
uint32_t colorPicked;
if (color == 12) { //"white"
colorPicked = strip.Color( 255.0 * ((float)f / 30.0), 255.0 * ((float)f / 30.0), 255.0 * ((float)f / 30.0));
} else if (color == 0) { //"blue"
colorPicked = strip.Color(0, 0, 255.0 * ((float)f / 30.0));
} else if (color == 1) { //"red"
colorPicked = strip.Color( 255.0 * ((float)f / 30.0), 0, 0);
} else if (color == 2) {//"green"
colorPicked = strip.Color(0, 255.0 * ((float)f / 30.0), 0);
} else if (color == 3) {//"magenta"
colorPicked = strip.Color( 255.0 * ((float)f / 30.0), 0, 255.0 * ((float)f / 30.0));
} else if (color == 4) {//"yellow"
colorPicked = strip.Color( 255.0 * ((float)f / 30.0), 255.0 * ((float)f / 30.0), 0);
} else if (color == 5) {//"cyan"
colorPicked = strip.Color(0, 255.0 * ((float)(float)f / 30.0), 255.0 * ((float)f / 30.0));
} else if (color == 6) { //"orange"
colorPicked = strip.Color( 255.0 * ((float)f / 30.0), 165.0 * ((float)f / 30.0), 0);
} else if (color == 7) {//"purple"
colorPicked = strip.Color( 128.0 * ((float)f / 30.0), 0, 128.0 * ((float)f / 30.0));
} else if (color == 8) {//"blueviolet"
colorPicked = strip.Color( 138.0 * ((float)f / 30.0), 43.0 * ((float)f / 30.0), 226.0 * ((float)f / 30.0));
} else if (color == 9) {//"olivedrab"
colorPicked = strip.Color( 107.0 * ((float)f / 30.0), 142.0 * ((float)f / 30.0), 35.0 * ((float)f / 30.0));
} else if (color == 10) {//"olive"
colorPicked = strip.Color( 128.0 * ((float)f / 30.0), 128.0 * ((float)f / 30.0), 0);
} else if (color == 11) {//"teal"
colorPicked = strip.Color(0, 128.0 * ((float)f / 30.0), 128.0 * ((float)f / 30.0));
}
return (colorPicked);
}

void colorFade() {
latch = false;

for (int i = 1; i < 30; i++) {

strip.fill(fadeColorPicker(fadeColor, i));
strip.show();
delay(100); //edits to desire

}

for (int i = 30; i >= 1; i--) {

strip.fill(fadeColorPicker(fadeColor, i));
strip.show();
delay(100); //edits to desire

}

fadeColor++;
if (fadeColor >= 13) {
fadeColor = 0;
}
}`

Getting bad request

Even after updating the firmware of my MKR1000, I get bad request as the errorReason(). Is there a way to get more detail on the errorReason() function; maybe an error code or solution?

Error in the getInt example

In the example in the README.md, there is an extra bracket.
if (firebaseData.dataType() == "int")) { val = firebaseData.intData(); Serial.println(val); }

should be :
if (firebaseData.dataType() == "int") { val = firebaseData.intData(); Serial.println(val); }

Connection Refused using an Arduino MKR1000 board

First of all thank you for the really useful library!
I have tried to run the Basic.ino example to see if my firebase database and the MKR1000 were working properly, but form the serial monitor of arduino I keep receiving a "connection refused" message.
I did check my firebase host and authorization. I have tried to use the hotspot on my phone as well to change wifi, but nothing worked so far.
Any suggestion on why it refuse to work ?
(the code I'm using is just the basic.ino example with my host, auth, ssid and password)

Connection Refused

Hi, I'm working on a project with an Arduino MKR 1000 (connected to six sensors) but firebaseData.errorReason() always returns "Connection refused." Any suggestions? Thanks :>
Screenshot 2024-03-11 231406

#include <WiFi101.h>
#include "Firebase_Arduino_WiFi101.h"

//firebase info
#define HOST "sensornetwork-fsl-default-rtdb.firebaseio.com"
#define AUTH "" //database secret
#define SSID ""
#define PASSWORD ""


FirebaseData db;

//pins info
const int NUM_SENSORS = 6; 
const int trigPins[NUM_SENSORS] = {1, 3, 5, 7, 9, 13};
const int echoPins[NUM_SENSORS] = {2, 4, 6, 8, 10, 14};

void setup() {
  Serial.begin(1000);

  //wifi setup 
  Serial.print("Connecting to Wi-Fi");
  int status = WL_IDLE_STATUS;
  while (status != WL_CONNECTED){
    status = WiFi.begin(SSID, PASSWORD);
    Serial.print(".");
    delay(100);
  }

  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();
  delay(100);

  //set up firebase
  Firebase.begin(HOST, AUTH, SSID, PASSWORD);
  Firebase.reconnectWiFi(true); 

  //set up all inputs and outputs
  for(int i = 0; i < NUM_SENSORS; i++){
    pinMode(trigPins[i], OUTPUT); 
    pinMode(echoPins[i], INPUT); 
  }

}

void loop() {
  long duration, inches, cm;
  
  for(int i = 0; i < NUM_SENSORS; i++){
    digitalWrite(trigPins[i], LOW);
    delayMicroseconds(2);
    digitalWrite(trigPins[i], HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPins[i], LOW);

    duration = pulseIn(echoPins[i], HIGH);

    inches = microsecondsToInches(duration);
    cm = microsecondsToCentimeters(duration);

    Serial.print("Sensor ");
    Serial.print(i+1);
    Serial.print(" : ");
    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    
    //update database and print status
    bool spotOccupied = (cm < 5);
    String path = "/spots/" + String(i+1); 
    Serial.println(path);
    
    if (Firebase.setBool(db, path, spotOccupied)) {
      Serial.println("Firebase update successful");
    } else {
      Serial.println("Firebase update failed");
      Serial.println(db.errorReason());
    }
    
  }
  
  delay(100);
}

long microsecondsToInches(long microseconds) {
  return microseconds / 148;
}

long microsecondsToCentimeters(long microseconds) {
  return microseconds / 58;
}

Connection refused on example code

Hi, I get a connection refused on the example code (basic). I filled in my project id, database secret (tested) and wifi data. The MKR1000 connects to wifi and is listed at the router.

Any idea how I can debug this? I use version 1.1.3

push and set TIMESTAMPs

Hi,

I am using an MKR1000 and I'm in need of setting and pushing a timestamp to my firebase project.

I've used similar methods successfully with your ESP8266 library.

So, I am just wondering if you plan to include these functions in this library or is there some issue that prevents these functions from being implemented.

Thanks.

Readme Addition

Readme Instructions do not mention, that the google.com certificate needs to be installed.


Open the Firmware update project (File -> Examples -> WiFi101 -> FirmwareUpdater)
Load it into the Arduino
Open the FirmwareUpdate Tool (Tools -> WiFi101 / WiFiNINA Firmware Updater)
Add the "google.com:443" SSL root domain to the arduino

Took me several hours to debug, why the connection to firebase got declined and I don't want others to live through this struggle.

checking connection and forcing reconnection

Hi, first of all, thanks for this amazing library.
I'm just wondering, how can I force a reconnection attempt as my project will lose connection and it will take up to 20 seconds to reconnect.
My project is interactive so when people use it, it uploads the data to firebase and a user waiting 20 seconds will make them walk away.
I am using Firebase.reconnectWiFi(true); but I would like to be able to monitor my connection and force it to reconnect when the connection is lost.

How would I check the connection status?
How can I force it to reconnect if disconnected?

thanks so much.

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.