Arduino 101 unstable with BlynkTimer

I’m using the Arduino 101, firmware 1.0.7 (yeh v2.0.2 bluetooth is bust).

What I’m seeing is unstable behaviour with BlynkTimer. Basically the arduino locks up when my android app pushes data to BLYNK_WRITE(v1) over bluetooth whilst my main code is doing its thing inside a BlynkTimer function. It doesn’t do it every time I push data - perhaps 1 in 10.

This happens on trivial sketches such as the following:

#define BLYNK_PRINT Serial


#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>
#include "CurieTimerOne.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "<REDACTED>";

BLEPeripheral  blePeripheral;

BlynkTimer timer;

int _count=0;
const int oneSecInUsec = 1000000;

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("pin:");
  Serial.print(_count);
  Serial.print(" ");
  Serial.println(pinValue);
  

  // process received value
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(1000);

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

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();

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

  timer.setInterval(500L, myTimerEvent);
}

void loop()
{
  blePeripheral.poll();
  Blynk.run();
  timer.run(); 
}

void myTimerEvent()
{
  _count++;
  Serial.print("event:");
  Serial.println(_count);
  Blynk.virtualWrite(V4,_count);
  
}

I can remove the Blynk.virtualWrite(V4,_count) and it still locks up.

When it does lockup I typically see Heartbeat timeout in the arduino 101 Serial logs.

The 101 has two core x86 and an arc core and the intel toolchain decides which parts should be run on which core. So I’m thinking that might be a factor.

I’ve tried a similar sketch that swaps out BlynkTimer for “CurieTimerOne.h” (the timer that intel provides for arduino 101) and the sketch is stable - I can change V1 without it locking up. Unfortunately Blynk.virtualWrite(V4, _count) don’t seem to arrive at my android app when run from the context of a “Curie” timer.

#define BLYNK_PRINT Serial


#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>
#include "CurieTimerOne.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "<REDACTED>";

BLEPeripheral  blePeripheral;

//BlynkTimer timer;

int _count=0;
const int oneSecInUsec = 1000000;

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("pin:");
  Serial.print(_count);
  Serial.print(" ");
  Serial.println(pinValue);
  

  // process received value
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(1000);

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

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();

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

  int time = oneSecInUsec / 2; // time is used to toggle the LED is divided by i
  CurieTimerOne.start(time, &myTimerEvent); 

  //timer.setInterval(500L, myTimerEvent);
}

void loop()
{
  blePeripheral.poll();
  Blynk.run();
  //timer.run(); 
}

void myTimerEvent()
{
  _count++;
  Serial.print("event:");
  Serial.println(_count);
Blynk.virtualWrite(V4,_count);
  
}

So my choice is 2 way comms (unstable) or 1 way comms (stable)