Connect to Firebase

Posted on
  • Hi,
    I understand that Espruino is not a ful-fledge node.js env. And I understand that ws is part of the package, and I can use it to connect to a ws server and do stuff on diff. events.

    My question is, is there a way to use firebase lib directly ? This will save me some work-arounds or writing my own ws wrapper on a saperate server to host websockets to which i'll connect from the esp8266.

    Any ideas are welcome.

    Thanks in advance.

  • The firebase js file is 360kB, and most Espruino devices have in the region of 50kB available RAM, so there's no way you can use the lib directly. It sounds like you might be trying to use just a bare ESP8266? In that case you'll have even less memory available.

    Potentially you could try to use tree-shaking tools to strip out the bits you're not using, but I think this is more effort that doing it directly, and you're very unlikely to get it small enough that you could run other code as well.

  • Maybe this is now possible on some of the larger devices such as the ESP 32?

  • You could try ESP32 WROVER board, which has additional PSRAM.
    Right now it supports 320kb, and could be expanded.
    See espruinoTask(void *data) in­b/master/targets/esp32/main.c
    Each jsVar takes 16 bytes, so 20000 jsVars are 320kb
    To put water into the wine, I would still expect firebase is way too large for these small chips.

  • Just to add, it'll be pretty easy to use firebase on any Espruino board that supports HTTPS using their REST API:­ce/rest/database/

    It's just the firebase library that is itself too big.

    If someone wrote a more sensible library for Espruino that interfaced to that then it should only take a few kb, and I'd be happy to host it on the Espruino site.

  • this thread is old, but just thought it's worth while stressing what @Gordon mentioned above:
    you can't perform a REST API call on a 'cheap' ESP8266 board, you'll need one of the boards that supports this.
    I actually like the idea of developing with the more expensive Wifi board, but I'd like to deliver them cheap boards of 2$ ESP8266 - and that (apparently) can't be used - unless you write and hosts an http to https proxy somewhere - not that hard really :) and you can still stay free with platforms like heroku

    ------- edit ----------
    btw - these boards DO support Firebase if you went along the C++ standard Arduino IDE, just far less fun coding on those

  • thanks @MaBe, but I already wrote a simple node 5 liner that fits my needs ;)

  • cool, do you like to share it?

  • a bit more than 5 lines actually

    const app = require('express')();
    app.get('/', (req, res) => {
      console.log("fetching ...", req.query.url);
      if (req.query.url) fetch(req.query.url, (data) => {res.send(data); });
      else res.send("missing url");
    const port = 9999;
    app.listen(port, () => {
      console.log(`fetch a url with http://localhost:${port}?url=https://som­`);
    function fetch(url, cb) {
      require("https").get(url, res => {
        let body = "";
        res.on("data", data => { body += data; });
        res.on("end", () => { cb(body); });
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Connect to Firebase

Posted by Avatar for daveamit @daveamit