BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk with BLE (HM10) / Arduino Nano + Android 8.0.0


#1

Hello,

Apologies if this has already been answered but I have spent 2 solid days scouring the forum and my issues still are not fixed.

I am trying to build a simple temperature / humidity sensor for environmental monitoring on an Arduino Nano which communicates to Blynk (library version 0.54 / app verson 2.27.1) on Andrioid version 8.0.0 on a Galaxy S8.

The hardware being used is an Arduino Nano + DSD Tech HM10 BLE module.

Just to update on what I have already checked, I was originally using software serial and having the exact same issue and was using the correct 10 / 11 pins for RX / TX.

About an hour ago to check if software serial was the issue I moved to Altsoftserial on pins 8 and 9 RX/TX. Getting the exact same issue.

I have tested the BLE module with App Inventor 2, this works perfectly however app inventor doesn’t have some of the features I need well documented so I thought as I have a relatively tight deadline, Blynk would be easier.

Also if I beam out temp data through BLE and test with any BLE scanner, I can see the temp data being logged and beamed over bluetooth.

All the issues with the system appear to be with the Blynk app. I can rarely (1 in every 20+ tries) get the app using the BLE widget to connect, the blinking LED on the HM10 turns solid to show a connection has been made. This will then disconnect after 30 seconds or so.

In the serial I mainly just get connecting… login timeout.with the Auth token packets being beamed out in 2 times (I assume as it is over the 20 char limit).

When it does connect, I cannot get anything to show up in the app in any of the widgets. I am pushing to virtual pin V5 but I have never managed to get any data show up.

Below is the latest incaration of code, I am using the Blynk example code which generates random fake temp data (I wanted to eliminate any issues with the analog pin read), and dumps it to V5.

  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  Warning: Bluetooth support is in beta!

  You can construct and display any strings on a Value Display.

  App project setup:
    Value Display widget attached to V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

#include <AltSoftSerial.h>
AltSoftSerial SerialBLE;
    
#include <BlynkSimpleSerialBLE.h>

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


BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendTemperature()
{
  // Generate random temperature value 10.0 to 30.0 (for example)
  float t = float(random(100, 300)) / 10;

  // Format: 1 decimal place, add ℃
  String str = String(t, 1) + "℃";

  // Send it to the server
  Blynk.virtualWrite(V5, str);
}

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

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

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

  // Setup a function to be called every second
  timer.setInterval(1000L, sendTemperature);
}

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

Debug serial output:

[2349029] <[02|00|01|00] 6fe0f069xxxxxx
[2349071] <ab5868cec630584d5
[2352112] Login timeout
[2354112] Connecting...
[2354112] <[02|00|01|00] 6fe0f069xxxxxxx
[2354154] <ab5868cec630584d5
[2357195] Login timeout
[2359195] Connecting...
[2359195] <[02|00|01|00] 6fe0f0xxxxxxxx
[2359237] <ab5868cec630584d5
[2362278] Login timeout
[2364278] Connecting...
[2364278] <[02|00|01|00] 6fe0f0xxxxxxx
[2364320] <ab5868cec630584d5
[2367361] Login timeout
[2369361] Connecting...
[2369361] <[02|00|01|00] 6fe0f06xxxxxxxx
[2369403] <ab5868cec630584d5

When it actually manages to connect, I can see the data being beamed over in the debug:

[503357] Ready
[503373] Free RAM: 1155
[503400] <[00|00|01|00|C8]
Waiting for connections...
[504469] <[14|00|02|00|0C]vw[00]5[00]10.7[E2|84|83]
[505469] <[14|00|03|00|0C]vw[00]5[00]14.9[E2|84|83]
[506469] <[14|00|04|00|0C]vw[00]5[00]17.3[E2|84|83]
[507469] <[14|00|05|00|0C]vw[00]5[00]15.8[E2|84|83]
[508469] <[14|00|06|00|0C]vw[00]5[00]23.0[E2|84|83]
[509469] <[14|00|07|00|0C]vw[00]5[00]17.2[E2|84|83]
[510469] <[14|00|08|00|0C]vw[00]5[00]24.4[E2|84|83]
[511469] <[14|00|09|00|0C]vw[00]5[00]17.8[E2|84|83]
[512470] <[14|00|0A|00|0C]vw[00]5[00]22.3[E2|84|83]
[513357] <[06|00|0B|00|00]
[513469] <[14|00|0C|00|0C]vw[00]5[00]20.9[E2|84|83]
[514469] <[14|00|0D|00|0C]vw[00]5[00]14.0[E2|84|83]
[515469] <[14|00|0E|00|0C]vw[00]5[00]26.5[E2|84|83]
[516358] <[06|00|0F|00|00]
[516469] <[14|00|10|00|0C]vw[00]5[00]19.2[E2|84|83]
[517469] <[14|00|11|00|0C]vw[00]5[00]14.2[E2|84|83]
[518469] <[14|00|12|00|0C]vw[00]5[00]28.7[E2|84|83]
[519359] <[06|00|13|00|00]
[519469] <[14|00|14|00|0C]vw[00]5[00]20.3[E2|84|83]
[520469] <[14|00|15|00|0C]vw[00]5[00]22.7[E2|84|83]
[521469] <[14|00|16|00|0C]vw[00]5[00]22.9[E2|84|83]
[522357] Heartbeat timeout: 522357, 503356, 519359

