From an iPhone 6s, three buttons using virtual pins send data to an Arduino Mega 2560 over a Bluetooth BLE link using an HM-10. When the Arduino receives its single digit inputs, it responds with a 40 byte message back to the iPhone for display on a Terminal widget.
Updating to the terminal widget stops after just a few (varies from ~4 to ~10) messages. To resolve the problem, I disconnect and reconnect the Bluetooth connection.
The Arduino IDE Serial Monitor continues to show the inputs from the iPhone. So it seems the BLE link to the Arduino is OK.
Text inputs from the iPhone keyboard continue to display locally on the Terminal widget. So it seems the terminal widget is OK.
It seems the Bluetooth link just in the direction to the Smartphone from the Arduino is what breaks.
Using Blynk library 0.6.1
Both an Uno and a Mega 2560 exhibit the same behavior.
Using Blynk server.
#define BLYNK_USE_DIRECT_CONNECT
#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
char auth[] = "CRiBbRNWOrWyjAdYciWSP6My2QehNcJf";
SoftwareSerial SerialBLE(10, 11); // Arduino RX, TX
WidgetTerminal terminal(V7);
BLYNK_WRITE(V7)
{
// Write to Smart Phone Terminal
if(param.getLength() > 0) { // avoids a blank message
terminal.clear();
terminal.print("From iPhone: ");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
}
terminal.flush();
}
// Decrementer button pressed on iPhone
BLYNK_WRITE(V4)
{
// assigning incoming value from pin V4 to a variable
if(param.asInt() == 1) {
terminal.clear();
terminal.println("Decrementer");
terminal.println("03-24-1951-70, 234, Yes, No Distance, 4 Digit pairs.");
Serial.println("Decrementer: ");
}
terminal.flush();
}
// Incrementer button pressed on iPhone
BLYNK_WRITE(V5)
{
// assigning incoming value from pin V5 to a variable
if(param.asInt() == 1) {
terminal.clear();
terminal.println("Incremeter");
terminal.println("03-24-1951-70, 234, Yes, No Distance, 4 Digit pairs.");
Serial.println("Incrementer: ");
}
terminal.flush();
}
// Selector button pressed on iPhone
BLYNK_WRITE(V6)
{
// assigning incoming value from pin V5 to a variable
if(param.asInt() == 1) {
terminal.clear();
terminal.println("Selector");
terminal.println("03-24-1951-70, 234, Yes, No Distance, 4 Digit pairs.");
Serial.println("Selector: ");
}
terminal.flush();
}
void setup()
{
// Clear the terminal content
terminal.clear();
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.flush();
terminal.clear();
// Debug console
Serial.begin(9600);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
Serial.println("Waiting for connections...");
}
void loop()
{
Blynk.run();
}