Blynk App Webhook Multiple Values to Thingspeak

Hello,

I have a Blynk App that needs to send 4 values to a Thingspeak channel. I manage to “post” 1 value but I need to post multiple at once so for example field1 needs the value of V1, field2 of V2 … ans so on

What is the exact syntax needed in the Blynbk App and can I do this with one webhook or do I need 4 of them to pass all 4 values ?

Thanks for your help !!

Please check the WebHook documentation - array of values is support in the body:

Use standard Blynk placeholders for Pin Value in the body or URL, for example:

https://api.thingspeak.com/update?api_key=xxxxxx&field1=/pin/

or for the body

["/pin/"]

When you need to send an array of values, you can refer to a specific index of the array value. Blynk Pin can hold an array of max 10 values:

/pin[0]/ , /pin[1]/ , /pin[2]/

Hello Yes I saw that doc. But it still is not clear to me, sorry.

Can you pls give specific code for sending V1 … V4 to Thingspeak ? What gioes in URL exactly, what goes in Body exactly ? One webhook or 4 ?

Thank You !!!

You need to collect values from all pins and write them into 1 pin (used by WebHook). Also you need to use the /pin[NUMBER]/ binding for WebHook setup:

@Tony_Knors if you have set Webhook as V1 and you need to send data for 4 fields use last screenshot from @BlynkAndroidDev but extend to pin[3] to give a 4 element array.

Then in your sketch it would be:

Blynk.virtualWrite(V1, variable1, variable2, variable3, variable4);

When I have multiple fields to populate I generally send it all as one big String including the field names etc. If you are still struggling I will dig out my Thingspeak code.

Hello,

I have added the following code to my sketch :

//Create Thingspeak String for V6
V6value="";
V6value= “&field1=”;
V6value += String(voltage_blynk);
V6value += “&field2=”;
V6value += String(current_blynk);
V6value += “&field3=”;
V6value += String(power_blynk);
V6value += “&field4=”;
V6value += String(energy_blynk);
V6value += “\r\n\r\n”;
Blynk.virtualWrite(V6, V6value);

So now in my Blynk App in V6 I have a string (example) “&field1=238.60&field2=1.20&field3=512.90&field4=5320” (without the quotes)

So in the Blynk App I now have the webhook defined as follows :

OUTPUT : V6
URL : https://api/thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX
Method : POST
Content type : application/json
Body : /pin/

Does that look OK ?

No Tony.

I think with the url you mean api.thing. not api/thing…

Blynk designed the Webhook so that a GET will also perform a POST and therefore POST is almost never needed.

Switch method to GET and remove the entry from Body.

With the correct url including API key press the Run Test button in the Webhook and it should show Result:OK.

If it doesn’t you have url or key incorrect. If you are sure it’s correct and it still gives error you might be “Blynk Blocked” for 10 failed attempts. Delete the Webhook and start again to release the block.

The Run Test is a new feature to try to avoid being Blynk Blocked and running a successful test might have the same effect as deleting the widget and starting again. @Dmitriy does a successful test remove the block?

Now that you have a successful test you need to “break” the Webhook by adding /pin/ to the end of it. When you had /pin/ it will be highlighted in green. Not for you, but sometimes an API url might end with / and therefore when you add the pin it will have a double backslash at the end of the url i.e. //pin/.

If you click Run Test again it will fail as it doesn’t understand what /pin/ means, this is ok. @Dmitriy can the test be set to exclude any /pin/ references in the url?

In my web history I have entries such as:

https://api.thingspeak.com/update?api_key=xxxxxxxx&field1=22&field2=70 so your Blynk.virtualWrite() looks ok. You don’t need to end it with the carriage return and new line stuff, “\r\n\r\n”, though. You only need “\n” if sending to Blynk Terminal.

Hello Paul, Sorry for the late reply but my PZEM died on me and had to wait for a new one.

I made the changes you proposed:

URL now reads : https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXX//pin/

V6 (Output) is as follows :

//Create Thingspeak String for V6
V6value="";
V6value= “&field1=”;
V6value += String(voltage_blynk);
V6value += “&field2=”;
V6value += String(current_blynk);
V6value += “&field3=”;
V6value += String(power_blynk);
V6value += “&field4=”;
V6value += String(energy_blynk);
// V6value += “\r\n\r\n”;
Blynk.virtualWrite(V6, V6value);

In your explanation you mention the Run Test but in my IOS Blynk App that does not seem to exist.

I have changed the method to POST
Content type = application/json
Body =

Having changed all this, I get NO update in my channel ?

Any further ideas ?

Kind regards,

Tony

@Tony_Knors I never use POST or BODY with Blynk Webhook’s.

Disable the Webhook until you have the correct details or you might be blocked by Blynk.

Get your ESP to give you the V6value and paste it into a web browser.

I notice when I do that I get a sequentially increasing number returned, 16, 17, 18 etc and if I refresh the browser too quickly I get a 0. Think this is Thingspeak’s minimum wait between API calls.

Let me know when ESP output data is working in a browser.

Sorry, I meant I changed the method to GET Paul, not POST !

I added a terminal in the app and now V6 shows (EXACTLY) :

&field1=228.90&field2=0.12&field3=16.00&field4=0.02

Actually looking at the URL I am entering in the browser it ends:

8C&field1=22&field2=61

8C is the last part of my key. So you don’t need //pin/ just /pin/ in the webhook but get it working in a browser first.

This specifically stated it wasn’t for your API call.

I added a terminal in the app and now V6 shows (EXACTLY) :

&field1=228.90&field2=0.12&field3=16.00&field4=0.02

Paste the full url into a browser.

You might need to send me your key via PM so I can unblock your Blynk account with an Android phone if iOS doesn’t have the Run Test. Or borrow an Android device from a friend.

The browser thing is not clear to me yet … So I need to set up the sketch so it also acts as a webserver, right ? May take me a few minutes :slight_smile:

I will send you the API Write key through email Paul !

No, just paste the full url for Thingspeak (as confirmed by your ESP) into Chrome, IE or Firefox and see what it returns.

All we are doing by using a real browser is testing that you have the correct URL for Thingspeak. Then we can move back to the Webhook.

Ah ok …

When I do this I get the following return : 15489 … this is the entry number

Not sure if that is your 15489th posting to Thingspeak or an error.

Probably not an error but do not use //pin/ it needs to be just /pin/ for Thingspeak.

It is not an error, it is the entry number it registered with TS … So the URL is OK