Unable to retrieve Location Metadata

Hi there,

I need some help with retrieving metadata from the Blynk console. There is a description on how to do this in the documentation, but it seems that it doesn’t work for location metadata.

I set up a metadata field of the type “location” in the Blynk console. This would allow end users to set a location for their device in the Blynk app.

To retrieve this location data on the ESP32, this was the code that I originally tried:


BLYNK_CONNECTED()
{
  Blynk.syncAll();
  Blynk.sendInternal("meta", "get", "Location");
}

BLYNK_WRITE(InternalPinMETA)
{
  String field = param[0].asStr();
  cloudMetaLocation = param[1].asStr();
}

Unfortunately, this outputs an empty string… After unsuccessfully trying to only retrieve the location field that I’m interested in, I added a text field in the metadata of the Blynk console section called “Test” and tried retrieving that:


BLYNK_CONNECTED()
{
  Blynk.syncAll();
  Blynk.sendInternal("meta", "get", "Location");
  Blynk.sendInternal("meta", "get", "Test");
}

BLYNK_WRITE(InternalPinMETA)
{
  String field = param[0].asStr();
  cloudMetaLocation = param[1].asStr();
}

This outputs the content of the “Test”-field only. So, is it possible that a “location-type” field in the Blynk console cannot be retrieved on the device? And if so, how can I allow the end user to set the device location in the app and make this information available to my ESP32?

Thanks a lot for your help.
Georg

Have you actually set a location for your device…

If not then a empty string is what I’d expect it to return.

Pete.

Yes, I provided a location. Any idea what I might have done wrong?

Best regards
Georg

It would probably help if you provided more information.

Pete.

ok no problem, but I don’t know what else I could provide. Could you tell me what you need?

Well, I’ve asked you a question and provided a screenshot, and you’ve replied “yes, I have”.
Some details might be good.
Details of what you get when you try using the REST API to retrieve the data might also be useful, but not if your reply is “same”.

Details of the Metadata IDs that you’ve cropped off of your screenshot might also be helpful.

Basically anything that helps to paint a full picture of what’s happening.

Pete.

I get your point and I’m trying to provide the info that you need.

Here’s a screenshot like yours which shows the metadata of the device:

As you can see, there is a value in the field “Test” which I can retrieve without problems. Do you know if it could be a datatype issue? I’m not sure what to expect when retrieving the location field. Is it a string which concatenates adress, zip code and city or is it coordinates?

I’m not actively using REST API so unfortunately I would need to know how to test it if that is an important information.

Best
Georg

here’s the uncropped screenshot:

So your template screen doesn’t show the metadata ID?…

It’s quite simple to use, this might help…

Pete.

Hello there, any updates on this topic. I’m trying to obtain the longitude/latitude of a device via the “Location” metadata field. I tried:

BLYNK_CONNECTED() {    
  Blynk.syncAll();
  Blynk.sendInternal("meta", "get", "Location");
}

BLYNK_WRITE(InternalPinMETA){
  String field = param[0].asStr();
  String value1 = param[1].asStr();
  String value2 = param[2].asStr();
}

Only field shows a value of: “Location”.
value1 and value2 are empty. Also tried param[1].asDouble()… shows 0.00.-

Also tried via API
https://ny3.blynk.cloud/external/api/device/meta?token=XXXXX&metaFieldId=3

Which shows: {“type”:“Location”,“orgLocationId”:2770,“size”:0.0}

Any sugestions?
Thans in advance.

You need a special syntax for that:

Blynk.sendInternal("meta", "get", "loc.latlon");

The logic behind this command is next:

  • if the device has location metafield filled in, the data is returned from it
  • if the device has a location assigned (organization location, not metafield location), the data is returned from organization location
  • if above failed - the location from IP address is returned

if you do
Blynk.sendInternal("meta", "get", "Location");

you just get a string of the Location metafield, formatted in a special way.

This API was done for some of our WL clients, so we never focused it for the blynk cloud. We would need to revisit it at some point and make it more clear.

By the way, where did you get this API from? I don’t think we ever put it in the documentation.

1 Like

Thanks Dmitriy… works nicely.

I found this API call on a post from Pete… Blynk get Switch metadata - #3 by PeteKnight

Saludos.

1 Like