Also when it does connect, I notice it manages to send the full Auth token properly (not split into 2 lines)

[503254] <[02|00|01|00] 6fe0f06xxxxxxxxxx
[503294] <ab5868cec630584d5
[503334] >[02|00|01|00] 
[503335] >6fe0f06xxxxxxxxxb5868cec630584d5
[503357] Ready
[503373] Free RAM: 1155
[503400] <[00|00|01|00|C8]
Waiting for connections...

I am all out of ideas on how to solve this. I have tested every piece of example code and cannot get anything to connect consistently and when it connects I have never received a single value in the Blynk app.

Any help would be appreciated, I have tried to be as comprehensive as possible and apologies if my post is messy, had a couple of sleepless nights on this one!

Thanks!


#2

Sorry, probably not the answer you may be looking for, but if you search this forum you will see that there are other BT/BLE related stability issues… but no solid developer feedback yet.

I suspect they are focusing more on the true IoT connection methods like WiFi. This is not to say there will not be further BT/BLE work, just saying search the forums and see what, if anything, others might be doing that may assist… but be prepared that some issues with Beta include inconsistent stability.


#3

Also… I stopped trying to use BT/BLE a while ago so I keep forgetting about this, but in some of the older github examples there is the inclusion of this line for BT/BLE sketches.

#define BLYNK_USE_DIRECT_CONNECT

I don’t know what it does, or if it helps, but it probably can’t hurt :stuck_out_tongue_winking_eye:


#4

Thanks for the help.

Will continue to update this thread with solutions / issues as it may help someone else.

So it turns out the HM10 BLE example sends the auth token in 2 sections which prevents the app from ever connecting to it.

Using the software serial example the auth token gets sent as one string. This fixes the connection issue but brings up another problem someone may be able to help with.

New code:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  =>
  =>          USB HOWTO: http://tiny.cc/BlynkUSB
  =>

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define BLYNK_USE_DIRECT_CONNECT

#include <BlynkSimpleStream.h>
#include <AltSoftSerial.h>

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

AltSoftSerial SwSerial; // RX, TX

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

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

  // Blynk will work through SoftwareSerial
  // Do not read or write this serial manually in your sketch
  SwSerial.begin(9600);
  Blynk.config(SwSerial, auth);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

The debug console:

[0] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.4 on Arduino Nano

[90] Connecting...
[273261] >[02|00|01|00] 
[273305] >012adb1xxxxxxxxxxxxxfe8c7
[273305] Ready
[273306] Free RAM: 1103
[273327] <[11|00|01|00]f
[273354] <ver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]Arduino Nano[00]cpu[00]ATmega328P[00]con[00]Stream[00]build[00]Jan  9 2019 12:50:45[00]
[273551] <[00|00|01|00|C8]
[273667] >[00|00|01|00|C8]
[274089] <[14|00|02|00|08]
[274091] <vw[00]5[00]274
[275089] <[14|00|03|00|08]
[275090] <vw[00]5[00]275
[276089] <[14|00|04|00|08]
[276089] <vw[00]5[00]276
[277089] <[14|00|05|00|08]
[277090] <vw[00]5[00]277
[278089] <[14|00|06|00|08]
[278089] <vw[00]5[00]278

As you can see it connects and starts immediately sending data to Blynk. However, on the app it says connecting…

The HM10 module light is solid during the data transfer, but it never connects through the app. It times out and disconnects after a while.


[292089] <[14|00|17|00|08]
[292090] <vw[00]5[00]292
[292668] Heartbeat timeout: 292668, 273667, 289670
[292669] Connecting...


Is there a way to delay the data transfer until the BLE is fully connected? I can find this for wifi code but not for bluetooth.

Thanks again!


#5

I guess you could try the Blynk.begin() method instead… it is a blocking command that will not allow further processing until connected.