Beacon Registered, but response indicates wrong UID

柔情痞子 提交于 2019-12-02 20:08:49

问题


I successfully registered a beacon using Google Proximity API but the response indicates a different UID

Request URL https://proximitybeacon.googleapis.com/v1beta1/beacons:register

Request

{
    "advertisedId": {
        "type": "EDDYSTONE",
        "id": "0x2f234454f4911ba9ffb6"
    },
    "status": "ACTIVE",
    "latLng": {
        "latitude": 51.4935657,
        "longitude": -0.1465538
    }
}

Response

{
  "beaconName": "beacons/3!d31d9fdb7e38e787f8f75d5b6bd7df6f",
  "advertisedId": {
    "type": "EDDYSTONE",
    "id": "0x2f234454f4911ba9ffbw=="
  },
  "status": "ACTIVE",
  "latLng": {
    "latitude": 51.4935657,
    "longitude": -0.14655379999999998
  }
}

If you notice carefully, the UID in the response does not match with the UID in POST request. Also, I tried the https://proximitybeacon.googleapis.com/v1beta1/beacons?q=status:active GET and I am still seeing slightly different UID.


回答1:


I'm assuming the strings you have in your code above are not actually what's being sent around because they shouldn't work at all.

There is an issue where: if you base64 encode the hex representation of the beaconID, and NOT the binary representation. It looks as though the server would erroneously accept this, but interpret it differently. That will be fixed soon.

So, instead of doing this:

var b64id = Base64Encode("abcdef0123456789abcdef0123456789");

You want to be doing:

var b64id = Base64Encode(HexToBinary("abcdef0123456789abcdef0123456789"));

I.e.

if you have the hex string for the id: abcdef0123456789abcdef0123456789, make sure that your code produces the base64 string: q83vASNFZ4mrze8BI0VniQ== — that is what you should be sending the server in the "id" field.

A BeaconID is 16 bytes long, that will show up as a 32 character hex string. The resulting base64 string encoding that beaconID should be about 23-24 characters long.

Hope that helps.



来源:https://stackoverflow.com/questions/32126857/beacon-registered-but-response-indicates-wrong-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!