Cannot bypass Blynk connect

Hi all. I have checked other threads but can’t seem to find a definitive answer.

I have an Arduino Mega, D1307RTC and an HMSoft bluetooth module.

I am trying to create a project but failing at the initial stages of building. I used to use it with an ethernet shield always connected to the internet but cannot use that now hence the bluetooth.

In a nut shell I want to create a sketch that turns a pump…

  • On and off at a specific time
  • Have it run for a specific time
  • Turn the whole timer part on and off
  • Be able to turn the pump on manually via a toggle button.

I want the above to work using Blynk and a mixture of time input, number input and buttons by connecting via bluetooth on my phone. However, I want to be able to disconnect from it once set and still have it run.

Of course I am having the dreaded issue whereby the sketch will not run when I’m not connected to it via the BT and gets stuck at the Blynk.begin(Serial, auth); and won’t progress until its connected.

Is it possible or should I quit now?

Many thanks,
Steve.

Actually, I think I may have cracked it but wanted you’re thoughts. I have just found something online and tried it and it ‘appears’ to work…

#define BLYNK_PRINT Serial // Enables Serial Monitor
#define BLYNK_USE_DIRECT_CONNECT

#include <SPI.h>
#include <BlynkSimpleSerialBLE.h>

char auth[] = "oCcaiR*******************************";

void setup()
{
  Serial.println("checkConnection 101");
  Serial.begin(9600);
  Serial.println("checkConnection 102");

  Blynk.config(Serial, auth);
  Serial.println("checkConnection 103");
}

void loop()
{
  Blynk.run();
  Serial.println("loop");
}

It seems to go straight to the loop section if not connected to BT, but then when I connect it almost instantly connects and functions (albeit the function is only to turn the on board led on and off) but appears to work.

Does anyone envisage any issues with this?

Hi Steve,
First of all, you wont be able to control the device from your Blynk app unless you are connected via Bluetooth. You also wont be able to monitor the status of the device or the pump unless its connected via Bluetooth, so the Blynk functionality will be ;limited to when you are within a few metres of the device.

Also, using your serial port for both the connection to your Bluetooth module and for debug messages is doomed to failure. The debug messages will be seen by the BT module and will be misunderstood and cause Blynk disconnections. A bit like trying to have a sensible conversation on an old Party Line (if you’re old enough to remember those :wink:)

I’m guessing that there is no WiFi available in this location, and that you don’t want to go down the GPRS route?

Pete.

Hi Peter.

You mean 0891 FIFTY FIFTY FIFTY!!! lol.

To be fair, I don’t need to be connected to it all the time. It’s basically a dosing pump system for a fish tank that will be set to come on and deliver and specific amount of millilitres of liquid into my tank every day. So I only need to connect now and again to adjust the time and maybe the dosage.

To be honest, for the amount of time that I will be adjusting it, I could just write it all in the sketch without Blynk and then just plug the laptop in to make changes, but I’ve got all this kit now and want to challenge myself.

I am by no means a coder. I learned everything myself and my old ethernet aquarium controller that I built (around 6000 lines of code) was self taught and took me 18 months to do lol. It wasn’t the cleanest code but it worked. Unfortunately my hardware failed so I’ve ripped it out and making this smaller project.

The serial outputs were just literally to find where it was halting. I normally delete them all after I know it works.

I do remember there was a ‘debug’ way where you could turn them on and off but just removing the // from a debug tag at the top but I can’t remember what it was now. :grin:

No, not that type of party line, the one where you and the neighbours shared one phone line and took it in turns to talk :rofl:

As you’re using a Mega, which has 3 serial ports, then why not connect your BT module to Serial2 or Serial3 ?

Pete.

Exactly HOW old are you Pete!? :joy:

That sounds amazing Pete, if I knew how to do it, I would lol.

Just turned 60 actually, but I do remember my grandmother still had had a party line when I was a kid and it could get very confusing when she rang us. She was a bit batty by then anyway, but trying to have a conversation with her when her neighbour was chatting away to someone about the price of fish at the same time was more than she could cope with! :crazy_face:

