Blynk Meets Bluz

Photo of gusgonnet

Made by gusgonnet

About the project

No Blynk libraries for Bluz? No problem!

Items used in this project

Hardware components

LS1021A Internet of Things Gateway LS1021A Internet of Things Gateway x 1
Particle Photon Particle Photon this one goes in the gateway shield (BLE to WiFi gateway) x 1
2-CH I2C MUX DK GR 2-CH I2C MUX DK GR x 1

Software apps and online services

Blynk Blynk

Story

No official Blynk libraries for Bluz

Connecting my Bluz DK to Blynk was something I wanted to do for a while. There are no libraries available, at least as far as I know (here and here).

However, there are great libraries for Particle Photons (and soooo many other microcontrollers).

While I was working on this Bluz temperature sensor the other day, I realized that the project already has a Particle Photon, so the light bulb turned on in my head...

What are we going to build here?

We are going to build a Blynk app that will display data from a Bluz DK.

As a secondary goal, we will turn on and off an LED with a Blynk button.

The project we will build

From left to right: the Bluz-Blynk Gateway, the Blynk app and the Bluz wireless temperature sensor

The Blynk libraries

The Blynk libraries take care of connecting our micro controllers to the Blynk cloud (or the Blynk Server in the picture below).

Once the connection is done, we can access data from that micro controller on a Blynk app on our phones (or tablets).

We can also control pins or trigger actions from buttons in the Blynk app.

The Blynk architecture

Installing the Blynk libraries

But where? Since there are no libraries for our cherished Bluz DK, what would happen if we installed the Blynk libraries in our Particle Photon instead?

I will tell you what would happen: we would end up with a Bluz Gateway that can run Blynk and that's it. Let's call it Bluz-Blynk Gateway just for fun.

The Bluz-Blynk Gateway is born

So, is this new Bluz-Blynk Gateway aware of the variables, data or functions in our Bluz DK?

No, it isn't. The Gateway just passes information through from BLE (Bluetooth Low Energy) to WiFi, but it knows nothing about that information.

See the challenge here?

I cannot install the Blynk libraries on my Bluz DK and the Gateway is not aware of the data on my Bluz DK.

So what now? Particle events to the rescue...

Events in Particle

There is a publish-subscribe functionality on the Particle Cloud that allows us to pass information around our Particle hardware. The publish sends an event to the cloud, to which we can subscribe from another Particle microcontroller. And even better, this event can contain some data.

Since Bluz DK is part of the Particle family, we can use this events mechanism to pass data from it to the Photon and back.

Particle events between Particle hardware

To send the temperature readings from our Bluz DK we need a publish statement to be executed every now and then:

 Particle.publish("BLUZ_TEMP", temperature, PRIVATE);

And in our Bluz-Blynk Gateway's, we need to subscribe to that event in the setup() function:

 void setup()
{
    Particle.subscribe("BLUZ_TEMP", getRemoteTemp, MY_DEVICES);
}

getRemoteTemp is a function that will get called when the event is received, so we will need to declare it in our firmware.

The architecture

Our project will have a Blynk app running in our phones/tablets. This app will talk to the Blynk libraries installed in the Photon in the Bluz-Blynk Gateway. Finally, the Photon will use events to transmit information back and forth to our Bluz DK.

Just like this:

Magic means BLE, then NRF to Photon then WiFi

The Blynk app

Our app consists of two basic Blynk widgets: a Value Display and a Button. Let's use virtual pins V0 and V1 for them:

Our Blynk app

You can create it yourself or you can clone it by scanning this QR code:

QR code for our Blynk app

Remember: you need to get an Auth Token for your Blynk app and paste it in the firmware, more info here.

The Bluz DK firmware

In this firmware we need to read the thermistor and send an event with that value.

We will need to subscribe to an event that will be triggered from the Photon when we hit the button in our app.

The Bluz-Blynk Gateway firmware

Here we need to write virtual pin V0 and read virtual pin V1.

V0 will contain the temperature sent in the event coming from the Bluz DK.

When we tap the Blynk button in our app, an event will be triggered, the Bluz DK will receive it and it will turn on the onboard LED.

Never used virtual pins before? No worries, read here about how they work.

The video

Once everything is set up and flashed, the project is ready!

Check the temperature and how tapping the button turns on the Bluz onboard LED!

Troubleshooting

There is A LOT going on in this project, and of course Murphy's law dictate that anything that can go wrong will go wrong, so don't lose your hope when you hit trouble.

Have in mind that this project is based on my previous Bluz wireless temperature sensor project, so if something is not explained here, it might be that is explained there. If not, ask in the comments below.

It always helps having strong communities. The bluz community is here, the Particle community is here and the Blynk community here.

Final notes

Finally I have a Blynk app for my Bluz projects! I'm pretty happy with the result. And all this time the solution was staring me in the face...

Need help?

If you require professional help with your projects, don't hesitate to write me a line about your needs at gusgonnet@gmail.com. Thank you!

Check the rest of my projects here!

Schematics, diagrams and documents

The Bluz wireless temperature sensor

Code

Bluz DK code

Bluz-Blynk Gateway code

Credits

Photo of gusgonnet

gusgonnet

If you need professional help with a project, contact me at gusgonnet@gmail.com

   

Leave your feedback...