Webhook format issues

Hi,
I’m trying to send some data (an array and an integer) to PushingBox so I can plot it in a Google Spreadsheet. I have done this without using Blynk with the following code:

if (client.connect(server, 80))
{
char sheetMsg[100]
sprintf(sheetMsg, “GET /pushingbox?devid=devid&char1=%s&int1=%d HTTP/1.1”,
char1, int1);
client.println(sheetMsg);
client.println(“Host: api.pushingbox.com”);
client.println(“Connection: close”);
client.println();
delay(10000);
client.stop();
}

I just found out about the webhook widget on Blynk and I would prefer to use that instead of the previously used code. My only problem is converting this code to the right format. This is what I converted it to:

  char sheetMsg[100];
  sprintf(sheetMsg, "http://api.pushingbox.com/pushingbox? 
  devid=devid&char1=%s&int1=%d", char1, int1);
  Blynk.virtualWrite(V0, sheetMsg);

I also defined V0 up top like in the example script. In the app I just copied the url. This doesn’t work. What am I doing wrong?

Thanks in advance, Ward

@ward it’s covered in the docs at http://docs.blynk.cc/#widgets-other-webhook

In the Webhook use:

http://api.pushingbox.com/pushingbox?devid=devid&char1=/pin[0]/&int1=/pin[1]/

Then send two array values to V0 for char1 and int1.

Blynk.virtualWrite(V0, char1, int1);

1 Like

@Costas Thanks for your reply! I have tested it now and it still doesn’t work. I used the virtualWrite you suggested and this is what I use in my app:

Output: V0
URL: http://api.pushingbox.com/pushingbox?devid=v228449BBD7B83A9&char1=%/pin[0]/&int1=/pin[1]/
Method: PUT
Content type: text/plan

I’m not sure about the method but I have tested both PUT and GET and neither work. Am i missing some code or am I doing something wrong?

You started the thread with GET so stick with it, no reason to switch to PUT.
You don’t need the % in the URL.
If it’s still failing after these changes ensure char1 and int1 are displayed correctly in Serial Monitor at the point you are sending them to the webhook.
Also paste your code extract that covers the array variables.

@costas I’m still having issues. This is the code that covers the array variables (owners is char1 and freeSpots is int1):

> char tags[7][5] = {"6196", "6753", "5655", "69EC", "9FFC"};
> char owners[7][5] = {"per1", "per2", "per3", "per4", "per5"};
> int freeSpots = 5;
> char lastTag[5];
> 
> int i = 0;
> while (i < 5)
> {
>    if (strcmp(tags[i], lastTag) == 0)
>    {
>       terminal.print(owners[i]);
>       Blynk.virtualWrite(V0, owners[i], freeSpots);
>       Blynk.run();
>    }
>    i++;
> }
> i = 0;

Also, do I need to define virtual pin 0 at the top of my program for the webhook function?

No the virtual pins are part of the Blynk library.
What does Serial Monitor show if you change the code to this:

int i = 0;
while (i < 5)
{
    if (strcmp(tags[i], lastTag) == 0)
    {
       terminal.print(owners[i]);
       //Blynk.virtualWrite(V0, owners[i], freeSpots);
       //Blynk.run();
       Serial.println(owners[i]);
       Serial.println(freeSpots);
    }
    i++;
 }
1 Like

The serial monitor prints the correct value of the owners array and the correct freeSpots value too.

Paste the exact details from Serial Monitor based on the extract provided i.e. without the virtualWrite() and Blynk.run().

1 Like

Per3
4

The lastTag value comes from a RFID system.

@Ward try changing the GET url to this:

http://api.pushingbox.com/pushingbox?devid=v228449BBD7B83A9&char1=/pin/

And in virtualWrite() use:

Blynk.virtualWrite(V0, String(owners[i]) + String("&int1=") + String(freeSpots));

I don’t use Pushingbox but sending that virtualWrite() does send an email to my test pushingbox email address of “Congratulation you just run your first scenario”.

For reference it looks like text/plain and application/json both work for Content Type in the webhook widget.

Out of interest, other than emailing pictures to yourself what else does pushing box do?
How are the two parameters actually used?

1 Like

OK I see it sends tweets and push messages etc together with bespoke url’s.

@Ward same question though with the parameters? Is it for a bespoke api?

Changing the url doesn’t fix the problem. I’m using Pushingbox together with a Google Script to send both variables to a Google Spreadsheet together with the time of sending.
Edit: is there any input in the ‘Body’ section of the app required?

Nothing required in the body and GET.
The url I provided is certainly sending the details to pushingbox.
Not sure how you are doing the Google stuff but I did post some details of how to send directly from Blynk to Google Sheets but it was quite some time ago.

1 Like

The problem lies with sending the data to Pushingbox, on the dashboard, I can see that no data is being sent to it. Also was that post you mentioned a post from you or a reply to a question?

Why is my dashboard being updated then?

Can you perhaps provide me the Url you are sending to Pushingbox so I can test it?

This is the sketch that shows the pushingbox dashboard has updated and confirmed with an email.
URL syntax is shown in the sketch and I am using a Blynk button to trigger the webhook call.

/*************************************************************
 Pushingbox.ino Webhook widget V0, GET no body json / txt
 Url http://api.pushingbox.com/pushingbox?devid=[deviceID]&char1=/pin/
 *************************************************************/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>  

char auth[33] = "xxx";   
char ssid[]   = "xxx";  
char pass[]   = "xxx";  
char server[] = "blynk-cloud.com";

char tags[7][5] = {"6196", "6753", "5655", "69EC", "9FFC"};
char owners[7][5] = {"per1", "per2", "per3", "per4", "per5"};
int freeSpots = 5;
char lastTag[5] = "69EC";

BlynkTimer timer;



BLYNK_WRITE(V0)  // V0 Pushingbox webhook widget
{
  String theResponse = param.asStr();  // nothing returned, same as a browser
  Serial.println(theResponse); 
}

void sendtoPushingbox()
{
  int i = 0;
  while (i < 5)
  {
      if (strcmp(tags[i], lastTag) == 0)
      {
         // line below sends to value display 
         Blynk.virtualWrite(V2, String(owners[i]) + String("&int1=") + String(freeSpots));
         Serial.print(owners[i]);
         Serial.print("  ");
         Serial.println(freeSpots);
         // line below sends to webhook widget
         Blynk.virtualWrite(V0, String(owners[i]) + String("&int1=") + String(freeSpots));
      }
      i++;
   }
}
// V1 not used
// V2 is a value display widget

BLYNK_WRITE(V3)  // button to call webhook on V0
{
  if(param.asInt() == 0)
  {
    sendtoPushingbox();    
  }
}

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, server); 
}

void loop()
{
  Blynk.run();
  timer.run(); 
}

@costas Your code works perfectly well, thanks. Perhaps mine doesn’t work because I’m not using the Blynk timer in it? Is it usefull for you if I include my full code in my post?

Nothing to do with the timer. I just had that as I was originally calling the function at timed intervals but it’s not needed.

You could post your code but I would need to see some of your Google stuff (PM if you need to).

What do you mean “Google stuff”? Do you need to see the spreadsheet aswell?