MLopezJ / nRF-Asset-Tracker-through-Coiote-flow

Module and data flow of the nRF Asset Tracker by its integration with Coiote from AVSystem
0 stars 0 forks source link

Complete flow: Thingy - Coiote - Device Twin #5

Open MLopezJ opened 1 year ago

MLopezJ commented 1 year ago

is desired to see all the integration working in the complete flow. Update a value in the device, pushing button for example, see it change in the Coiote Dashboard and reflect it in the device twin as well.

...

In Azure, the device was created after the integration. Data in device twin was not the expected and it was not updated with the values shown in Coiote Dashabort. ....

Originally posted by @MLopezJ in https://github.com/MLopezJ/asset-tracker-cloud-coiote-azure-converter-js/issues/3#issuecomment-1446051154

Right now it is not possible to see this behavior.

MLopezJ commented 1 year ago

Approach 1:

  1. Take a device already connected to Coiote dashboard. (firmware configuration)
  2. Remove device from Coiote dashboard
  3. Add device to Coiote dashboard
  4. Connect device to Azure in Coiote (device in IoT already exist but twin result is not the expected.)

Thingy91 credentials:

Result

Data is been sending to Coiote properly but it is not reflected in device twin

MLopezJ commented 1 year ago

Approach 2:

  1. Take a device already connected to Coiote dashboard.
  2. Remove device from Azure
  3. Remove device from Coiote dashboard
  4. Add device to Coiote dashboard
  5. Connect device to Azure in Coiote

Result

Data is been sending to Coiote properly but it is not reflected in device twin

Old device twin

{
    "deviceId": "urn:imei:351358815340515",
    "etag": "AAAAAAAAAAE=",
    "deviceEtag": "MTU3MDQyODA2",
    "status": "enabled",
    "statusUpdateTime": "0001-01-01T00:00:00Z",
    "connectionState": "Disconnected",
    "lastActivityTime": "0001-01-01T00:00:00Z",
    "cloudToDeviceMessageCount": 0,
    "authenticationType": "sas",
    "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
    },
    "modelId": "",
    "version": 2,
    "properties": {
        "desired": {
            "$metadata": {
                "$lastUpdated": "2023-02-27T11:56:04.1648972Z"
            },
            "$version": 1
        },
        "reported": {
            "$metadata": {
                "$lastUpdated": "2023-02-27T11:56:04.1648972Z"
            },
            "$version": 1
        }
    },
    "capabilities": {
        "iotEdge": false
    }
}

new device twin

{
    "deviceId": "urn:imei:351358815340515",
    "etag": "AAAAAAAAAAE=",
    "deviceEtag": "Mzc1Njc1NjAx",
    "status": "enabled",
    "statusUpdateTime": "0001-01-01T00:00:00Z",
    "connectionState": "Disconnected",
    "lastActivityTime": "0001-01-01T00:00:00Z",
    "cloudToDeviceMessageCount": 0,
    "authenticationType": "sas",
    "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
    },
    "modelId": "",
    "version": 2,
    "properties": {
        "desired": {
            "$metadata": {
                "$lastUpdated": "2023-02-28T13:16:00.2070304Z"
            },
            "$version": 1
        },
        "reported": {
            "$metadata": {
                "$lastUpdated": "2023-02-28T13:16:00.2070304Z"
            },
            "$version": 1
        }
    },
    "capabilities": {
        "iotEdge": false
    }
}
MLopezJ commented 1 year ago

Approach 3: Create new LwM2M Template in Coiote

Previous template name is Template without Telemetry and objects described there were related to expected objects in Anjay-client. Current firmware used is Asset Tracker v2.

  1. Take a device already connected to Coiote dashboard.
  2. Remove device from Azure
  3. Remove device from Coiote dashboard
  4. Add device to Coiote dashboard
  5. Create new template
  6. Connect device to Azure in Coiote using new template

Result

Data is been sending to Coiote properly but it is not reflected in device twin

{
    "deviceId": "urn:imei:351358815340515",
    "etag": "AAAAAAAAAAE=",
    "deviceEtag": "ODg2NDE0NDQ3",
    "status": "enabled",
    "statusUpdateTime": "0001-01-01T00:00:00Z",
    "connectionState": "Disconnected",
    "lastActivityTime": "0001-01-01T00:00:00Z",
    "cloudToDeviceMessageCount": 0,
    "authenticationType": "sas",
    "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
    },
    "modelId": "",
    "version": 2,
    "properties": {
        "desired": {
            "$metadata": {
                "$lastUpdated": "2023-02-28T13:35:18.7804381Z"
            },
            "$version": 1
        },
        "reported": {
            "$metadata": {
                "$lastUpdated": "2023-02-28T13:35:18.7804381Z"
            },
            "$version": 1
        }
    },
    "capabilities": {
        "iotEdge": false
    }
}
MLopezJ commented 1 year ago

