Dynamic fields in HTTP Route URL field

Hello everyone,

I’m trying to forward my Notecard data from Notehub to Ubidots using an raw HTTP Route. Based on Ubidots’ Docs, they recognize the device label one wants to send data to in the URL as follows:

https://industrial.api.ubidots.com/api/v1.6/devices/{DEVICE_LABEL}

where the {DEVICE_LABEL} is to be replaced by a unique label within Ubidots account. I’d like that to be my Notecard’s Device UID.

How can I set up my Route URL field so it replaces that portion of the URL with the Device UID syncing data to Notehub and triggering the Route?

I need this since I’d like to have a single Route to serve all of my Notecard devices or Product

Thanks in advance.

D

2 Likes

Hey David, welcome to the community, we’re glad you’re here!

I know I sent you this info via email yesterday, but I will include it here for anyone else who might be interested.

There are 3 fields you can use in the route url that can help here. Note all three must include the square brackets:

  • [device] - for the DeviceUID
  • [product] - for the ProductUID
  • [sn] - for the Serial Number

So, for Ubidots, https://industrial.api.ubidots.com/api/v1.6/devices/[device] will route to a url with your DeviceUID on the end.

1 Like

Hello @bsatrom and @dsepulvedara, I found this topic after reading the Ubidots routing tutorials at both sources and still not quite understanding the solution to the problem David posted earlier.

According to the documentation:

A Route is an external API, or Server location, where Notes will be forwarded for a Device or Fleet upon receipt. Routes are defined in Notehub for a Project and can target a single Fleet or all devices in a Project.

I have no problem connecting one device per route"*", but I couldn’t figure out how to build routes for a fleet or for an entire project. Personally I’m more interested in building a route for a fleet, but others might come from a different angle.
It would be greatly appreciated if one of you guys could post an example for each the fleet and the project level route URL.

“*” [edit]: it turned out this was a temporary error, see the summary of my journey below.

Based on @bsatrom’s suggestion I tried the https://industrial.api.ubidots.com/api/v1.6/devices/[product] request but it returns a "status":"404","text":"{\"code\": 404001, \"message\": \"The request was not found.\"}' error.

Thank you.

1 Like

Thanks for the question @LBBD, perhaps @dsepulvedara can chime in and provide more insight on whether it’s possible to route data for an entire fleet in Ubidots, and if so, the right endpoint to use.

Poking around their docs, however, it looks like you might need to add a device-group. See: Update Device Group

Thanks for your quick reply. I hope @dsepulvedara can chime in, because the Ubidots User Guide doesn’t seem to offer a direct solution to this question in the context of device groups.

Device groups will allow the below operations:

  • Add devices to an Organization
  • Move a Device Group’s devices from one Organization to another
  • Create Global events associating to a Device Group.

My understanding was that in order to avoid setting up individual routes for each devices manually, the {DEVICE LABEL} should be dynamically added to the https://industrial.api.ubidots.com/api/v1.6/devices/ endpoint URL.

Would this be feasible in Notehub’s Routes/Create Route
General HTTP/HTTPS Request/Response ?

Hello @LBBD and @bsatrom,

To be honest, I’m not sure about what the ProductUID does or its goal within Blue’s Notehub. I think that’s a separate topic that I can learn myself through the Docs. Certainly, using it in the Route configuration will render an error in our API.
What I do know is that to correctly forward data from a fleet to Ubidots over a “General HTTP/HTTPS Request/Response” route, the URL should be set to:

https://industrial.api.ubidots.com/api/v1.6/devices/[device]

That way [device] will be replaced by the Notecard’s DeviceUID which will act as the Ubidots Device label (unique identifier within Ubidots account)

Does it make sense?

Best,

–David

David, thank you for checking back.

As far as I know the “General HTTP/HTTPS Request/Response” routing method has no option for dynamically generated URLs. Consequently, each device would require a manually created individual route.

