Using Blynk with Particle Mesh Devices

If you are using Particle Mesh devices with Blynk here are a few things that might help to know…

First, Blynk works great with the Boron and Argon. The Xenon is where you may run into a stumbling block. The Xenon will communicate with the mesh’s gateway and other devices in the same mesh network but they can not connect directly to Blynk. This is due to network protocol limitations over mesh networking. It will however work if you are using an Ethernet Featherwing on the Xenon.

More info about that here - Mesh Network Protocol

And here - udp-and-tcp-in-mesh

The simple solution is to setup your mesh gateway with Blynk and have it Publish events that the Xenon subscribes to. Being the Xenon can communicate with the Particle cloud with no problem it will be able to Publish and Subscribe. As well using cloud functions and variables that the gateway device can take to Blynk.

Now what would be REALLY cool is if Particle had their own dashboards of widgets. :wink:


Here is a demo for using Blynk with Particle Mesh. This code here you will flash to an Argon or a Boron. Do not flash this code to the Xenon. This demo will toggle the built-in LED on digital pin 7 on for 5 seconds then turn it off on both the mesh gateway and the Xenon. The Xenon code for this demo is posted separately. I know there is probably a better way to code this but this works ok.

/* Demo of using Blynk to toggle the built-in LED on and off on a Xenon in a mesh network.  As well as the Argon.
 The gateway device is a Particle Argon or Boron.  This is the code that is flashed to the Argon or Boron.
 The Argon or Boron is the only device in the network communicating with Blynk.

 By: Tim Gardner     Date: 5/18/19
 This is based off the Particle Blynk library example:

  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:
    Sketch generator: 
    Blynk community:  
    Follow us:        

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

  No coding required for direct digital/analog pin operations!
  We are working with Particle Publish/Subscribe so we need some code.
  In the Blynk App on your phone, add a momentary button tied to digital pin 7 in the project.

#include <blynk.h>  // Make sure you include this library or else it won't work!

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

void setup()

    pinMode (D7, OUTPUT);  // D7 is tied to the built-in LED.
    Blynk.begin("Your-Auth-Code-Goes-Here");   // Yout Blynk auth code goes here.
    delay(2000); // 2 second delay.

void loop()
{;  // Start Blynk running.

    if (digitalRead(D7) == HIGH) // If Blynk button for the LED is pressed then do the following...
       Particle.publish("LED", "On");  //  Publish to particle cloud so the LED turns on
       delay(5000);  // Wait 5 seconds then turn the LED off 
       Particle.publish("LED", "Off");  // Publish to the cloud so LED turns off
           // Nothing else to do here for now.


This is the Blynk demo code to flash to the Xenon. Do not flash this to an Argon or Boron. I know there are different and/or better ways to do this but this is a quick and easy way that works.

Demo code using Particle Xenon with Blynk in a mesh network.  Blynk does not run on the Xenon.
Blynk runs on the gateway device - either a Boron or Argon device.
The Xenon with respond and react to events published in the particle cloud.  Or variables also.
The Blynk code goes on the Argon or Boron and the Blynk app will only communicate with it.

By: Tim Gardner   Date: 5/18/19

It connects to the Particle Cloud to watch for Published event and data LED On or Off
It connects to the Argon working as the Gateway and it connects to Blynk for controlling from mobile device.

void setup() {

pinMode (D7, OUTPUT);
Particle.subscribe("LED", myHandler); // Subscribe to the LED event in the particle cloud.
}                                              // myHandler is the function below of what to do if the event is published.

void loop() 
              // Nothing to do here right now.

void myHandler(const char *event, const char *data)
  /* Particle.subscribe handlers are void functions, which means they don't return anything.
  They take two variables-- the name of your event, and any data that goes along with your event.
  In this case, the event will be "LED" and the data will be "On" or "Off".

  Since the input here is a char, we can't do

  chars just don't play that way. Instead we're going to strcmp(), which compares two chars.
  If they are the same, strcmp will return 0.

  if (strcmp(data,"On")==0) {
    // If the button is pushed in the Blynk App, turn on the LED
  else if (strcmp(data,"Off")==0) {
    // If the button is off, turn off the LED
    digitalWrite(D7, LOW);
  else {
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.