Approach 4

In all the last approaches, the device twin contains this value: "connectionState": "Disconnected",. This approach is about follow AV System tutorial with Anjay-client and see if that value is returned too.

  1. Remove device from Azure
  2. Remove device from Coiote dashaboard
  3. Write new firmware with Programer
  4. Create new device in Coiote
  5. Use minicom to connect with Anjay and set config credentials
  6. start anjay server
  7. Connected device with Azure ussing "no telemetry" template

Result

{
    "deviceId": "aa",
    "etag": "AAAAAAAAAAE=",
    "deviceEtag": "MjMzNTE0Njg4",
    "status": "enabled",
    "statusUpdateTime": "0001-01-01T00:00:00Z",
    "connectionState": "Disconnected",
    "lastActivityTime": "0001-01-01T00:00:00Z",
    "cloudToDeviceMessageCount": 0,
    "authenticationType": "sas",
    "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
    },
    "modelId": "",
    "version": 2,
    "properties": {
        "desired": {
            "$metadata": {
                "$lastUpdated": "2023-02-28T14:40:39.0837179Z"
            },
            "$version": 1
        },
        "reported": {
            "$metadata": {
                "$lastUpdated": "2023-02-28T14:40:39.0837179Z"
            },
            "$version": 1
        }
    },
    "capabilities": {
        "iotEdge": false
    }
}

Thingy91 credentials:

  • endpoint: urn:imei:351358815340515
  • psk: 000102030405060708090a0b0c0d0e0f

Tried to use the last credentials but anjay complain about long in psk. "aa" and "aa" were used instead.

MLopezJ commented 1 year ago

Situation related to Approach 4: Anjay client

Connection between device and Coiote dashboard is not persistent.

In the attempt, the connection only established first time but after that data were not sent to Coiote Dashboard.

This situation was already described here:

Create new device on environments and test flow

It is interesting how the connection between Thingy:91 and Coiote sometimes is not working as expected. In the attempt that was made to create a new environment, this step fails and was needed to use the previous device connection

Receive data in Coiote Dashboard from Thinghy:91

  • Use already generated firmware
  • Update Thingy config using anjay
  • Result: Not able to connect to Coiote after some tries
  • Re write firmware with Programmer
  • Turn off and on the Thingy
  • Update Thingy config using anjay
  • After try again result was the same
  • Update Thingy config with already connected device info

It is not the main objective of this project so no effort is going to be made in this concern.

Originally posted by @MLopezJ in https://github.com/MLopezJ/asset-tracker-cloud-coiote-azure-converter-js/issues/8#issuecomment-1429342996

In the current case, the connection was failing. I stopped and started the client several time but same behavior keep repeating. I let it fail for 1 hour and after that, I stopped the client and relaunch,and then it works!

However, Device twin is not updated with expected data

MLopezJ commented 1 year ago

Why device twin says the connection is "disconnected" when connection was created succesfully and data is being sent from Device to Coiote?

How can I see device twin logs?

MLopezJ commented 1 year ago

Approach 4: retry

Commands used to connect with Anjay

ls /dev/serial/by-id/ -ls
minicom --device /dev/ttyACM0 --baudrate 115200

Result

Data is been sending to Coiote properly but it is not reflected in device twin. Connection state of device twin is disconnected

Same result as previous try.

New try

Result

Same situation described here: https://github.com/MLopezJ/nRF-Asset-Tracker-through-Coiote-flow/issues/5#issuecomment-1448466044

Retry: Template with Telemetry data

Result

Same result than previously.

MLopezJ commented 1 year ago

How can I see device twin logs?

Device Activity log is not providing useful information. Screenshot from 2023-03-02 13-43-29

MLopezJ commented 1 year ago

Set configuration as Approach 3

It is the most realistic scenario in order with what it is needed.

Connection was not possible

[00:08:11.352,386] <inf> app_event_manager: CLOUD_EVT_CONNECTION_TIMEOUT                                                            
[00:08:11.352,966] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:351358815340515                                          
[00:08:11.352,996] <wrn> cloud_module: Cloud connection establishment in progress                                                   
[00:08:11.352,996] <wrn> cloud_module: New connection attempt in 512 seconds if not successful                                      
[00:08:11.990,356] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:351358815340515' with client lifetime 43200 
[00:08:12.027,099] <dbg> lwm2m_security: load_credentials_to_modem: Existing credentials found on modem                             
[00:08:12.676,422] <inf> net_lwm2m_engine: Connected, sock id 0                                                                     
[00:08:12.857,482] <err> net_lwm2m_rd_client: Failed with code 4.0 (Bad Request). Not Retrying.                                     
[00:08:12.859,252] <wrn> lwm2m_integration: LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE                                              
[00:08:12.859,344] <inf> app_event_manager: CLOUD_EVT_DISCONNECTED     

Try to connect with LwM2M client sample

Connection works. Data is been sending from thingy to Coiote properly but it is not reflected in device twin. Connection state of device twin is disconnected

Try to connect with Asset Tracker v2 firmware

Connection was not possible

[00:01:48.519,592] <inf> app_event_manager: CLOUD_EVT_CONNECTION_TIMEOUT
[00:01:48.520,172] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:351358815340515
[00:01:48.520,202] <wrn> cloud_module: Cloud connection establishment in progress
[00:01:48.520,202] <wrn> cloud_module: New connection attempt in 128 seconds if not successful
[00:01:49.311,096] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:351358815340515' with client lifetime 43200
[00:01:49.357,391] <dbg> lwm2m_security: load_credentials_to_modem: Existing credentials found on modem
[00:01:49.913,879] <inf> net_lwm2m_engine: Connected, sock id 0
[00:01:50.090,057] <err> net_lwm2m_rd_client: Failed with code 4.0 (Bad Request). Not Retrying.
[00:01:50.091,949] <wrn> lwm2m_integration: LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE
[00:01:50.092,071] <inf> app_event_manager: CLOUD_EVT_DISCONNECTED

Retry to connect with LwM2M client sample

+CSCON: 0
+CSCON: 1
[00:00:43.043,243] <inf> app_event_manager: CLOUD_EVT_CONNECTION_TIMEOUT
[00:00:43.043,823] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:351358815340515
[00:00:43.043,853] <wrn> cloud_module: Cloud connection establishment in progress
[00:00:43.043,853] <wrn> cloud_module: New connection attempt in 64 seconds if not successful
[00:00:43.821,472] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:351358815340515' with client lifetime 43200
[00:00:43.856,201] <dbg> lwm2m_security: load_credentials_to_modem: Existing credentials found on modem
[00:00:44.520,996] <inf> net_lwm2m_engine: Connected, sock id 0
[00:00:44.621,551] <err> net_lwm2m_rd_client: Failed with code 4.0 (Bad Request). Not Retrying.
[00:00:44.623,504] <wrn> lwm2m_integration: LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE
[00:00:44.623,596] <inf> app_event_manager: CLOUD_EVT_DISCONNECTED
+CSCON: 0
MLopezJ commented 1 year ago

Remove Existing credentials found on modem

MLopezJ commented 1 year ago

cloud_connect failed, error: -119

cloud_connect failed, error: -119 appears as part of the logs but I was not able do identify what the error code -119 means.

Knows it could give a little bit of context about the issue.

[00:00:10.160,919] <inf> lwm2m_security: Modem connection restored
[00:00:10.169,311] <inf> app_event_manager: MODEM_EVT_LTE_CONNECTED
[00:00:10.170,135] <err> cloud_module: cloud_connect failed, error: -119
[00:00:10.170,166] <wrn> cloud_module: Cloud connection establishment in progress
[00:00:10.170,166] <wrn> cloud_module: New connection attempt in 32 seconds if not successful
[00:00:10.739,868] <inf> net_lwm2m_engine: Connected, sock id 0
[00:00:10.856,262] <err> net_lwm2m_rd_client: Failed with code 4.0 (Bad Request). Not Retrying.
[00:00:10.858,215] <wrn> lwm2m_integration: LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE
[00:00:10.858,306] <inf> app_event_manager: CLOUD_EVT_DISCONNECTED
MLopezJ commented 1 year ago

Remove Existing credentials found on modem

  1. Flash at_client:
  2. List credentials: AT%CMNG=1
