After 12 requests (~60 sec) Firebase or Python-firebasin library do not send and receive data
Question: I have a problem, please help me.

I created Python script what is collaborating with Firebase to save and
receive data. My script works with python-firebasin library ([link to python-
firebasin](https://github.com/abeisgreat/python-firebasin)). I tested my
application one week with my Firebase account - HACKER PLAN. All works fine
all this time. After that i buy premium account with special URL like
x.firebaseio.com here begins my problems. I import json structure from my old
firebase to my new firebase account and set in my Python script new firebase
URL to my new firebase account. So now all must works fine with my new
firebase premium account. I run my script and ~60 seconds my script works
fine. Callback events work, set values works. But after ~60 seconds Firebase
do not receive and do not send any callback to my Python script. For debugging
i wrote simple script what send unixtime to firebase every 5 second. So all
works fine first 12 requests (12 * 5 = ~60 sec), after what firebase do not
receive any data. Python do not send any error and callback too. Atention: All
works fine with my old Firebase account - HACKER PLAN!

    
    
    from firebasin import Firebase
    from time import sleep, time
    
    # Firebase
    vGFirebase = None
    
    vGCompanyId = '1'
    vGHardwareId = '0000000000123123'
    
    i = 1
    
    vGFirebase = Firebase('https://subdomain.firebaseio.com')
    
    def errorCallback(data):
        print('errorCallback', data)
    
    while True:
        try:
            pingChild = vGFirebase.child('data/app/pings/' + str(vGCompanyId) + '/' +  str(vGHardwareId))
            sendTime = int(time())
            pingChild.set(sendTime, errorCallback)
            print(i, 'send ', sendTime)
            i += 1
            sleep(5)
        except:
            print('Exception')
            break
    
    vGFirebase.waitForInterrupt()
    

I enable Debug mode in python-firebasin library. So after 12 requests i got
this message: **(('Closed down :(', 1006, 'Going away'),)** So i think this is
because Firebase close connection... But why?

Sorry for my bad english...


Answer: firebasin does not start a Heartbeat to keep the connection alive. You can
easily start one yourself. After the line creating `vGFirebase`:

    
    
    from ws4py.websocket import Heartbeat
    while not vGFirebase.connection.data:
        sleep(1)
    Heartbeat(vGFirebase.connection.data,2).start()
    

Unfortunately, the _keep_alive method in dataref.py seems to not get along
with hacker plans and causes them to disconnect when it fires its own
keepalive message, so you'll also need to disable that. You can do so on the
fly by adding

    
    
    import firebasin
    firebasin.dataref.RootDataRef._keep_alive = lambda *x: None
    

to the top of your script. A more permanent, but non-portable solution would
be to patch dataref.py to replace it's _keep_alive method with one that starts
ws4py's Heartbeat. I've submitted a pull request to do that upstream; we'll
see if there is a reason Abe Haskins didn't do it that way in the first place.