In the meantime, the “General HTTP/HTTPS Request/Response” method does offer an option for forwarding data from a set of devices defined as “fleets” or “project”, under a single route configuration.

Is there a way to identify the devices and to assign the forwarded data to that particular device in Ubidots (other than the URL’s device label) as @bsatrom suggested in an earlier post?

@LBBD, are you sure that the below doesn’t work?

Back then, I tested the same and it indeed replaced [device] with the DeviceUID as advised by @bsatrom here

As a matter of fact, this is how my route looks in my Notehub account and last time I tested, which to be fair was a long time ago, it worked perfectly:

First, many thanks for @dsepulvedara and @bsatrom for their inputs.

CONCLUSIONS:

  1. Don’t get confused
    As you are reading the documentations you come across:
    https://industrial.api.ubidots.com/api/v1.6/devices/{DEVICE_LABEL}
    https://industrial.api.ubidots.com/api/v1.6/devices/[device]
    https://industrial.api.ubidots.com/api/v1.6/devices/[device-name]/
    https://industrial.api.ubidots.com/api/v1.6/devices/sensor-data/

There are multiple ways to successfully land your data in Ubidots and it’s very convenient if you know what to expect and how to achieve it, but you can easily put yourself into a pretty dizzying tailspin. As it happened to me, even though this wasn’t the first time I used Ubidots.

  1. What works
    Ubidots automatically initializes (creates) a unique device label, identical to the {DEVICE_LABEL}, which is the very last member of the endpoint URL.
    The {DEVICE_LABEL} can be:
    A. an arbitrary character string, like sensor-data, OR
    B. one of the field names [device], [sn] ,[product] that Notehub can identify, and dynamically substitute with the sending Notecards’ DeviceUID, Serial Number or ProductUID.
    Anytime you create a route with a URL that contains a {DEVICE_LABEL} that is different from the existing device labels , Ubidots will initialize a new device.
    This is where things might become a bit tricky and you need to factor in the scope of the route exaction (see the next point)

  2. What doesn’t work
    While a manually set {DEVICE_LABEL}, like sensor-data perfectly identifies the device in Ubidots, the Notehub has no clue to which Notecard you meant by sensor-data, devG1_b32 or whatever that character string might be, even if you put the deviceUID, Serial Number or ProductUID in place of the {DEVICE_LABEL}.
    While the Notehub can recognize the [device] , [sn] , [product] fields and substitute them with the particular Notecard’s information that is sending the data, it cannot go the other way. Putting a deviceUID or a Serial Number in the URL will not tell the Notehub which Notecard’s data you want to include in the route execution.
    If you set the {DEVICE_LABEL} manually, the only thing that determines what data will be forwarded under that label is how you set the Filters in the route configuration.

To illustrate this with a theoretical example, let’s say you have ten Notecards with Serial Numbers (sn) from sens00 to sens09 and all of them monitor temperature and humidity data which is put in the sensor.qo notefile and updated every 10 minutes. Now, let’s see two routing scenarios with one {DEVICE_LABEL} being the serial number field [sn] and another the actual serial number.

A - https://industrial.api.ubidots.com/api/v1.6/devices/[sn]
B - https://industrial.api.ubidots.com/api/v1.6/devices/[sens00]

In scenario ‘A’ you’ll see ten devices appearing in Ubidots labeled with your ten Notecards’ serial number, in the order of their data update. Anytime, any of your sens00-sens09 devices sends the humidity and temperature information, it will be associated with the corresponding device label (serial number) in Ubidots.

In scenario ‘B’ however, you will see only one device in Ubidots, labeled as sens00 but it might display all the humidity and temperature data arriving from your entire fleet or project. You’ll see the last update as humidity and temperature values, regardless of which Notecard the data is coming from.
In this scenario the FILTERS configuration will determine the scope of the route execution which has nothing to do with the serial number you manually inserted in the URL.

2 Likes

Thanks for this thorough explanation @LBBD! I’m making a note to update our tutorials and this will help to clarify what to do in these multi-device scenarios.

2 Likes