# example output
%CMNG: 0,6,"0606060606060606060606060606060606060606060606060606060606060606"
%CMNG: 42,0,"56AE01E6773BDAEC4BFB216D4005ADB06E4F680BD8BFB8BE4C683CE921681897"
%CMNG: 42,1,"320E7F17AB1C7B8E35851862DE358A0D3FDD770C4A26DA7AC29B63EBB201F710"
%CMNG: 42,2,"3A78F6F7C2297288FFEB3E53ED9D92963D32A6BA1288011EA4A3DCC0033F28DD"
%CMNG: 35724861,3,"D65DF89F702EEC58CA3C7BF2001C9FFC7CD80553AE01D42A799BA26756142D96"
%CMNG: 35724861,4,"3F89EB2281D1A29137E6D5AE2A4F0F1D04E6688E72083938C2E8983F522DE00E"
%CMNG: 35724862,3,"D65DF89F702EEC58CA3C7BF2001C9FFC7CD80553AE01D42A799BA26756142D96"
%CMNG: 35724862,4,"3F89EB2281D1A29137E6D5AE2A4F0F1D04E6688E72083938C2E8983F522DE00E"
%CMNG: 4294967293,10,"2C43952EE9E000FF2ACC4E2ED0897C0A72AD5FA72C3D934E81741CBD54F05BD1"
%CMNG: 4294967294,6,"7EA0BF5A4A79790D538EF211AFFDC723FF3D402D51A4EC29064155A4658529EE"
%CMNG: 4294967292,11,"B2C46C2AE7C81943A8BD6DD4ED2A50B659A225A098A177BACB575459CD57CAEF"

tag 42 refers to AWS, 11 to Azure.

  1. delete an entry: AT%CMNG=3,TAG-ID,CONTENT-TYPE

example: AT%CMNG=3,35724862,4

Flash at_client

MLopezJ commented 1 year ago

Check nRF Cloud status

MLopezJ commented 1 year ago

Test fllow with nRF9160-DK

the SIM CARD used is the same than used in tests with the Thingy:91

Result

Push button test

I will push a button from mRF9160 DK device. I'm expecting to see the event in the minicom console, then see the "5500 Digital input state" from "3347 Push button" object change to true and same in the device twin.

Result

ConnectionState is "connected" and "$lastupdate" is from ""2023-03-03T12:10:06.5346995Z"" . "Version" is 9.

MLopezJ commented 1 year ago

Test fllow with Thingy:91

firmware used will be LwM2M-client sample

ConnectionState is "Disconnected" and "$lastupdate" is from "2023-03-02T13:32:22.0173103Z"" . "Version" is 2.

MLopezJ commented 1 year ago

test flow with Thingy:91 + Asset Tracker firmware

Was not possible to connect to Coiote with Thingy:91 + Asset Tracker firmware

MLopezJ commented 1 year ago

test flow with Thingy:91 + Asset Tracker firmware part II

Steps

  1. Remove all applications from nRF Connect
  2. Update value for CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP to n in overlay-lwm2m.conf
  3. Add asset_tracker_v2 folder as application to nRF Connect
  4. Edit build configuration: add overlay-lwm2m.conf as Kconfig fragments
  5. Select thingy91_nrf9160_ns as board
  6. Build configuration
  7. Erase and flash to board

Connection with Coiote using Thingy:91 + Asset Tracker firmware was possible. But push button object doesnt change in Coiote dashboard and device twin is not updated

MLopezJ commented 1 year ago

Asset Tracker v2 objects in Coiote

1 - LwM2M Server

Screenshot from 2023-03-07 13-03-06

3 - Device

Screenshot from 2023-03-07 13-04-26

4 - Connectivity Monitoring

Screenshot from 2023-03-07 13-05-59

5 - Firmware Update

Screenshot from 2023-03-07 13-06-33

6 - Location

Screenshot from 2023-03-07 13-06-59

3303 - Temperature

Screenshot from 2023-03-07 13-22-58

3304 - Humidity

Screenshot from 2023-03-07 13-23-26

3323 - Pressure

Screenshot from 2023-03-07 13-24-02

3347 - Push button

Screenshot from 2023-03-07 13-24-41

10256 - ECID-Signal Measurement Information

Screenshot from 2023-03-07 13-25-07

50001 - Location Assistance

Screenshot from 2023-03-07 13-25-35

50009 Configuration

Screenshot from 2023-03-07 13-26-03

MLopezJ commented 1 year ago

Update NCS version to 2.3.0

Version used was 2.0.2 but newest is 2.3.99. There is not any reason to use 2.0.2 and not the newest version. 2.3.0 is the version than is going to be installed.

Change done following the next link: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html

Open NCS 2.3.0

For the connection, the same steps described here were followed. https://github.com/MLopezJ/nRF-Asset-Tracker-through-Coiote-flow/issues/5#issuecomment-1457941208

Result

Connection with Coiote was established. 50009 - Configuration object was updated with new props as 8 - Accelerometer inactivity threshold and 9 - Accelerometer inactivity timeout.

Push button is not updated when button in the device is pushed.

Device twin is not updated.

MLopezJ commented 1 year ago

Device twin is not updated.

Max size of device twin object could be the reason why device twin is not updated.

More info here: Implications in order with Azure definitions