-
Notifications
You must be signed in to change notification settings - Fork 89
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
Unexpected parsing of Array of Objects (MQTT measure) #856
Comments
Using latest version of iotagent and sending:
I see all these measures are delivered to CB:
|
@AlvaroVega hi, okay. that's exaxtly the point apparently the array is processed one by one, but I want to habe the whole array as a single attribute value, because it is a forecast for the next X-hours. Therefore, it should one single update putting the whole thing in one operation. Expected this: NOTE: We are using the single-measure-mqtt-api. Ergo, one single value at a time {
"id": "thing:dev",
"type": "thing",
"timestamp": {
"type": "DateTime",
"value": "2025-01-28T06:00:00Z",
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2025-01-27T14:30:57.399Z"
}
}
},
"value": {
"type": **"Array",**
"value": **[
{"timestamp": "2025-01-27T09:00:00Z", "value": 10.67},
{"timestamp": "2025-01-27T12:00:00Z", "value": 10.2},
{"timestamp": "2025-01-27T15:00:00Z", "value": 9.16},
{"timestamp": "2025-01-27T18:00:00Z", "value": 7.72},
{"timestamp": "2025-01-27T21:00:00Z", "value": 7.39},
{"timestamp": "2025-01-28T00:00:00Z", "value": 6.39},
{"timestamp": "2025-01-28T03:00:00Z", "value": 5.87},
{"timestamp": "2025-01-28T06:00:00Z", "value": 5.54}
]**,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2025-01-27T14:30:57.399Z"
}
}
},
"TimeInstant": {
"type": "DateTime",
"value": "2025-01-27T14:30:57.399Z"
}
}
|
Srroy, could you tell me exactly how you send MQTT ? i.e.:
|
@AlvaroVega sure. From commandline it should be something like:
|
I guess you really are sendint something like: (HTTP):
MQTT:
In MQTT case CB updates are done one by one. This PR enables sent to CB in just one shot: #857 @tstorek thanks for report! |
@AlvaroVega I do not exactly understand. Just to clarify. The value of the attribute contains the whole Array in the sent message. We want to have the whole list in one single attribute in CB. Thus, the cb should show it like this: "temperatureForecast": {
"type": "Array",
"value": [
{"timestamp": "2025-01-27T09:00:00Z", "value": 10.67},
{"timestamp": "2025-01-27T12:00:00Z", "value": 10.2},
{"timestamp": "2025-01-27T15:00:00Z", "value": 9.16},
{"timestamp": "2025-01-27T18:00:00Z", "value": 7.72},
{"timestamp": "2025-01-27T21:00:00Z", "value": 7.39},
{"timestamp": "2025-01-28T00:00:00Z", "value": 6.39},
{"timestamp": "2025-01-28T03:00:00Z", "value": 5.87},
{"timestamp": "2025-01-28T06:00:00Z", "value": 5.54}
]
}
|
@AlvaroVega @fgalan I appreciate you quick reaction. However, from my point, the solution will still lead to an unexpected behavior if the array only contains 1 element. While this is necessary for the multi-measurement api for the single one it is relatively nasty. |
If you send just one element: mosquitto_pub -h localhost -t /json/APIKEY/dev1/attrs/temperatureForecast -m '[
{"timestamp": "2025-01-29T09:00:00Z", "value": 44 }
]' CB receives a single jSON:
time=2025-01-29T09:48:03.796Z | lvl=DEBUG | corr=b3d4b7ea-c3eb-46b2-8567-8fc7f30a6511 | trans=b3d4b7ea-c3eb-46b2-8567-8fc7f30a6511 | op=IoTAgentNGSI.Request | from=n/a | srv=smartcity | subsrv=/ | msg=Options: { The point here is that |
Exactly. As explained in the Orion API documentation
Only a few types (explained in that reference) have an special semantic in the NGSI API (and |
@fgalan @AlvaroVega I totally understand that Just a suggestion, restain the send type in the single measurement. Thus even an empty array In the MultiMeasurement, one would do the same:
As I understand it in the code (I'm not Node.js programmer) this requires another hierachical level in in message parsing.
I think that steps 2-3 are currently lumped together with leads to the current behavior. |
@tstorek maybe you can try it with latest version again. |
IoT Agent JSON version the issue has been seen with
{'libVersion': '4.0.1', 'port': 4041, 'baseRoot': '/', 'version': '3.0.2'}
Bound or port used (API interaction)
Northbound (Provision API and NGSI Interactions)
NGSI version
NGSIv2
Are you running a container?
Yes, I am using a contaner (Docker, Kubernetes...)
Image type
normal
Expected behaviour you didn't see
We want to send weather forecast objects via the IoT-Agent to the orion.
Provisioning as an Array and MQTT-Traffic works as expected:
Here an example of the payload for a temperature:
As this is valid JSON we expect the payload parsed in this form.
Unexpected behaviour you saw
Unfortunetly, the IoT-Agent only parses the first item of the array and sends it the the context broker.
In the MongoDB we only find the first value:
I think the issue is here:
iotagent-json/lib/commonBindings.js
Line 253 in 5cd70e4
Steps to reproduce the problem
Configs
Log output
The text was updated successfully, but these errors were encountered: