Ubidots - Photon issues (Spanish)

@gusgonnet
Hi, I am Ubidots’ user … ( do you speak Spanish?..Argentina?).
Maybe you can help me with some issues regarding Photon wit Ubidots.
Let me know.
Thanks

hola, si señor! Muchos por aca podemos ayudar.
Podes abrir otro topico con tus preguntas, por favor?
Please open a new topic with your questions so everybody benefits from the answers.
Gracias!
Gustavo.

2 Likes

@gusgonnet Happy Holidays !!! , voy aprovechar que hablas spanish.
Estoy haciendo una aplicacion de monitoreo basado en la Plataforma ubidots.
El objetivo es usar Electron para este caso.
He empezado a codificar usando el Photon por razones de economia.
Tengo corriendo mi codigo muy bien con Ubidots TCP , Photon y usando las libreria de Ubidots para particle device.
Estoy cambiando mi codigo para usar Webhook dado que el uso de data es menor que otros protocolos especialmente para Electron. Enviar datos a Ubidots con webhook funciona bien.
Ahora continuando con webhook se me presenta el siguiente problema ,pues solo me baso en la libreria generada por Ubidots: tengo un widget en el Ubidots dashboard denominado “Slider” al que le asignado la variavle “c”. El slider ademas de variar el contenido de “c” envia su valor a Ubidots cloud. Mi hardware tiene un sensor cuya lectura “s” debe ser comparada contra el valor “c” del “Slider”. Por ejemplo si “s” es mayor que el valor del slider “c” entonces envio el valor “s” a un Metric widget que lo exhibe y… ademas un contexo indicando que “s” supero el valor del slider. El punto importante de esto es que el customer debe ser quien establece el valor del slider .Es similiar a ajustar la temperatura desada del un termostato.
Aqui vien mi problema debido no conocer como codificar con HTTP.
Se que puedo usar un webhook con un get request y obtener el valor de “c” en en el codigo de mi Electron. Puedo configurar el webhook hasta el punto donde selecciono “GET”, luego el box me pide que especifique el “Querry string” y ademas otros box que no se llenar.!!!.

El webhook para enviar datos lo obtuve de una receta que da ubidots en:

https://help.ubidots.com/connect-your-devices/connect-your-particle-device-to-ubidots-using-particle-webhooks

He intentado usar EVENT, esta utilidad me obliga a a establecer una condicion logica, pero el customer no debe entrar en la configuracion del Event.
Quizas tu me puedas ayudar en algo y te lo agradezco de antemano.

Saludos

Hey @Meson777, like @gusgonnet suggested, I’ve moved your question over to a new topic.

While it’s great that assistance is available In Spanish, it’s a double edged sword: anyone who doesn’t speak Spanish can’t benefit from the answers, and they won’t be able help you either (even though they might know the answer to your problem). As such, I’d very much recommend sticking to English on these forums. Google translate does a relatively good job in getting stuff to English if that’s what you’re struggling with.

1 Like

You can always also add the Spanish version after the English translation. That way you get the widest reach and can still convey your intended thoughts as precise as you can do in your native language.
(e.g. Moors and I are not native English either).

1 Like

@gusgonnet Happy Holidays !!! , I’ll take advantage of that you speak Spanish.
I’m doing a monitoring application based on the Ubidots Platform.
The goal is to use Electron for this project.
I have started coding using the Photon for economy reason.
I have running my code very well with Ubidots TCP, Photon device and using the Ubidots libraries for particle device.
I’m changing my code to use Webhook since the use of data is less than other protocols especially for Electron. Sending data to Ubidots with webhook works fine.
Now continuing with webhook I am presented with the following issue, because I only rely on the library generated by Ubidots:
I have a widget in the Ubidots dashboard called “Slider” to which I assigned the variable “c”. The slider in addition to varying the content of “c” sends its value to Ubidots cloud. My hardware has a sensor whose reading “s” must be compared against the “c” value of the “Slider”. For example if “s” is greater than the value of the “c” slider then I send the value “s” to a Metric widget that displays it and … also a context indicating that “s” exceeded the value of the slider. The important point of this is that the customer must be the one who establishes the value of the slider. It is similar to setting the desired temperature of a thermostat.
Here comes my problem because I do not know how to code with HTTP.
I know that I can use a webhook with a get request and get the value of “c” in the code of my Electron. I can configure the webhook to the point where I select “GET”, then the box asks me to specify the “Query string” and also other boxes that I do not fill. !!!.

