Need to do simple statistics in Blynk. How?

How can I run some simple statistics on logged data and show it in app?

For example: I’ve been logging temperature every 1 min for one year. In the app I want to show that for how long (days, hours, minutes) the temperature has been over 80 centigrades.

I have other similar things I have to do so this is not the only example. I’d like to know more broadly how this can be done.

Thanks,
Tipo

As BLYNK is just a GUI, you will have to do the computations outside of BLYNK and then send that data back for display.

You can export the stored data to a CSV, and do the required math in EXCEL. But I do not know of a way to send it back to the microprocessor.

My thoughts are that you will need to store the data locally as it is colleced, say on an SD Card, and retrieve it from there for you statistic computations. Then send that data to BLYNK.

1 Like

Blynk is more than GUI. The data sits in Blynk local server or in Blynk cloud server.

Can the computations be done in local or cloud server? How exactly?

You could publish the data to Google Sheets and do the analysis there. Heck, there may be a way to read the analyzed data that is in the Google sheet and display in Blynk.

Blynk is an IoT GUI… not a multipurpose analytics App. However, as stated, there should be no reason you can’t setup the Local Server database and use other 3rd party analytics programs to run your statistics, then send that data back to Blynk (Webhook perhaps) for viewing… but the how-to is up to you and Google.

1 Like

Can I get data to “external” mysql database without setting up a local server?
Maybe with webhook, or using RESTful API, or by some other means?

Yes. You can use webhook widget or reporting widget for that.

Hi, i guess that we can use the webhook, but does anyone know how to trigger the webhook to send that Blynk app input data to that mysql server or made the webhook show the data from the server on the app ? Basically, I guess the external server can not trigger itself to send to Blynk and I feel like weebhook and Blynk API are only mean to support for some specific 3rd party services… ?!

@niki take a look at BlynkTimer (Arduino’s SimpleTimer) to trigger the Webhook at your chosen intervals.

@Costas Thanks for your reply, I have tried the Timer but look like that it can not trigger the Webhook directly , I have tried many ways but the output of the Timer can not connect to the Webhook to trigger, that is what I m trying to do … or did I miss anything ?

I can guess that the timer could send to the Blynk clould and Device could receive it . Then, device will send a trigger back to the Webhook so that the webhook could send the http request to my server. But I am trying to avoid keeping communicating back and forth with the device, so could I really trigger the Webhook directly from the app Blynk Timer (if yes then how ? ) or from any other Blynk widgets ?

Not the Timer widget, BlynkTimer library also known as Arduino SimpleTimer.

@Costas Blynk Timer library so does it means I have to set it up in my Device code and control it from there ? Is there any widget app that I could trigger the webhook directly without anything related to the Device ?

@niki you just need a few lines of code.

See this example for BlynkTimer with an ESP https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=GettingStarted%2FPushData

You can trigger the Webhook with a Blynk button, and a bit of code, but you don’t really want to do that.

Funnily enough, this type of functionality is exactly what @Costas was arguing for in another recent thread.

At present, if you’re hoping to retrieve data from the Blynk cloud server and write it into a MySQL database (and possibly parse the data as well) then you’re going to need a device running that code.

Personally, I’d take a different approach…
Do a one-off exercise to extract the historical data from Blynk and populate your MySQL With it. Then change the code that you’re using for logging temperature data and get it to write the data to MySQL as well as to Blynk.

Pete.

Ok I see, I just want to find the most quick and efficient way to communicating from Blynk App to my server without relating to the devices cause there are still a lot of things that device need to do itself, but I guess at some point I need help from device to communicate with Blynk cloud, can not just leave it out !

Thanks @Costas and everybody for helping me out !

I do not really understand the discussion that webhook would need to be triggered. I’m using webhook right now to send data to Thingspeak and it works fine: every time when the data comes from device to Blynk, it gets sent automatically to Thingspeak.

*** The question is that what needs to be in webhook url in order that the data gets sent to mysql?

Right now I’m sending data to mysql from device with this code.

 if (client.connect("www.test.xxxxxxxxxxx.fi", 80)) {
    Serial.println("Connected to server");
    client.println("POST /api/meteringData HTTP/1.1"); 
    client.println("Host: test.xxxxxxxxxx.fi:80");
    client.println("Content-Type: application/json"); 
    //client.print("Content-Length: "); 
    //client.println(root.measureLength());
    client.println(); 
    root.printTo(client);
  }
  delay(1000);   // Give arduino client time to receive reponse from the server
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

@Dmitriy Do you still think webhook is useful in this task? Thanks.

Yes. You just need to fill webhook fields correctly.

About Webhook widget:
On the top OUTPUT is virtual pin.
Then in BODY the hint is “Use /pin/ to insert pin data”. What pin this is referring to?

The pin data that triggers webhook. So you can resend trigger value to any 3-d party.

So OUTPUT virtual pin value doesn’t get sent to 3-d party?
BODY /pin/ refers also to virtual pin and that is the one that get’s passed to 3-d party?