ankraft / ACME-oneM2M-CSE

An open source CSE Middleware for Education.
https://acmecse.net/
BSD 3-Clause "New" or "Revised" License
23 stars 16 forks source link

Subscription notification using MQTT wrong receiver in topic and 'to' #108

Closed samuelbles07 closed 1 year ago

samuelbles07 commented 1 year ago

Hi,

I found that when POA of AE is using MQTT, CSE notify to the wrong receiver. What i expect is when new contentInstance under container control-glass created, i get notification since i already create subscription resource under the container.

AE attributes

{
    "m2m:ae": {
        "acpi": [
            "acp1994839229681685407"
        ],
        "api": "NCGlass",
        "rr": true,
        "poa": [
            "mqtt://localhost:1883"
        ],
        "srv": [
            "3"
        ],
        "rn": "CGlass",
        "ri": "CGlass",
        "pi": "id-asn",
        "ct": "20230120T082858,465351",
        "lt": "20230120T192335,443259",
        "et": "20280119T082858,465402",
        "ty": 2,
        "aei": "CGlass"
    }
}

Container attributes

{
    "m2m:cnt": {
        "acpi": [
            "acp1994839229681685407"
        ],
        "mbs": 10000,
        "mni": 10,
        "rn": "control-glass",
        "ri": "cnt3472203593848019878",
        "pi": "CGlass",
        "ct": "20230120T093353,618096",
        "lt": "20230120T093353,618096",
        "et": "20280119T093353,618155",
        "ty": 3,
        "cni": 10,
        "cbs": 62,
        "st": 29
    }
}

Subscription attributes

{
    "m2m:sub": {
        "acpi": [
            "acp1994839229681685407"
        ],
        "enc": {
            "net": [
                1,
                2,
                3,
                4
            ]
        },
        "nu": [
            "/id-asn/cse-asn/CGlass"
        ],
        "rn": "sub-control-glass",
        "ri": "sub8641760446866483662",
        "pi": "cnt3472203593848019878",
        "ct": "20230120T094106,999444",
        "lt": "20230122T095921,074178",
        "et": "20280119T094106,999529",
        "ty": 23,
        "nct": 1
    }
}

CSE log debug

HTCR_10634 - ==> HTTP Request: cnt3472203593848019878                                                                                                                 HttpServer.py:205
           DEBUG   HTCR_10634 - Operation: CREATE                                                                                                                                        HttpServer.py:206
           DEBUG   HTCR_10634 - Headers:                                                                                                                                                 HttpServer.py:207
                   Host: localhost:8082
                   Connection: keep-alive
                   Content-Length: 49
                   Sec-Ch-Ua: "Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"
                   Sec-Ch-Ua-Mobile: ?0
                   User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
                   X-M2M-Ri: fivh17hl7bp
                   Content-Type: application/json;ty=4
                   Accept: application/json
                   X-M2M-Origin: CAdmin
                   X-M2M-Rvi: 3
                   Sec-Ch-Ua-Platform: "macOS"
                   Origin: http://localhost:8082
                   Sec-Fetch-Site: same-origin
                   Sec-Fetch-Mode: cors
                   Sec-Fetch-Dest: empty
                   Referer: http://localhost:8082/webui/index.html?ri=id-asn&or=CAdmin
                   Accept-Encoding: gzip, deflate, br
                   Accept-Language: en-US,en;q=0.9
           DEBUG   HTCR_10634 - Body:                                                                                                                                                    HttpServer.py:213
                   b'{\n    "m2m:cin": {\n        "con": "halow"\n    }\n}'
           DEBUG   HTCR_10634 - CREATE ID: cnt3472203593848019878, originator: CAdmin                                                                                                RequestManager.py:204
           DEBUG   HTCR_10634 - Process CREATE request for id: cnt3472203593848019878|None                                                                                               Dispatcher.py:519
           DEBUG   HTCR_10634 - Get parent resource and check permissions: cnt3472203593848019878                                                                                        Dispatcher.py:549
           DEBUG   HTCR_10634 - Retrieve local resource: cnt3472203593848019878|None for originator: None                                                                                Dispatcher.py:281
           DEBUG   HTCR_10634 - Request from CSE Originator. OK.                                                                                                                     SecurityManager.py:91
           DEBUG   HTCR_10634 - CREATING resource ri: cin486656427157705761, type: 4                                                                                                     Dispatcher.py:676
           DEBUG   HTCR_10634 - Parent ri: cnt3472203593848019878                                                                                                                        Dispatcher.py:679
           DEBUG   HTCR_10634 - Activating resource: cin486656427157705761                                                                                                                 Resource.py:213
           DEBUG   HTCR_10634 - Validating attributes                                                                                                                                      Validator.py:89
           DEBUG   HTCR_10634 - Validating resource: cin486656427157705761                                                                                                                 Resource.py:501
           DEBUG   HTCR_10634 - Child resource added: cin486656427157705761                                                                                                                     CNT.py:144
           DEBUG   HTCR_10634 - Checking subscriptions (createDirectChild) ri: cnt3472203593848019878                                                                           NotificationManager.py:231
           DEBUG   HTCR_10634 - Handling notification for notificationEventType: createDirectChild                                                                             NotificationManager.py:1016
           DEBUG   HTCR_10634 - Sending notification to: /id-asn/cse-asn/CGlass, reason: createDirectChild, asynchronous: True                                                 NotificationManager.py:1032
           DEBUG   NOT_sub864 - Sending NOTIFY request to: /id-asn/cse-asn/CGlass for Originator: /id-asn                                                                           RequestManager.py:1022
           DEBUG   NOT_sub864 - Retrieve local resource: None|cse-asn/CGlass for originator: None                                                                                        Dispatcher.py:281
           DEBUG   HTCR_10634 - Retrieve local resource: sub8641760446866483662|None for originator: None                                                                                                                                                                                                               MQTTClient.py:402
           DEBUG   NOT_sub864 - MQTT connection already created: localhost:1883                                                                                                          MQTTClient.py:463
           DEBUG   NOT_sub864 - MQTT Request ==>: /oneM2M/req/id-asn/id-asn/json                                                                                                         MQTTClient.py:574
                   Body: {'fr': '/id-asn', 'to': '/id-asn', 'ot': '20230122T093701,431237', 'op': 5, 'rqi': '2569162440163804104', 'rvi': '3', 'pc': {'m2m:sgn': {'nev': {'rep':
                   {'m2m:cin': {'con': 'halow', 'ri': 'cin486656427157705761', 'pi': 'cnt3472203593848019878', 'rn': 'cin_VFqh0lCERH', 'ct': '20230122T093701,391742', 'lt':
                   '20230122T093701,391742', 'et': '20280121T093701,391785', 'ty': 4, 'cs': 5, 'st': 24}}, 'net': createDirectChild}, 'sur': '/id-asn/sub8641760446866483662'}}}
           DEBUG   HTCR_10634 - Validating resource: cnt3472203593848019878                                                                                                                Resource.py:501
           DEBUG   HTCR_10634 - cni > mni: Removing <cin>: cin3449333533774497151                                                                                                               CNT.py:204
           DEBUG   MQTTClient - Starting actor: mid_336.153848849                                                                                                                   BackgroundWorker.py:86
           DEBUG   HTCR_10634 - Removing resource ri: cin3449333533774497151, type: 4                                                                                                    Dispatcher.py:993
           DEBUG   None       - ==> MQTT Request: /oneM2M/req/id-asn/id-asn/json                                                                                                         MQTTClient.py:166
           DEBUG   None       - Operation: NOTIFY                                                                                                                                        MQTTClient.py:158
           DEBUG   None       - Body:                                                                                                                                                    MQTTClient.py:160
                   {"fr": "/id-asn", "to": "/id-asn", "ot": "20230122T093701,431237", "op": 5, "rqi": "2569162440163804104", "rvi": "3", "pc": {"m2m:sgn": {"nev": {"rep": {"m2m:cin":
                   {"con": "halow", "ri": "cin486656427157705761", "pi": "cnt3472203593848019878", "rn": "cin_VFqh0lCERH", "ct": "20230122T093701,391742", "lt":
                   "20230122T093701,391742", "et": "20280121T093701,391785", "ty": 4, "cs": 5, "st": 24}}, "net": 3}, "sur": "/id-asn/sub8641760446866483662"}}}
           DEBUG   HTCR_10634 - Deactivating and removing sub-resources for: cin3449333533774497151                                                                                        Resource.py:255
           DEBUG   None       - <== MQTT Response (badRequest): /oneM2M/resp/id-asn/id-asn/json                                                                                          MQTTClient.py:574
                   Body: {'fr': '/id-asn', 'to': '/id-asn', 'rsc': 4000, 'op': 5, 'rqi': '2569162440163804104', 'rvi': '3', 'pc': {'m2m:dbg': 'ID too short. Must be
                   /<cseid>/<structured|unstructured>.'}}

And when i see in sendMqttRequest "to" parameter haven't been used and when build request topic, it use originator as mqtt topic receiver path.

Or maybe i am doing something wrong since i am new in oneM2M. Thank you!

ankraft commented 1 year ago

Thanks for reporting this, and also for the resources that made it easy for me to find the problem. There was an error in the MQTT binding that put the wrong ID in the topic etc. when sending notifications.

I released a new version of the master branch 0.11.2 . I hope it solves you problem.

samuelbles07 commented 1 year ago

Yes, it works!