The webhook to send data I got from a recipe from ubidots at:

I have tried to use EVENT, this utility forces me to establish a logical condition, but the customer must not enter inside Event configuration.
Maybe you can help me with something and I thank you in advance.

regards

I have had a look at the Ubidots feature set and AFAICT there doesn’t seem to be a straight forward path to that.
I could imagine you could create a derivative of c (e.g. c - previous(c)) and use that for the webhook trigger, but that seems a clumsy workaround.
However, this isn’t really a question specific to Particle but rather to Ubidots. You might have more luck asking there.

Some feature requests for Ubidots webhook triggers would be to add a not equal trigger and an on change event (potentianlly with threshold and hysteresis parameters). Either of these would make it a lot easier to achieve what you’re after.

We can tag @mariahernandez who wrote some of the Ubidots tutorials for their page.

@ScruffR Thank you. I tried to use the last example from the link I posted.
but I said in my post is the customer who needs to set the slider value, and no a condition set inside the Event configuration. I will talk with Ubidots.
Thaqnk for your interest on helps me.

Hi, I think one way of doing that is to create an internal Ubidots variable and make it the sliders' value so your customer can modify it from the interface.
However @ScruffR is right, you'll probably get better answers on the ubidots forums.

Hola,
creo una manera de hacer eso es crear una variable interna de ubidots y representarla en el "slider" para que el cliente tuyo pueda modificarla desde la interface, y hacer la logica desde Ubidots.
Pero Scruffer tiene razon, lo mejor seria preguntar eso en el foro de Ubidots.

Saludos y felices fiestas!
Gustavo.

1 Like

Another upside on using a webhook is that the information travels encrypted all the way from your Particle device to the Cloud, then to Ubidots.
While using the Ubidots library, the information travels unencrypted to Ubidots, since it uses HTTP.

Gustavo.

@gusgonnet Thanks for your answer. yes, I am trying to create a variable for the slider called s and retrieve it from Ubidots Cloud. I think that this can be done with a webhook where the method used be GET request in place the POST request. But really I do not have the background to fill out all the boxes in the webhook configuration for this case.
I selected Ubidots because they have a complete set of libraries for Photon and Electron. Maybe you can help me to configure that type of webhook.

hola,
you can find all the info about configuring webhooks for ubidots here:

and here:
https://ubidots.com/docs/devices/particleWebhook.html#setup

I wrote few example projects here:

and there:

@Meson777

I found the way to use Particle webhooks to retrieve data from Ubidots to your device, and then use the value as you see fit within your firmware. Here the steps I followed:

1. Create a webhook as you’d normally do to POST data to Ubidots but fill the options as indicated below:
Event name: get_lv
URL:
https://industrial.api.ubidots.com/api/v1.6/devices/{{{PARTICLE_DEVICE_ID}}}/variable_label/lv
IMPORTANT NOTE: replace “variable_label” for the Ubidots variable label from which you want to retrieve last value from.
Request type: GET
Request format: Query parameters
Device: Any
Query parameters: Select the custom option and enter token in the leftmost field. In front of it, enter a valid Ubidots TOKEN from your account.
Response topic: {{{PARTICLE_DEVICE_ID}}}/hook-response/{{{PARTICLE_EVENT_NAME}}}/
– Save the configuration.

Here some pics from my webhook setup:


2. In the Particle IDE, copy and paste the below code which triggers the webhook above every 5 seconds and also subscribes to the hook-response, that is, the value retrieved from Ubidots, then convert it to float and prints it to the serial monitor.

float value_from_ubidots;

void setup() {
  // Subscribe to the response event, scoped to webhooks triggered by this device
  Particle.subscribe(System.deviceID() + "/hook-response/Get_lv/", myHandler, MY_DEVICES);
}

void myHandler(const char *event, const char *data) {
  // Handle the webhook responses
  value_from_ubidots = atof(data);
  Serial.print("Value from ubidots: ");
  Serial.println(value_from_ubidots);
}

