Build application with Blynk and Blynk reconnect



  • Hi,
    I'm new to the Omega so I would like to get some better understanding how things works. I can't find proper documentation of Blynk library and available methods inside object var blynk = new BlynkLib.Blynk (token);

    Things that I would like to uderstand better is:

    • what is propper way to run node.js script automatically after startup (this would be my program or application if you like)
    • how to properly detect connection and disconnection of apcli0 wifi network
    • how to properly detect and handle connection and disconnection to the Blynk service (server)
    • how to fast (as possible) toggle GPIO from node.js

    I have writen my application in node.js. It works almost fine, but there are some issues.

    • One thing that bothers me is that if Omega starts up without WiFi application available then My application starts and can't connect Blynk. So,
    blynk.on('connect', function(){
    // some acctions
    });
    

    never happens.

    • Another issue is that if for some reason, wifi drops during work, Blynk won't reconnect.
      But, both issues dosn't exist if I login to console (after startup) and manually start node.js script.

    Please advise,



  • @Mario-Simunic
    I'm running FW omega2p-v0.2.0-b186 on Omega2+
    When I run My node.js script manually after startup, everythings fine until I dissable My WiFi router (to test reconection to blynk).
    Then:
    blynk.on('disconnect', function() { console.log("DISCONNECT"); });
    doesn't happen.

    After I anable WiFi again, serial Console puts message:

    events.js:146
          throw err;
          ^
    
    Error: Uncaught, unspecified "error" event. (ECONNRESET)
        at emit (events.js:144:17)
        at Blynk.error (/usr/bin/blynk-library/blynk.js:589:8)
        at null.<anonymous> (/usr/bin/blynk-library/blynk.js:552:48)
        at emitOne (events.js:77:13)
        at emit (events.js:169:7)
        at TLSSocket.<anonymous> (/usr/bin/blynk-library/blynk-node.js:204:16)
        at emitOne (events.js:77:13)
        at TLSSocket.emit (events.js:169:7)
        at emitErrorNT (net.js:1255:8)
        at nextTickCallbackWith2Args (node.js:437:9)
    

    So, there is no automatic connection status response.
    Also, it looks like reconnection to Blynk server fails somewhere.

    blynk.virtualWrite(v0, 0); // Does nothing, but it should update button in App connected to V0
    


Looks like your connection to Community was lost, please wait while we try to reconnect.