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 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.
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.
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 ParticleThere 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.
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 architectureOur 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:
Our app consists of two basic Blynk widgets: a Value Display and a Button. Let's use virtual pins V0 and V1 for them:
You can create it yourself or you can clone it by scanning this QR code:
Remember: you need to get an Auth Token for your Blynk app and paste it in the firmware, more info here.
The Bluz DK firmwareIn 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 firmwareHere 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 videoOnce everything is set up and flashed, the project is ready!
TroubleshootingThere 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 notesFinally 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!
Comments