How to Connect a Particle Device to Blynk

See all the details on how to push data from your Particle device to Blynk by looking at this blog , or the documentation . Feel free to ask me any questions about using the Particle and Blynk together.

Blynk is an IoT Platform that features a no-code mobile app and web dashboard. Using the hardware agnostic low code Blynk library, you can easily connect a Particle device to Blynk and quickly build a Android or iOS mobile app and web dashboard to visualize the data sent from your Particle device. A free plan exists to try it out with no expiration. Learn more about Blynk by reviewing this blog

2 Likes

Thanks for sharing this tutorial, it’s very useful for rapidly connecting particle devices to mobile apps.

EDIT: Managed to push some data through to Blynk, bound to have more questions soon though :slight_smile:

Hi Mark -

Thank you for the post. I have been trying to follow, but without much success. I will take the blame for that as I am not much of a programmer :slight_smile:

I managed to set up the Webhook and seems to be sending data to the Webhook successfully.

I am not able to get the data into the Blynk Dashboard. I included the following in the top section of my code;

//--  Blynk declarations    --//
#define BLYNK_TEMPLATE_ID "xxxxx"
#define BLYNK_TEMPLATE_NAME "Level Sensor"
#define BLYNK_AUTH_TOKEN "xxxxx"
const char *WEBHOOK_NAME = "Blynk";

The application code already runs a couple of timers, so I assumed I could skip the Blynk timer? (might be be first mistake already)

The second bit of "Blynk code" I have is publishing to the webhook;

Particle.publish("blynk_https_get", String(level), PRIVATE);

What I am failing to understand is where I determine that this data should go to the V0 datastream in Blynk? Any prior experience with Blynk was using WiFi devices so the Blynk.write() command was the first thing I though of, but seems with the API it works differently as I am posting to the webhook?

Hope you can assist :slight_smile:

Regards, Friedl.

Hi Friedl!
Last time I got in trouble with blynk it was because the library NEEDS those lines to be declared BEFORE you include the blynk header with:

#include <blynk.h>

Unsure if this impacts the webhook, but maybe you'd like to validate that.

Source

Hi @gusgonnet -

Thank you for the info. I managed to get it working in the meantime.

I did try the library as this is what I am more accustomed to using with BLYNK, but two things made me change my mind;

  1. Their documents mention that if you are using a GSM device, you should be using the API. I might be misreading that so my apologies in advance if this is the case, but this is what I got from it.

  2. After importing the library into Workbench (quite a large library) VSC started complaining about the 'locations' of the included libraries so I started changing them one by one but it's like going down the rabbit hole so I reverted back to using the API again. So far so good :melting_face:

1 Like

Do NOT install the Blynk library. In the first paragraph of the blog, it is stated that the Blynk HTTP API will be used to communicate with Blynk.

Do NOT use the Blynk library. In the first paragraph of the blog it states that the Blynk HTTP API is used. Do not use Blynk.write(), that is part of the library. You cannot use the Blynk timer because you shouldn't be using the Blynk library.

Your Particle webhook called in Particle.publish() needs to match what was assigned to your webhook. WEBHOOK_NAME = "Blynk" is not the same as "blynk_https_get". You have the webhook working, so maybe that is okay despite what you shared?

Make sure the BLYNK_AUTH_TOKEN matches what is configured for the Blynk device you activated in the Blynk console. Make sure the Blynk datastreams are configured properly, and both the web dashboard and mobile app widgets are configured properly (you don't need to use both the web dashboard and mobile app, but one would help).

The Particle.publish() passes data to the Particle webhook. The Particle webhook reformats the data received and calls the Blynk HTTP API. The Blynk HTTP API updates the datastream values (V0, V1, ... V6). The Blynk web dashboard and mobile app will automatically update the widgets when the connected datastream values are updated.

The blog also provides information on how to call the Blynk HTTP API with your browser to verify Blynk is configured properly.

The only one piece actually needed from the 3x defines for Blynk is "BLYNK_AUTH_TOKEN". Look over the code and you will see that that is passed in the string that is sent by the Particle.publish().

// Note the escaped double quotes around the value for BLYNK_AUTH_TOKEN. 
   snprintf(data, sizeof(data), "{\"t\":\"%s\",\"v0\":%lu,\"v1\":%lu,\"pot\":%.1f,\"lat\":%f,\"lon\":%f,\"spd\":%f,\"moved\":%u}", BLYNK_AUTH_TOKEN, v0, v1, pot, lat, lon, mph, loc);

If you have a Boron and a GPS, don't hack it, set it up and use it first as provided. Then make changes.

1 Like

Hi Mark -

Thank you for your reply.

I am not using the library. I did consider it at some stage, but decided against it as per your documentation, even though there are some videos using Blynk libraries on GSM devices.

As per the screengrab, the Webhook name is Blynk and the Event is blynk_https_get, hence the reason for my code:

const char *WEBHOOK_NAME = "Blynk";

When I do the actual publish, I refer to the Event;

 Particle.publish("blynk_https_get", data, PRIVATE); 

Is this wrong? Is has been working for the last couple of days, maybe I was being lucky :slight_smile: I will change it and test.

Kind Regards,
Friedl

An Integration (webhook) has a 'Name' and an 'Event Name' fields. The 'Event Name' on must match the event name called in Particle.publish("event_name", data, PRIVATE).

The webhook 'Name' has nothing to do with Particle.publish(), so the "const char *WEBHOOK_NAME = "Blynk";" can be removed.

I suspect you correctly configured the Integration (webhook) 'Event Name' as "blynk_https_get", and your sketch is calling the same with Particle.publish(). That is why you are seeing it called successfully when you review the webhook log.

If the Particle webhook is receiving data from the Particle device via Particle.publish(), then the next step is to confirm that the Particle webhook is correctly communicating with the Blynk HTTP API. The easiest way to do that is to manually call it with a browser as discussed here. You can inspect the contents of the HTTP GET executed by the Particle webhook, so use that information and compare it to manually executing a HTTP GET in the browser. You will get a response from Blynk if using the browser if the HTTP GET is formatted incorrectly.

https://{server_address}/external/api/batch/update?token={token}&V0=0&V1=0&V2=1.5&V3=-73.8731,40.8414&V4=12.54&V5=0

Hi Mark -

Sorry, maybe I have not been clear or you maybe missed this EDIT :slight_smile:

I managed to get the webhook / api integration working and have been posting data to Blynk dashboard successfully. I will now sign up for the pro plan in order to test more thoroughly.

Kind Regards.
Friedl.