void loop() {
    bool success;
    success = Particle.publish("get_lv", NULL, 60, PRIVATE);
    if(success) {
        Serial.println("Webhook triggered");
    }
    delay(5000);
}

I hope this gets you through your intention.

–David

@dsepulvedar @gusgonnet
Thank you for your suggestions.

David, what you send me is exactly what I need.
I configured the webhook and download the code as you explain me.
This is the code as I have in my webIDE.
Observe what I commented.

// This #include statement was automatically added by the Particle IDE.
//#include <Ubidots.h>
//#include "Ubidots.h"


//const char* WEBHOOK_NAME = "get_lv";
//Ubidots ubidots("webhook", UBI_PARTICLE);




float value_from_ubidots;

void setup() {
  // Subscribe to the response event, scoped to webhooks triggered by this device
 
  Serial1.begin (56700);
  Particle.subscribe(System.deviceID() + "/hook-response/Get_lv/", myHandler, MY_DEVICES);
}

void myHandler(const char *event, const char *data) {
  // Handle the webhook responses
  value_from_ubidots = atof(data);
  Serial1.print("Value from ubidots: ");
  Serial1.println(value_from_ubidots);
}

void loop() {
    bool success;
    success = Particle.publish("get_lv", NULL, 60, PRIVATE);
    if(success) {
        Serial1.println("Webhook triggered");
    }
    delay(5000);
}

Only Particle.publish is working , I can see that from the terminal.
I am using a variable_label called pL which is the slider variable I am interested in retrieve .
The variable lv always return null, I can see that from Particle console, not from terminal.
I double checked the webhook configuration so it matches what you sent me.
I attached pics from the Particle Console so you can see the error displayed.

I thought you were after a way to push the variable from Ubidots to your device when the user changes the slider setting to safe data by only transfering when the variable is updated in the dashboard.
The way above regularly requests data from Ubidots, even if the value hasn't changed there and hence permanently nibbles into your data allowance.

@ScruffR You are correct. My suggestion will be periodically requesting data to Ubidots even though the value has not changed. But as you mentioned earlier, Ubidots event engine doesn’t support conditions such as “has changed” yet, so this a provisional workaround using Particle webhooks that is the initial request.

Now, @Meson777, I see there are three mistakes, one is coming from me (I apologize for that):

1. In the setup() function, when subscribing to the hook-response, you need to replace “Get_lv” with “get_lv” which is the webhook name. This is my error, just an uppercase “G” that should be lowercase.

2. Additionally, in the Response topic field, there’s a hyphen in the Particle variable {{{PARTICLE_EVENT-NAME}}} while it should be an underscore, that is,{{{PARTICLE_EVENT_NAME}}}.

3. In the webhook’s URL, you’re entering pL as your variable label, but remember all variable labels are lowercase. Adjust it to be pl

Further, let me clarify lv is not a variable, is part of the Ubidots API endpoint and it means Last Value. With that in mind, you are only going to retrieve your variable last value.

I remained on thinking about your case and there’s also another option that would prevent your firmware from constantly requesting data to Ubidots. @ScruffR already pointed it out: using synthetic variables you are able to compute the condition right there from Ubidots rather than on your firmware. This is the steps I followed:

1. Create a synthetic variable with the below expression (DO NOT COPY/PASTE THE COMMENTS IN THE SYNTHETIC EDITOR, JUST THE EXPRESSIONS):

dif = s - c // difference between sensor and slider value according to your nomenclature
where(dif > 0, 1, 0) // Evaluates dif and if true populates with 1, otherwise is 0.

2. Create an event that triggers every time your synthetic variable equals 1. Once triggered, configure it to send a webhook to particle to which your firmware should be subscribed as described in example 6 here. Doing so you will avoid frequent and unnecessary request and also be able to flag your firmware as you need to.

As a final note, I leave to you which method to use according to what you consider more appropriate.

Best,

–David

1 Like

@Meson777, I did a mistake again. This time on the first expression for the Synthetic Variable.
It should be:

dif = fill_missing(s - c)

fill_missing() function fills the gaps between both time series in order to compute dots which do not have the same timestamp.

Best,

–David

1 Like