Blynk stuck in Login timeout on Arduino 101 BLE

I need some help with my project to visualize CAN-Bus data from a car via Blynk.

After some time the App will loose contact to the server (Android 6.0, WLAN, with latest App 1.14 from today), so I get a Heartbeat failure and then a Login timeout from which Blynk will not recover:

[25182] Ready [440416] Heartbeat timeout [445420] Login timeout [450420] Login timeout [455421] Login timeout [460423] Login timeout [465424] Login timeout [470425] Login timeout [475426] Login timeout
The sketch is still running and is responsive, but the Arduino 101 can’t be reconnected through BLE - it is no more “visible” (even to other BLE scan tools on other devices!).

Do you have a suggestion?

THX

@odyssey can you please provide the minimum sketch that demonstrates the problem?

Here is the main-sketch with the Blynk connectivity (BLE) - have a look:

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial

//#define BLYNK_USE_DIRECT_CONNECT
#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>
#include "canDiag.h"

#define CS     10                //!< chip select pin of MCP2515 CAN-Controller
#define CS_SD  8                 //!< CS for SD card, if you plan to use a logger...
MCP_CAN CAN0(CS);                //!< Set CS pin

canDiag DiagCAN;
BatteryDiag_t BMS;
ChargerDiag_t NLG6;
CoolingSub_t CLS;
DriveStats_t DRV;

CTimeout CAN_Timeout(1000);        //!< Timeout value for CAN response in millis
CTimeout DEVstatus_Timeout(2000);

WidgetLED LEDcon(V0);

unsigned long time = millis();
unsigned int delta = 0;

char auth[] = "auth token";

int state = 0;

BLEPeripheral  blePeripheral;

void setup() {
  Serial.begin(9600);
  delay(1000);
  //while(!Serial);

  //LED CAN-Bus active
  pinMode(8, OUTPUT);
  //LED BLE connected
  pinMode(7, OUTPUT);

  // MCP2515 read buffer: setting pin 2 for input, LOW if CAN messages are received
  pinMode(2, INPUT);

  // Initialize MCP2515 and clear filters
  DiagCAN.begin(&CAN0, &CAN_Timeout);
  DiagCAN.clearCAN_Filter();

  blePeripheral.setLocalName("EDm");
  blePeripheral.setDeviceName("EDm");
  blePeripheral.setAppearance(384);

  Blynk.begin(auth, blePeripheral);

  blePeripheral.begin();

  Serial.println("Waiting for connections...");
}

//Default handler for Blynk read requests (timing set in App-Widget)
BLYNK_READ_DEFAULT()
{
  int pin = request.pin;
  switch (pin) {
    case V1:
      if(state = DiagCAN.ReadSOC(&BMS)) Blynk.virtualWrite(pin, BMS.SOC);
      break;
    case V2:
      if(state = DiagCAN.ReadSOCinternal(&BMS)) Blynk.virtualWrite(pin, BMS.realSOC / 10.0);
      break;
    case V3:
      if(state = DiagCAN.ReadHV(&BMS)) Blynk.virtualWrite(pin, BMS.HV);
      break;
    case V4:
      if(state = DiagCAN.ReadPower(&BMS)) Blynk.virtualWrite(pin, ((BMS.Power / 8192.0) -1) * 300);
      break;
    case V6:
      if(state = DiagCAN.ReadLV(&BMS)) Blynk.virtualWrite(pin, BMS.LV);
      break;
    case V7:
      if(state = DiagCAN.ReadODO(&BMS)) Blynk.virtualWrite(pin, BMS.ODO);
      break;
    case V20:
      if(state = DiagCAN.ReadVelocity(&DRV)) Blynk.virtualWrite(pin, DRV.velocity);
      break;
    case V21:
      if(state = DiagCAN.ReadECO(&DRV)) Blynk.virtualWrite(pin, DRV.ECO_total);
      break;
    case V22:
      Blynk.virtualWrite(pin, DRV.ECO_accel);
      break; 
    case V23:
      Blynk.virtualWrite(pin, DRV.ECO_const);
      break; 
    case V24:
      Blynk.virtualWrite(pin, DRV.ECO_coast);
      break;  
    case V25:
      if(state = DiagCAN.ReadRange(&DRV)) Blynk.virtualWrite(pin, DRV.range);
      break;
    case V26:
      Blynk.virtualWrite(pin, DRV.HVactive);
      break;
    case V27:
      Blynk.virtualWrite(pin, DRV.usablePower);
      break;
    case V28:
      if(state = DiagCAN.ReadEnergyConsumption(&DRV)) Blynk.virtualWrite(pin, DRV.energyStart / 100.0);
      break;
    case V29:
      Blynk.virtualWrite(pin, DRV.energyReset / 100.0);
      break;      
    case V30:
      if(state = DiagCAN.ReadUserCounter(&DRV)) Blynk.virtualWrite(pin, DRV.odoStart / 10.0);
      break;
    case V31:
      Blynk.virtualWrite(pin, DRV.odoReset / 10.0);
      break;        
  }
}

//Show status of CAN-Bus and Blynk connect
void DEVstatus() {
  boolean fConnected = Blynk.connected();
  if (!state || !fConnected) {
    state = DiagCAN.ClearReadBuffer();
  }
  digitalWrite(8, state);
  
  //Serial.print("CANstatus: "); Serial.println(state);
  if (fConnected = Blynk.connected()) LEDcon.setValue(state * 255);  
  digitalWrite(7, fConnected);
}

void loop() { 
  Blynk.run();
  blePeripheral.poll(); 
  if (DEVstatus_Timeout.Expired(true)) {
    DEVstatus();                                  //Poll CAN and connectivity status
  }
  
}

When I get the Login timeout the DEVstatus() will still report the CAN-Bus traffic as expected!

It seems I found a solution, but maybe someone give further advice - THX!

  1. I optimized the calling time for the CAN query to < 100ms (timeout set to 200ms as max.)
  2. The MCP2515 lib now uses SPI.beginTransaction() and SP.endTransaction(). These functions are better in interrupt context.
  3. I needed to move away from the BLYNK_READ_DEFAULT() and now use the dedicated BLYNK_READ(pin):
BLYNK_READ(V1) {
  if(state = DiagCAN.ReadSOC(&BMS)) Blynk.virtualWrite(V1, BMS.SOC);
}

....

BLYNK_READ(V31) {
  if(state) Blynk.virtualWrite(V31, DRV.odoReset / 10.0);
}

BLYNK_READ(V40) {
  Blynk.virtualWrite(V40, IOcount++);
}

Now I can monitor and log my Smart ED during driving :wink: Here is a screenshot:

1 Like

Hello, newbie here. I failed to connect to Arduino 101 through BLE.

I tried with Samsung and Pixel phone (both with Bluetooth 4.2). I used the Blynk app on my iPad too but no luck. I use Inter Curie Library 1.0.7.

I used the Arduino_101_BLE example sketch. The serial monitor would say:

Waiting for connection…
[8053] Login timeout
[16284] Login timeout
[18999] Disconnected

My Blynk app can search the 101 but can’t connect to it.

I tried multiple days still can’t get it working. Can anyone help pls?

Please try 2.27.2 beta version for Android - it has some fixes and support for latest blynk library (which has changes for ble/bluetooth login flow)

1 Like

thanks it works!

Please switch to library v0.6.1, that also contains a fix for Bluetooth connectivity: https://github.com/blynkkk/blynk-library/releases/tag/v0.6.1

Does anyone know how to get this working for IOS I’m having the same problem with an UNO and just keep getting told to search the forum. And yes everything is up to date.

There’s an iOS beta program, delivered via Testflight, that has some Bluetooth improvements. You gave to contact @Eugene to get on the beta program.

Pete.