Pete.

2 Likes

It looks pretty straight forward I think. There is an example in one of the links and pin numbers in the other:

https://www.arduino.cc/en/pmwiki.php?n=Reference/serial

In the top right of this photo you’ll see pins 16 and 17 labelled as Tx2 and Rx2

Connect your Bluetooth module to these pins (Tx to Rx and Rx to Tx)

Add this line…

  Serial2.begin(9600);

and change this line:

 Blynk.config(Serial, auth);

to

 Blynk.config(Serial2, auth);

Pete.

Oh right. That simple? I’ll do that in the morning then. Thank you very much for the help.

Did it work?

It did indeed. I was having to take the bluetooth module out of the Arduino every time I wanted to upload the sketch, now I don’t have to. Works great.

I have another ask…
Is there a way of syncing the buttons, time inputs and number inputs on my app when I connect to the Arduino via bluetooth?

When I open the app and it connects, I need it to refresh the values on the app from the hardware but can’t figure it out.

I mean I could put in a 'sync; button the app that will pull the data, but I’d rather it be automatic.

Ok so I have one thing working… here’s my code…

#define BLYNK_PRINT Serial 
#define BLYNK_USE_DIRECT_CONNECT

#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include <SPI.h>
#include <BlynkSimpleSerialBLE.h>
#include <EEPROM.h>


char auth[] = "eC7EkzCrBfdy************************";


WidgetLCD lcd(V14);

BLYNK_APP_CONNECTED() 
{
  Serial.println("App Connected.");
}

BLYNK_APP_DISCONNECTED() 
{
  Serial.println("App Disconnected.");
}

void setup() 
{
  Serial.begin(9600);
  Serial2.begin(9600);  
  Blynk.config(Serial2, auth);
}

void loop() 
{
  Blynk.run();
  tmElements_t tm;

Now if I add this to the bottom… I get the serial print, but only the FIRST time I connect after resetting the Arduino. If I then close the app and reopen, it does not find it again.

BLYNK_CONNECTED()
        {
          Blynk.syncAll();
          Serial.println("BLYNK CONNECTED SYNC");
        }

If I put the following in instead, I get absolutely nothing…

BLYNK_APP_CONNECTED() 
    {
      Serial.println("App Connected.");
    }

BLYNK_APP_DISCONNECTED() 
{
  Serial.println("App Disconnected.");
}

I do have the checkbox on the settings on for ‘notify devices when app connected’.

I’m not sure what the limitations are with Bluetooth, but I know that some things that work perfectly when using WiFi/Ethernet are limited with BT, because of the nature of the connection (the device cant talk directly to the server, it needs the phone connected, so some server-based things synch as synchronisation and off-line alerts may not work the same way).

Is there no way of providing internet access in this location, preferably via WiFi?

Pete.

Hi Peter. Thanks again for your reply.

I do have a network shield but space in the box is limited and I don’t really have a network port that close. It’s not much of a big deal if I have to add a sync button to pull the values from the Arduino and refresh the data on the app, just thought I’d ask in case there was an easy fix.

I thought that the app on my phone would at least pull the last known data on the Blynk servers though but it’s just opening up as blank widgets.

I know it’s offline, I’m at work, but it does that even when I’m at home and connected via BT

Have you thought about dumping the Mega and going for a NodeMCU connected via WiFi instead, or if you’re committed to the Mega then add an ESP-01 as a WiFi adapter, which would be smaller than the BT module.

Pete.

Hi Pete. I wanted to try and make it with what I’ve got but I’ll have a look at them online.

Shouldnt the app sync with the cloud when I open it anyway? Because it’s not.

It’s complicated with BT.

Normally it’s device>>cloud server >>App but with BT it’s device>>App>>cloud server and the cloud server bit is (I think) optional depending on connectivity and the use of Direct Connect.

That’s why WiFi is a better option in my opinion.

Pete.