-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible Bug in IoT Agent (tested only with iotagent-json) #401
Comments
Could you repeat the test using different api keys for the service? For instance:
In order to see if the problem also happens in this case. |
No, in this case, it works. The problem is the "apikey" which is queried before doing anything. If I have 2 groups with same apikey, it will always get the first one, since the 1st query to MongoDB is (as I explained before):
However, May the IoTAgent be using a "Document Database" like MongoDB as some kind of relational database. Why not adding to the documents in the "device" collection the "resource" and "apiKey" fileds from the group collection and perform just one query on the device to MongoDB instead of the 3 that are currently happening (groups, devices, groups again)? |
Which version of the IOTA agent did you use in your tests, please? |
Probably is not found due to that POST does not contain a proper resource (that should be /iot/office), and agent is looking with default resource (/iot/d) and that apikey. |
We have included recently some improvements related to apiKey management in the library (https://github.com/telefonicaid/iotagent-node-lib/blob/master/CHANGES_NEXT_RELEASE#L1):
Maybe it is not related with this problem but I'd recommend to use last version ( |
Anyway, looking to the queries you cite:
I think that if the query would include also the resource, i.e:
it will work Note that according to model (https://github.com/telefonicaid/iotagent-node-lib/blob/master/lib/model/Group.js#L47) the combination of apiKey + resource is unique, so that query always return the right document, by definiton. The problem here is how to get the resource. In theory the URL path can be taken as resource. So if the request is for instance As workaround: ensure that all you services has different apiKeys and it should work. |
Let's Imagine I have an office (with a sensor providing humidity and temperature) and a car (with a sensor providing speed and fuel). The default API Key is "1234". So I provision two groups:
Each group with one sensor:
And I POST data to the second device (office) with this error:
The response is:
{"name":"DEVICE_NOT_FOUND","message":"No device was found with id:thing:office0001"}
So, I try to find out why looking at the queries in MongoDB:
1. find { find: "groups", filter: { apikey: "1234" }, projection: { __v: 0 }, limit: 1, ...
The answer is (but it shouldn't be this one):
{ "_id" : ObjectId("5cd3fe60e6e14c017af932a8"), "resource" : "/iot/car", "apikey" : "1234", "type" : "thing", "service" : "car", "subservice" : "/car_measurement", "__v" : 0 }
2. find { find: "devices", filter: { id: "office0001", service: "car", subservice: "/car_measurement" }
That query is not the one that should be made, it doesn't correspond to my POST!!!
At this time I have a new Device in IoT Database (That I don't know why it is there), without Objects:
And I have a new device in my MongoDB:
{ "_id" : ObjectId("5cd4016fe6e14c017af932ac"), "subscriptions" : [ ], "creationDate" : ISODate("2019-05-09T10:31:11.301Z"), "id" : "office0001", "type" : "thing", "name" : "thing:office0001", "service" : "car", "subservice" : "/car_measurement", "transport" : "HTTP", "__v" : 0 }
The text was updated successfully, but these errors were encountered: