# Particle Mesh + Blynk Tutorial (x2!)

**URL:** <https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426>\
**Category:** Tutorials\
**Tags:** boron, argon, mesh\
**Created:** [July 29, 2019, 1:02am UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426 "2019-07-29T01:02:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaredwolff](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jaredwolff/32/18462_2.png) [@jaredwolff](https://community.particle.io/u/jaredwolff)\
**Post date:** [July 29, 2019, 1:02am UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/1 "2019-07-29T01:02:57Z")

</div>

Over the past few days I tooled around with getting Particle Mesh devices working with Blynk. There’s actually a few ways to attack it.

This is a re-post from my blog. I figure it may be super valuable for folks so I’ll share it here. 🙂

## From Particle Cloud to Blynk

 ![Particle Cloud to Blynk](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Copy_of_Mesh_to_Blynk-33d60955-97f6-47d2-a78c-97724c502154.png)

Let’s start with the most simple use case: getting data from any Particle Device to Blynk.

The Air Quality data from [Particle Squared](http://jaredwolff.com/homemade-indoor-air-quality-sensor/) is perfect for this example. So, i’ll be using that.

First let’s create a new Blynk Project

 ![Create Project in Blynk](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/IMG_2233-2a80b63a-b88b-4e58-a50b-5fc02923ae23.png)

Grab the **Auth Token** we’ll need that in a bit. You can **tap the Auth Token** to copy it to your clipboard.

Next, let’s add a **SuperChart** for this example.

 ![Add a SuperChart](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/IMG_2231-308d94bf-63f4-40a6-98e3-e49ced05c90a.png)

Configure the SuperChart to use a Virtual Pin. We don’t have access to the actual hardware pins on the device. **V0** is a good choice.

 ![Select Virtual Pin 0](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/IMG_2232-e53a0997-453e-47ee-b2d1-27a30dc12dfc.png)

To update values in Blynk, we’ll have to connect somehow. The best way is to use an **Integration** in the **Particle Console.**

In Particle Console, click the icon below the terminal icon. Then click on **New Integration.**

 ![Create new Integration in Particle Console](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Screen_Shot_2019-07-27_at_10-33b85b6e-d685-4c1a-b639-423df7b2dd85.43.37_AM.png)

Look at the example below to see how I filled everything out.

 ![Enter all the information into the New Integration Screen](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Screen_Shot_2019-07-24_at_3-a5433944-8a2a-4b0d-81b6-faa4c038bd65.27.06_PM.png)

Particle Squared uses the **Event Name** as \*\*\*\*`blob`. For other projects this may be different. **Remember:** your event name is the same as from `Particle.publish(eventName, data)`.

The **URL** is set to use the `blink-cloud.com` address. According to their API a sample URL looks like:

 ![Blink cloud write pin API call](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Screen_Shot_2019-07-24_at_4-730022d3-f758-43b3-b4cc-bb3012d22d9e.44.06_PM.png)

I’ll also include it here so it’s easier to copy

```
http://blynk-cloud.com/auth_token/update/pin?value=value

```

Replace `auth_token` with the **Auth Token** we got earlier.

Replace `pin` with the virtual pin we want to modify. In this case **V0**

Replace the `value` with the value you want to use.

We’ll reference one of the values in the Particle Squared `blob`. It’s organized like this:

```
{
  "temperature": 28.60,
  "humidity": 45.00,
  "sgp30_tvoc": 18,
  "sgp30_c02": 400,
  "bme680_temp": 27.36,
  "bme680_pres": 1012.43,
  "bme680_hum": 43.80,
  "bme680_iaq": 43.90,
  "bme680_temp_calc": 27.30,
  "bme680_hum_calc": 43.97
}

```

Particle uses [mustache templates](http://mustache.github.io/mustache.5.html). As you can see in the screenshot above, you can set `value` to `{{{temperature}}}`.

**Note:** If you’re working on your own project, it’s important to publish with JSON. As a reference the `Particle.publish` command looks like:

```
// Publish data
Particle.publish("blob", String::format("{\"temperature\":%.2f,\"humidity\":%.2f}",si7021_data.temperature, si7021_data.humidity) , PRIVATE, WITH_ACK);

```

Click the **big blue Save button** at the bottom of the screen. Then we can move on to the next step!

### Testing

Since creating our Particle Webhook Integration, it’s been publishing data to Blynk. Let’s go see if it’s working.

First, let’s go back to the Blynk app. **Hit the Play Button in the top Right** in Blynk screen.

 ![Watch data come into Blynk app](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/IMG_2234-43cebeaa-2dd4-401c-84e5-b365953f4a66.png)

If your integration has been running for a while, you should see the graph populate with data! In the case you don’t see anything, let’s check the logs.

**Go back to your integration** and **scroll towards the bottom**. We want to see if there are any errors.

Not sure what that looks like? Here’s an example of an integration with errors:

 ![Particle console integration errors](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Screen_Shot_2019-07-24_at_4-47e820b4-1636-406e-8ba1-ff22cf899478.55.36_PM.png)

You can scroll further down to investigate why the error has occurred.

 ![Investigate Particle Integration failure further](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Screen_Shot_2019-07-24_at_4-2e5843f3-1960-41a7-90b0-d80432d6ef2d.56.36_PM.png)

All the way at the bottom shows the response from the server. Depending on the service, they’ll give you information why your API call failed. In my case, I was missing values for two fields.

### Particle to Blynk is working!

You now have a basic way of publishing to a virtual pin in Blynk. There are drawbacks though. Most importantly, you’ll have to create an integration for every signal virtual pin. If you have eight readings, that means eight integrations.

Bummer.

In the next section, you’ll learn a different way to configure Blynk. Let’s go!

## Local Mesh Using Blynk Library

 ![Particle Mesh to Blynk](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Mesh_to_Blynk-0a66867b-a193-4b97-801a-b780c9a481e2.png)

Unlike the first method, we’ll be focusing on changing firmware only.

We’ll use a Argon, Boron or Ethernet Connected Xenon and one regular Xenon. For the rest of this tutorial, we’ll call these devices an “edge router”.

The Xenon will run the Particle Squared code. Instead of using `Particle.publish` we’ll be using `Mesh.publish`. This allows us to publish only to the local mesh network.

Meanwhile the edge router is listening for the message. It collects the values and then uses the Blynk API to publish to the app.

Here are the steps:

### Setup our Edge Router

Pull up the menu by pressing **Cmd+Shift+P**. Type **Install Library.**

 ![Install library in Visual Studio Code](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Screen_Shot_2019-07-28_at_4-f8149823-96fc-460f-b47e-2bcf56b670c2.50.29_PM.png)

Then enter **blynk.** The library should download if you haven’t already.

Once installed you can include the library at the top of your `.ino` file like so:

```
#include <blynk.h>

```

In our `setup()` function let’s init the Blynk library:

```
// Put initialization like pinMode and begin functions here.
Blynk.begin(auth);

```

In our `setup()` function, subscribe to the `temperature` event. The connected Xenon will generate this event.

```
// Subscribe to temperature events
Mesh.subscribe("temperature",tempHandler);

```

Define `tempHandler` like this for now:

```
// Temperature event handler for mesh
void tempHandler(const char *event, const char *data){
}

```

In the `loop()` function make sure we have `Blynk.run();`

```
// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
  Blynk.run();
}

```

Finally, for `tempHandler` we can add a debug print to monitor events. I’ve used something like this:

```
Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");

```

Particle uses this in some of their examples. It’s perfect for our purposes as well!

**Note:** make sure you have `Serial.begin()` called in your `Setup()` function!

So now we have `tempHandler` to receive data from the Xenon. The edge router can now take that data and upload it to Blynk. Let’s use the `Blynk.virtualWrite` function for this:

```
// Write the data
Blynk.virtualWrite(V0, data);

```

This will write the temperature value from a Xenon to the `V0` pin. If you used something other than V0, be sure to change that value here. (This is the same setup as the previous _Particle Cloud to Blynk_ example)

 ![DataStream V0](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/IMG_2232-e53a0997-453e-47ee-b2d1-27a30dc12dfc.png)

The final code for the edge router should look something like this. Compile a flash it to your device when you’re ready!

```
/*
 * Project blynk-argon-forwarder
 * Description: Argon Blynk forwarder for Particle Mesh. Forwards data from mesh connected devices to Blynk.
 * Author: Jared Wolff
 * Date: 7/25/2019
 */

#include <blynk.h>

char auth[] = "<ENTER YOUR AUTH KEY>";

// Temperature event handler for mesh
void tempHandler(const char *event, const char *data){
  Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");

  // Write the data
  Blynk.virtualWrite(V0, data);
}

// setup() runs once, when the device is first turned on.
void setup() {

  // Serial for debugging
  Serial.begin();

  // Put initialization like pinMode and begin functions here.
  Blynk.begin(auth);

  // Subscribe to temperature events
  Mesh.subscribe("temperature",tempHandler);

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
  Blynk.run();

}

```

Remember to set `auth` using the `AUTH TOKEN` in the Blynk app!

### Setting up a Xenon

 ![Xenon!](https://www.jaredwolff.com/two-best-ways-to-get-particle-mesh-working-with-blynk/images/Copy_of_Compose-a34be8da-a352-4a76-af8c-8c83e65efe50.png)

Create a new project. This time it will be for the Xenon capturing “temperature data.”

Let’s add a variable called `time_millis` to the top of the file. The type is `system_tick_t`. We’ll use it to create a simple delay timer for the temperature readings.

```
// Global variable to track time (used for temp sensor readings)
system_tick_t time_millis;

```

For the interval, let’s use a preprocessor define

```
#define INTERVAL_MS 2000

```

Now let’s tie those together in the `loop()` function. We’ll use an `if` statement to compare our current system time with that of the last event plus offset. If you ever need a simple timer, this is one of the best ways to do it!

```
// Check if our interval > 2000ms
  if( millis() - time_millis > INTERVAL_MS ) {
  }

```

Once we’re inside, make sure you reset `timer_millis`:

```
		//Set time to the 'current time' in millis
    time_millis = millis();

```

Then, we’ll generate the temperature value using the `random()` function. We’ll use the two parameter variant. That way we can set the minimum value and the maximum value:

```
    // Create a random number
    int rand = random(20,30);

```

Finally we’ll `Mesh.publish` the value:

```
    // Publish our "temperature" value
    Mesh.publish("temperature",String::format("%d",rand));

```

When this example runs, the temperature is broadcast to the mesh network. Then, the edge router receives it and forwards it on to Blynk!

You can flash this firmware whenever you’re ready. Here’s the full code for the Xenon so you can cross compare:

```
/*
 * Project blynk-xenon-rgb
 * Description: Recieve RGB level from connected Edge Router. Sends simiulated temperature values via mesh to the Blynk cloud.
 * Author: Jared Wolff
 * Date: 7/25/2019
 */

// How often we update the temperature
#define INTERVAL_MS 2000

// Global variable to track time (used for temp sensor readings)
system_tick_t time_millis;
// setup() runs once, when the device is first turned on.
void setup() {

  // Set time to 0
  time_millis = 0;

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {

  // Check if our interval > 2000ms
  if( millis() - time_millis > INTERVAL_MS ) {
    //Set time to the 'current time' in millis
    time_millis = millis();

    // Create a random number
    int rand = random(20,30);

    // Publish our "temperature" value
    Mesh.publish("temperature",String::format("%d",rand));

  }

}

```

### Give it a test!

Now that we’ve programmed both devices let’s get them talking to each other.

I’ve already set up the Argon with a mesh network called **8f-9.** I’ll explain how to get the Xenon connected with the CLI. You can also used the Particle App.

First, let’s connect the Xenon to USB and get it into Listening Mode. After connect, hold the **Mode button** until **blinking blue.**

Then use the CLI to set up the mesh network. First let’s get the device ID:

```
Jareds-MacBook-Pro:nrfjprog.sh jaredwolff$ particle identify
? Which device did you mean?
  /dev/tty.usbmodem146401 - Argon
❯ /dev/tty.usbmodem146101 - Xenon

```

If you have multiple devices connect, make sure you select the right one! If prompted, select a device. Your output should look something like:

```
Your device id is e00fce682d9285fbf4412345
Your system firmware version is 1.3.0-rc.1

```

We’ll need the **id** for the next step. Now, let’s run the `particle mesh` command.

```
particle mesh add <xenon id> <id of your argon, boron, etc>

```

Here’s an example below:

```
particle mesh add e00fce682d9285fbf4412345 hamster_turkey
? Enter the network password [hidden]
▄ Adding the device to the network...

```

At the end of it you’ll see:

```
Done! The device should now connect to the cloud.

```

This process is not perfect. During the `Adding the device to the network...` stage, I had to remove the Xenon using `particle mesh remove`. Then re-run the `particle mesh add` command after resetting the Argon.

Now here comes to finale.

Connect the two devices to serial using `particle serial monitor --follow`

If you have the two devices connected, `particle serial monitor` will prompt you to select:

```
Jareds-MacBook-Pro:blynk-xenon-rgb jaredwolff$ particle serial monitor --follow
Polling for available serial device...
? Which device did you mean? /dev/tty.usbmodem146101 - Xenon
Opening serial monitor for com port: "/dev/tty.usbmodem146101"
Serial monitor opened successfully:

```

**Remember:** You have to run `particle serial monitor` for each device you want to connect to.

If all is working, you’ll likely see some output from the edge router!

```
Serial monitor opened successfully:
event=temperature data=21
event=temperature data=28
event=temperature data=21
event=temperature data=27
event=temperature data=28
event=temperature data=26
event=temperature data=23
event=temperature data=26
event=temperature data=21

```

Looking at the app, the **Super Chart** should be reacting to this new data.

Compare the last value in the command line to the last on the chart? Do they match? If so, you made it to the end of this example!

## Conclusion

In this tutorial you’ve learned how to forward Particle Cloud data to Blynk. You’ve also learned how to do the same using a Particle Argon, Boron or ethernet connected Xenon. Awe yea. 🕶👍

Now that you have the tools to Blink-ify your Particle Mesh powered projects, it’s time to get to work!

By the way, this post is an excerpt from my upcoming _Ultimate Guide to Particle Mesh_. I’ll be sharing more exclusive content with my mailing list as it get’s closer to launch. [You can sign up here for updates.](https://jaredwolff.com/the-ultimate-guide-to-particle-mesh/)

---

<div class="post-metadata">

**Author:** ![gusgonnet](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gusgonnet/32/27491_2.png) [@gusgonnet](https://community.particle.io/u/gusgonnet)\
**Post date:** [August 1, 2019, 2:15am UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/2 "2019-08-01T02:15:15Z")

</div>

nice tutorial, Jared!  
I did not know blynk had an API that we can shoot from a webhook.  
If I got it right, this way we do not need to use the Blynk library in our projects, when all is needed is monitoring. Cool!  
Thank you,  
Gustavo.

---

<div class="post-metadata">

**Author:** ![jaredwolff](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jaredwolff/32/18462_2.png) [@jaredwolff](https://community.particle.io/u/jaredwolff)\
**Post date:** [August 1, 2019, 2:49am UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/3 "2019-08-01T02:49:30Z")

</div>

Thanks Gustavo!

The only caveat is that Blynk doesn’t know when your device is “Online” It may prevent you from activating certain widgets (buttons, RGB zebra, etc). I’m sure some type of keep alive endpoint exists, it’s just not documented. 😉

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 13, 2020, 6:26pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/4 "2020-01-13T18:26:26Z")

</div>

HI @jaredwolff

Would you mind helping me getting a Webhook set up to send data to Blynk? Apologies for the trivial question on the back of such a good tutorial, but I am very new to this 🙂

I will gladly send through my code if you can find the time to assist.

Many thanks!  
Friedl.

---

<div class="post-metadata">

**Author:** ![jaredwolff](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jaredwolff/32/18462_2.png) [@jaredwolff](https://community.particle.io/u/jaredwolff)\
**Post date:** [January 13, 2020, 6:56pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/5 "2020-01-13T18:56:32Z")

</div>

Hi @friedl_1977

If you have specific questions or error messages i’d be happy to work through them here. If it’s something you’d rather not share you can email me [hello@jaredwolff.com](mailto:hello@jaredwolff.com)

Jared

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 13, 2020, 7:06pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/6 "2020-01-13T19:06:29Z")

</div>

HI @jaredwolff

Thanks for the prompt response. I have been all over the place trying to find a good and easy to use ‘Dashboard’. I have been using Ubidots so far, but the lack of a scheduler widget is problematic in this case, hence me looking at Blynk 🙂

No problem, I will post it here, it might help someone else as well.

```auto
#include <blynk.h>
#include <cmath>

char auth[] = "my_secret_code";

// Establish Ubidots Webhook
const char* WEBHOOK_NAME = "Amp";       
   
#define CURRENT_SENSOR A5    
    
int led = D7;

int redPin = D3;       
int greenPin = D1;    
int bluePin = D2;

int i = 0;
 
float amplitude_current; // Float amplitude current
float effective_value; // Float effective current

void setup() {

    Serial.begin(115200);
    // Subscribe to the integration response event
    Blynk.begin(auth);
    
    pinMode(led, OUTPUT);
    
    pinMode(redPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    
}

void pins_init()
{
    pinMode(CURRENT_SENSOR, INPUT);
}

const int Resolution = 3277; //4095 
const float FullScaleAmps = 40.0;
const int ZeroValue = 2047; //2047 //2100
const float MilliVoltsPerAmp = float(Resolution) / FullScaleAmps;

float getRms()
{
    const int numSamples = 1000;
    // The integer value (between 0 and 4095) that we read from the sensor
    int sensorValue;
    // The timestamp of the "previous" sample
    int ts_prev = 0;
    // The difference between the "present" and "previous" timestamps
    int ts_delta = 0;
    // We keep the value of the first timestamp to use in the final
    // averaging step. Alternatively we could simply sum up all the
    // deltas from the start to the end.
    int ts_first = 0;
    // The integaer value of the "prevous" sample.
    int value_prev = 0;
    // Total elapsed time for the 1000 samples.
    int elapsedTime = 0;
    // The timestamp as read from the sensor.
    uint32_t timeStamp = 0;
    // The measured values (integers) are converted to floats for the calculation.
    float val_now = 0.0;
    float val_prev = 0.0;
    float accum = 0.0;
    float avgValue = 0.0;
    float rms = 0.0;
    
    for (int k=0; k<numSamples; k++) {
        sensorValue = analogRead(CURRENT_SENSOR);
        timeStamp = micros();
        if (ts_prev > 0) {
            ts_delta = timeStamp - ts_prev;
            if (ts_delta < 0) {
                // If we detect an overflow we return an invalid RMS current value immediately
                return -1;
            } else {
                val_now = (float(sensorValue) - float(ZeroValue)) / MilliVoltsPerAmp;
                val_prev = (float(value_prev) - float(ZeroValue)) / MilliVoltsPerAmp;
                accum += 0.5 * ts_delta * (val_now*val_now + val_prev*val_prev);
            }
        } else {
            // This is only executed the first time round the loop
            ts_first = timeStamp;
        }
        ts_prev = timeStamp;
        value_prev = sensorValue;
    }
  
    elapsedTime = timeStamp - ts_first;
    avgValue = accum / float(elapsedTime);
    rms = sqrt(avgValue);
    return rms;
}

int debug;

void loop() {
    
    Blynk.run();

    float sensor_value = getRms();
 
  if (sensor_value >= 0) {

     char data[16];
     snprintf(data, sizeof(data), "%.3f", sensor_value);
     Particle.publish("Amp", data, PRIVATE); 
     
     delay(10000);
  
    } else {
      
     System.reset(); 
     
           }
}

```

In a nutshell, I managed to get data to Blynk from the Webhooks, but only if I use a content value such as “1” or “2” as the VALUE under query parameters.

I suppose I can try to use the method of sending data to Blynk using their “timer method” but I prefer Webhooks.

Thanks again!!

---

<div class="post-metadata">

**Author:** ![jaredwolff](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jaredwolff/32/18462_2.png) [@jaredwolff](https://community.particle.io/u/jaredwolff)\
**Post date:** [January 13, 2020, 7:20pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/7 "2020-01-13T19:20:53Z")

</div>

Hey @friedl_1977 thanks for sharing. A few questions:

What type of device are you using? (Xenon, Argon, Boron?)  
Are you having trouble receiving or sending data to Blynk? Can you highlight where you’re having trouble in the code?

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 13, 2020, 7:32pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/8 "2020-01-13T19:32:20Z")

</div>

HI @jaredwolff

- I am using Photon on this particular product as I am sending “live” data. Boron would cost a fortune to run 😃
- Having rouble sending data via Virtual pin and Webhooks from Photon to Blynk
- I presume my problem lies in the Webhooks setup as this code publishes successfully to Particle Cloud as well as Ubidots.

Here are some screen grabs on my Webhooks setup:

 ![27](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/4/1/4148d041d6d5875da4d6433913df1677ca99695b.png)

 ![34](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/2/8265e7023bf9c9820143221c593c8be10d3176f2.png)

If it is indeed in my code, I suspect in the Particle.publish statement:

```auto
if (sensor_value >= 0) {

     char data[16];
     snprintf(data, sizeof(data), "%.3f", sensor_value);
     Particle.publish("Amp", data, PRIVATE); 

```

but as I mentioned, this publishes successfully everywhere else.

Below is another screen grab from te Event monitor under the Webhooks section.

 ![36](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/d/2/d2955a21e7f9008c0e32db4809c4d15b87ff5b52.png)

Thanks

---

<div class="post-metadata">

**Author:** ![jaredwolff](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jaredwolff/32/18462_2.png) [@jaredwolff](https://community.particle.io/u/jaredwolff)\
**Post date:** [January 13, 2020, 8:05pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/9 "2020-01-13T20:05:21Z")

</div>

Ahh ok,

So for writing using the Blynk API, you need to call

`Blynk.virtualWrite(11, <your value>);`

Where the first param is the virtual pin and the second is the value you’re trying to push. This should work a-ok on your Photon.

Make sure for your different elements, that you select the virtual pin. (note that when using `virtualWrite` you don’t have to include the `V`)

 ![IMG_8B2006079422-1](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/1/5/15d4e842cd13526fde2a1edb1fcc3e87073fb862.jpeg)

If you’re trying to publish with a webhook, when you do your `Particle.publish` you need to make sure the object is a JSON string. So instead you’ll have to publish something like:

```auto
Particle.publish("blob", String::format("{\"data\":%.3f}", sensor_value) , PRIVATE, WITH_ACK);

```

That way your data will get picked up and replaced into the `{{{data}}}` mustache template

Hope that helps!

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 13, 2020, 8:09pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/10 "2020-01-13T20:09:20Z")

</div>

HI @jaredwolff -

GREAT Thanks. Let me make the changes, I will let you know. Might need one last bit of help in constructing the JSON string, but let me try first 🙂

Regards,  
Friedl.

EDIT:

SOLVED, thanks!!!

 ![55](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/0/803023f3e200e39e92cb5820998c994f1adf9d9c.png)

---

<div class="post-metadata">

**Author:** ![jaredwolff](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jaredwolff/32/18462_2.png) [@jaredwolff](https://community.particle.io/u/jaredwolff)\
**Post date:** [January 20, 2020, 6:45pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/11 "2020-01-20T18:45:04Z")

</div>

That’s awesome @friedl_1977! Glad you got it working.

---

<div class="post-metadata">

**Author:** ![gusgonnet](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gusgonnet/32/27491_2.png) [@gusgonnet](https://community.particle.io/u/gusgonnet)\
**Post date:** [January 21, 2020, 3:00am UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/12 "2020-01-21T03:00:57Z")

</div>

> [@friedl\_1977](#):
>
> I have been using Ubidots so far, but the lack of a scheduler widget is problematic in this case, hence me looking at Blynk 🙂

Hi Friedl,  
I got curious about that scheduler widget that you are missing in Ubidots.  
What is the function of this scheduler and why do you need one? (out of curiosity)  
Thanks,  
Gustavo.

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 21, 2020, 5:29am UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/13 "2020-01-21T05:29:25Z")

</div>

HI @gusgonnet -

Thanks for the interest 🙂

In this case, it is not to launch a rocket to Mars (unfortunately as that would be awesome) but rather something simple such as triggering a relay for;

- Various Specific start times i.e. tie of day
- Various days of the week
- Set ‘run’ times.

I will be posting this project soon, just want to solve the dashboard issue. Was going to use Blynk, but at $2000 p/a it is a bit too pricey.

I tried a workaround in Ubidots using a combinations of some variables and events to work together but after a couple of discussions with support realised it won’t work as the events won’t trigger again unless it went back to “normal” first as explained here:

 ![](https://downloads.intercomcdn.com/i/o/69057305/11a2e07cd762a12e21ecf214/QfJVu4gQaEfgQxAixHB3JO-B4cMfSWToOsdLieysTTn1KMmI3haD0e7DYxyHS0Wd0QbnvVBaBwoak84D-BU5k5tp2yhg169rH1YzhxMtGDUK7ku8SI-o3HgrZUYHyBR1T8y-TSc)

**At closer look here:**

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/e/8/e8afdb05f3e2736ef9d308f364493ab95010d81c.png)

I thought it might work, but not sure whether the “Monday event” will trigger again nor does it allow you to set the “run time” of whatever you are trying to control. In addition to this, I would not want to relay on a client to edit events in order to use the even scheduler 😄 Lastly, I tried modifying the following widget as suggested by Ubidots support, I managed to het something done but it seems in the end you still need device specific hardware to make this work, or some serious coding skills.

> **[Operate STREGA's schedulers on Ubidots](https://help.ubidots.com/en/articles/2844113-operate-strega-s-schedulers-on-ubidots)**
>
> Learn how to program automatic operation of the STREGA schedulers through Ubidots Dashboard

In my case, the client will be controlling and monitoring pumps. I also realised I will have to improve and rely more on code running on the Particle device itself and less on Dashboard for doing calculations as the Synthetic variable seems relatively slow and will not suffice for live data streaming, even with fairly simple Watt calculations.

Hope this answers your question.

Kind Regards,  
Friedl.

---

<div class="post-metadata">

**Author:** ![gusgonnet](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gusgonnet/32/27491_2.png) [@gusgonnet](https://community.particle.io/u/gusgonnet)\
**Post date:** [January 23, 2020, 1:07pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/14 "2020-01-23T13:07:08Z")

</div>

I see, thank you for your explanation!  
I got in trouble in a similar way once with Ubidots, and at the end the workaround I was able to negotiate with Ubidots Support was to clear the variable once the alarm is triggered.  
So to say, I had an integer variable **alarm** that had 3 levels of alarm: 0, 1 and 2.

alarm is 0 =\> no alarm triggered in ubidots  
if alarm goes to 1 =\> alarm event triggered in ubidots, another event (in ubidots) that clears the alarm (sets to 0)  
if alarm goes to 2 =\> alarm event triggered in ubidots, another event (in ubidots) that clears the alarm (sets to 0)

and so on. Otherwise like you observed, once the alarm was set to 1, if set again to 1 (by the particle device) was not triggering an extra alarm (and the user would have missed a notification email, for instance).

I think there was a schedule lib around for particle devices, would that help in your case?

An upside for the timings on your case being controlled by the device itself and not the cloud is more reliability, since it does not depend on any connection to a cloud (ubidots, in your case) for the schedule to work.

A downside would be more C work 🙂  
Gustavo.

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 23, 2020, 3:41pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/15 "2020-01-23T15:41:03Z")

</div>

Hi @gusgonnet -

> [@gusgonnet](#):
>
> So to say, I had an integer variable **alarm** that had 3 levels of alarm: 0, 1 and 2.

 ![41](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/5/2/5229be228a69946bff087e75ceb5572d874b05ca.png)

First I created a Control Variable and Event. If this variable is set to 1, the Event tigers a web hook posting 1 to the Photon which in turn sets digitalPin HIGH. If the Control variable is set to 0, the event publishes 0 via web hook to Photon setting the pin LOW.

From here I now have three variables for scheduling days of the week (to simplify and avoid ending up with 1000's of events);

- Even's
- Odd's
- All

 ![31](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/9/8926ab4cb371724ba816ec191175680157b4f2c5.png)

Each variable is linked to a button on the dashboard to activate the appropriate one and setting the variable value to 1 if activated. From here I created 3 events, one for each variable. Each of these variables are then set to run a specific time of day, on either ODD, EVEN or ALL DAYS.

Lastly I have a RESET event. This event in essence determines the runtime of each scheduled event. After the time expires, the CONTROL Variable is set to 0.

 ![47](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/4/f/4fa17b8fb3eea85a10fce494454926e0fe610292.png)

I have only tested two consecutive days, so far so good, but I am sure I will run into some problems somewhere as this seem a very clumsy way to run a scheduler.

Honestly, Blynk seems like the better option for this and thanks to @jaredwolff I got going in couple of minutes, it is just too costly ($2000 pa), I did not have a great time in their forum and I am not comfortable with the way Blynk requires you to keep _**Void loop()**_ section clear of anything. I get it is the way it works and they have their reasons, but I am quite new to C++ so this feels like an unnecessary curveball for me at this stage 🤣

Thanks again!

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 24, 2020, 12:47pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/16 "2020-01-24T12:47:56Z")

</div>

Hi @gusgonnet

Gave it one more go in Ubidots before I take on C... 🤯

> [@gusgonnet](#):
>
> alarm is 0 =\> no alarm triggered in ubidots  
> if alarm goes to 1 =\> alarm event triggered in ubidots, another event (in ubidots) that clears the alarm (sets to 0)  
> if alarm goes to 2 =\> alarm event triggered in ubidots, another event (in ubidots) that clears the alarm (sets to 0)

Following your advice I (think) it is working with the odd exception of the webhook triggering but the Photon missing the payload for some reason. My concern is that the times it did miss, it was without fail, when tuning the pump off 😲

I think best will be to set the schedule in Ubidots, but leave the rest up to the Photon. This way, Ubidots can only send updated info the the Photon (or suppose Photon should rather check daily). My C is not nearly good enough to make this work though, so this should be fun 😆

Thanks again.  
Friedl

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 26, 2020, 4:18pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/17 "2020-01-26T16:18:54Z")

</div>

hi @jaredwolff

Just a quick question if you don’t mind. Am I correct in saying that if I follow the process above (using Webhooks sending data to Blynk rather thank Blynk timers and keeping the _**Void loop()**_ clean) I will have to create a Webhook for each device as the Webhook contains the Blynk Authorisation code. Is this correct?

Apologies for the trivial question. Finding an affordable dashboard solution is proving more difficult than I would have thought 🤣

My understanding is that if you opt for the $6000 license with Blynk this will not be a problem as the app you will be publishing will be handling the AUTH tokens, but $6k is quite a bit of money, especially due to our weak currency 🙈

Many thanks!  
Friedl.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 26, 2020, 4:35pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/18 "2020-01-26T16:35:11Z")

</div>

> [@friedl\_1977](#):
>
> I will have to create a Webhook for each device as the Webhook contains the Blynk Authorisation code. Is this correct?

No, you can pass in the authorisation code via the publish event

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [January 26, 2020, 5:27pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/19 "2020-01-26T17:27:15Z")

</div>

@ScruffR

Great news, thanks!! Let me see if I can figure this out 😄

To start, do I remove it from the URL in the webhook correct?

 ![01](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/d/3db905cc867ddf09137312e07394b353b0aedf15.png)

Many thanks,  
Friedl.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 26, 2020, 5:33pm UTC](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426/20 "2020-01-26T17:33:32Z")

</div>

> [@friedl\_1977](#):
>
> To start, do I remove it from the URL in the webhook correct?

Not quite. You don't remove it but replace it with a handlebars variable (e.g. `{{authCode}}`) which you then provide in your event data as JSON field like `"{ ...<otherFields> ..., \"authCode\":\"<yourCodeHere>\" }"`.

[Next page](https://community.particle.io/t/particle-mesh-blynk-tutorial-x2/51426.md?page=2)
