Electron - posting to multiple data aquisition services

Hi All
Wondering if I can please get some advice with respect to my data usage on Electron…

I would like to post “tank level” value every 5 minutes. I would like to utilise both Blynk for phone app and cloud server such as Ubidots or Freeboard for dashboard.
I also post device “uptime” to Blynk.

Application is currently working well, but using loads of data on my Electron. Is there a more efficient way of sending the values without using excessive data?
EG - is thee a way to post a particle.publish function, and then re-direct Blynk and Ubidots to read values from particle console instead? This way I would only be posting data once…?
I’ve included my code below.

Thanks guys

> //Blynk configuration
> #include “blynk.h”
> #define BLYNK_PRINT Serial
> char auth[] = "*"; //authenticate token (Blynk)

> //Ubidots configuration
> #include “Ubidots.h”
> #define TOKEN "*" //authenticate token (Ubidots)
> Ubidots ubidots(TOKEN);

> //Timer handler configuration
> #include “SparkCorePolledTimer.h”
> SparkCorePolledTimer updateTimer1(300000); //Timer1 (5 minutes) - remote poll
> void OnTimer1(void);

> float TnkLvlPV_RAW = A0; //Raw signal data from field
> float Tx01 = 0.0; //transmission tag #1 (actual level, scaled)
> unsigned long UPtime = 0UL; // Interanl tag to process UPtime
> char Tx02[40]; // Transmission tag #2 (device UPtime)

> void setup () {
> pinMode(TnkLvlPV_RAW,INPUT);
> Blynk.begin(auth); //open connection and authenticate

> Serial1.begin(115200); //initiate timer handler and ubidots
> updateTimer1.SetCallback(OnTimer1);
> }

> void loop() {
> updateTimer1.Update(); //constantly update timer
> Blynk.run(); //Run handling code for Blynk

> unsigned long now = millis(); // This sectiion handles the logging of device UPtime.
> if (now-UPtime>600000UL) { //Publish every 10 minutes
> UPtime = now;
> unsigned nowSec = now/1000UL;
> unsigned sec = nowSec%60;
> unsigned min = (nowSec%3600)/60;
> unsigned hours = (nowSec%86400)/3600;
> sprintf(Tx02,"%u:%u:%u",hours,min,sec);
> Blynk.virtualWrite(1, String(Tx02)); //publish uptime to Blynk
> }
> }

> void OnTimer1(void) { //Handler for the timer, will be called automatically
> // Read alalogue value assigned to TAG “TankLevelPV_RAW”
> Tx01 = analogRead(TnkLvlPV_RAW);
> Tx01 = map(Tx01, 0, 4095, 0, 100); //scale raw value to 0-100 %
> delay(100);
> Blynk.virtualWrite(0, String(Tx01));
> ubidots.add(“tint01”, Tx01);
> ubidots.sendAll();
> }

@BIBZY84,

It might be overkill, but you might try using webhooks and webtasks. I have posted a detailed method for doing this here:

One nice thing about this approach is that once you get the Particle.publish link working to the webtask, you can pretty much do whatever you want with the data - send it to multiple services, decrypt/decompress, reformat, process the data, etc. Another nice thing is that all of this is done in a secure way - authentication is built into the webtask framework.

We use this framework for sending data from our devices to multiple databases and services - both our own and 3rd-party. And if we decide to add another, or delete one, we don’t have to change anything in the firmware. We just change the webtask, recompile it, and we’re good to go.

Anyway, I’m sure others have good/better ideas, but thought I’d offer this up. Cheers,

L3

PS - if you do this, you could send your data in a really tight format to cut down on cell usage, and then unpack it on the webtask

1 Like

@leo3linbeck Thanks for sharing mate. Do you think this system would work for apps such as Blynk though? I searched through I had a search to see and understand whats involved but cant seem to find any materiel that details requirements for setting up a webhook to Blynk.
I have always had in my mind that a simple particle.publish would be the only required transmission, then having the ability to push/handball the data out to other services as I please.
Has anyone been able to push to blynk from console?

@BIBZY84,

Well, again, it may be overkill, but here’s on option (BTW: I know nothing about Blynk beyond what I just learned in the last 3 minutes):

They have a RESTful API that allows you to do your “virtual write” to a Blynk pin by calling an HTTP end point. The documentation for this call is here:

http://docs.blynkapi.apiary.io/#reference/0/set-widget-property-via-get/set-widget-property-via-get

You’d have to get an authentication token (by calling the Apiary authentication endpoint, since Blynk hosts its api on Apiary apparently), and then make an HTTP call to Blink using the above call. If you select “Node.js” on the Apiary panel, it will give you the code you would need to copy into your webtask.

You can do all this from a webtask - these are just regular HTTP calls, and since webtasks are built on node.js, you can simply “require” the module you need (like http or rp if you want use promises), and make the call from the webtask. You can also send notifications, emails, etc through the Blynk api.

Hope this helps. Cheers,
L3

2 Likes

@leo3linbeck This is great mate. Thanks for sharing and in such detail. I am learning heaps from it. I will have a crack and let you know how I get on. Again much appreciated
Cheers