Unable to do FOTA using leshan LWM2M
Answer
5/23/18 6:55 AM

Hello Everyone,

      I'm trying to update the firmware on the XDK using FOTA. I am using leshan LWM2M server to do the work and to host the bin file using the Californium CoAP server. Both servers are running on diffrent ports but on same machine. What I achieved is as follows:

1. Whenever I'm trying to write the file I get error  Unable to write resource / 5/0/1

2. But if I check the SD card on XDK I see one file named FIRMAWAREUPDATE.BIN, whos size is not equal to the size of the file I am updating.

3. As I try to update the firmware XDK crashesh.

Please gide ,

Best Regards,

Kedar 

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/23/18 12:10 PM as a reply to Kedar Dahivale.
Hello Kedar,

could you tell me whether the CoAP server from which you provide the binary is supporting blockwise transfer?

If I may quote the part of the specification of the Lwm2m Object Firmware Update :
A LwM2M Server MUST support block-wise transfer

Also, could you tell me what exactly you are writing to resource 5/0/1?

Again, quoting the specification for resource 5/0/1:
The URI format is defined in RFC 3986. For example, coaps://example.org/firmware is a syntactically valid URI. The URI scheme determines the protocol to be used. For CoAP this endpoint MAY be a LwM2M Server but does not necessarily need to be. A CoAP server implementing block-wise transfer is sufficient as a server hosting a firmware repository and the expectation is that this server merely serves as a separate file server making firmware images available to LwM2M Clients.

And finally, what is the size of the file FIRMWAREUPDATE.bin on your SD Card?

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/25/18 2:37 PM as a reply to Alexander Sawtschuk.

Hello Sir,

  Sorry for the late reply.

I am using the Californium CoAP server, I’ve some update on issue.

Now I am able to download full bin file on the sd card throiugh the same server., but now issue is I am unable to flash the file on the XDK. I think I am using the wrong bin file to flash. Can u please tell me which file(bin file) I should host in CoAP server and from where I will get that file?

Best Regards,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/28/18 1:58 PM as a reply to Kedar Dahivale.
Hello Kedar,

FOTA is a feature that is available with XDK Bootloader versions 1.0.0 and higher.

Does your XDK have the correct bootloader? The Bootloader Version is shown in the Devices View in the XDK-Workbench on your device. If the version is below 1.0.0, then you can not use FOTA.

If the version is correct, then the following lines should be printed in the console when you build the application:
 
INFO | Creating Firmware Over the Air (FOTA) Container
INFO | Binary File: /home/alexander/XDK-Workspace/MyProject/debug/MyProject.bin
INFO | Header Version: 0100
INFO | Product Class: 0010
INFO | Product Variant: 0000
INFO | Firmware Version: 00000000


The second line tells you the location of the binary as well.

If that is not printed, then the XDK-Workbench is not building for Bootloader version 1.1.0. Usually, the XDK-Workbench warns you, if you are using mismatched bootloader versions and the XDK would most likely not even start the application after flashing. In any case, if your XDK has bootloader version 1.1.0, then you can let the XDK-Workbench build for XDK-Workbench 1.1.0 by selecting Window > Preferences in the top menu bar.

In the new window that popped up, go to XDK > Bootloader and FOTA. There, select Bootloader version 1.1.0.

If everything is correct and the correct binary is downloaded, then FOTA should be applied correctly.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/28/18 2:56 PM as a reply to Alexander Sawtschuk.

Hello Sir,

     I have bootloader version 1.1.0 and selected correctely for the project. As per your suggestion I’ve checked the after build result and it looks fine(attaching the screenshot).

It seems that previously also I was using the correct bin file, the path is as per follow.

 INFO | Binary File: /root/XDKWorkspace/BoschXDKCloudConnectivity/debug/BoschXDKCloudConnectivity.bin

Another isssue I am facing now is, now whenever I am trying to write the file from leshan server on XDk, leshan server is unable to send the request to CoAP(Californium Server) which is hosting the bin file. Attaching the screenshot of leshan CoAP messages. I am new to CoAP so unable to understand the issue. 

As you mentioned in your last comment about applying FOTA correctly, can you please elaborate on the same?

Thanking You,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/28/18 4:37 PM as a reply to Kedar Dahivale.
Hello Kedar,

as per my understanding, since resource 5/0/3 is showing the value 2, which basically means that the device is ready to update, then you need to press the Exec button on resource 5/0/2.

To put it shortly, in state 1 on resource 5/0/3, the XDK is downloading the binary. In state 2, the XDK is ready to update. On your next attempt, I recommend to press the Observe button of resource 5/0/3 first, then insert a URL on resource 5/0/1.

If the state changes from 1 to 2 then, I think you are good to go. If this is not the case, then I would need to look into how to execute a Firmware Update myself, so I can provide better support. The theory behind this is pretty clear - I just need to check which practical issues can arise.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/29/18 8:32 AM as a reply to Alexander Sawtschuk.

Hello Sir,

       Thank you so musch sir now it can work!! 

      Thank you.

Best Regards,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
5/29/18 1:36 PM as a reply to Kedar Dahivale.
Hello Kedar,

I am always glad to help and to hear that it is working now.

Please feel free to ask if you have any further questions or concerns.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/5/18 8:56 AM as a reply to Alexander Sawtschuk.

Hello Sir,

    As you mentioned in your comment

"as per my understanding, since resource 5/0/3 is showing the value 2, which basically means that the device is ready to update, then you need to press the Exec button on resource 5/0/2." 

is it possible to automate this process from XDK side ? as every time  I have to press Exec button.

Thanks and Reagads,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/5/18 1:48 PM as a reply to Kedar Dahivale.
Hello Kedar,

unfortunately, the resource indicating the state of the firmware download (i.e. resource /5/0/3) is hidden inside the FOTA API. As such, a firmware update should not be executed, since the state is not known.

In general, I would recommend to use CoAP or HTTP to access the Leshan API for executing the firmware update, instead of trying to do this on the XDK.

For example, the following command will trigger the execute on resource /5/0/2, given that you execute it on the server that hosts the Leshan Server, and its http end point is on port 8080.

 
curl localhost:8080/api/clients/XDK110_Flight/5/0/2 -d "1"


You could also write the new firmware's URI to resource 5/0/1 using the same command structure:

 

curl localhost:8080/api/clients/XDK110_Flight/5/0/1 -d "coap://server-url:5683/newfirmware.bin"


And you can also read the current state using:

 
curl localhost:8080/api/clients/XDK110_Flight/5/0/3


Given these commands, you can combine them into a script which first writes a new URI, then reads the state on /5/0/3 every second until the state's value is 2 and then you write "1" to /5/0/3

During all of this, keep in mind that these are workarounds. The Leshan Server is just a demo, not a full-fledged production server. Depending on your motivation towards learning Java, you could implement such a functionality in the server itself.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/6/18 2:21 PM as a reply to Alexander Sawtschuk.

Hello Sir,

   Thank you for your solution.

I have another qustion as currently I am using the Bosch cloud connectivity example which has so many objects. and I want to expose only FOTA object. As I was reading through the old posts I found the implementation is done using FotaDownload.h and FotaDownload.c So does it mean I have to use these 2 files to expose the FOTA to leshan server.? can u please guide me on the same

Regards,

Kedar

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/7/18 2:14 PM as a reply to Kedar Dahivale.
Hello Kedar,

I am always glad to help and glad to hear that my solution works for you.

As for only exposing the FOTA implementation, I would recommend to create a new project that starts Lwm2m with only Fota enabled. I think, trying to remove everything from the BoschXdkCloudConnectivity example's code that has nothing to do with Fota will be more difficult than starting from the ground up. The Fota implementation should be done similiarly to how it is done in the BoschXdkCloudConnectivity example.

For Lwm2m, I recommend to take a look at the guide in the XDK Learning Section

Otherwise, you can deactivate updating the sensors (although the sensors are still exposed) in Lwm2mObject_SensorDevice.c on line 85 where SensorDeviceResources is defined. For IDs 1 to 7 in that struct, set the value to false instead of true. This way, the sensors are shown, but they have a static value of 0.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex

EDIT: It turns out that you can also remove objects in Lwm2mObjects > Lwm2mObjects.c. There, you will find the array ObjectInstances and you can remove the objects you do not require. For testing, I removed everything except the Firmware object (lines 75 to 79) and then it only showed the Firmware resource and the Server resource in Leshan.
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/7/18 3:10 PM as a reply to Alexander Sawtschuk.

Hello Sir,

     Thank you for your support!

I made new program and followed the tutorial of LWM2M now I can see the FOTA object on the server, but when I try to update the firmware there is no change in state of update result 5/0/5 and state 5/0/3. Should I include FotaDonload.c and FotaDownload.h file also in my project?

Best Regards,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/7/18 3:50 PM as a reply to Kedar Dahivale.
Hello Kedar,

first I would like to make you aware of my edit to the last response (it's at the very end). Since you are using that example only to flash a new firmware, I think that edit wouldould actually be the easiest solution to your use case.

Otherwise, considering the new application you are creating, only exposing the FOTA Object to Leshan does not define how it is handled on the XDK. As such, integrating FotaDownload.c and FotaDownload.h will definitely help, but you also need to take a look at how these two files are integrated into the BoschXdkCloudConnectivity example.

I.e., every reference to Fota should be investigated, and an equivalent usage should be implemented.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/13/18 11:30 AM as a reply to Alexander Sawtschuk.

Hello Sir,

    Thank you for your suggestion. It worked  by removing the other object instances.

 But I have an update question , I created new application and to create application followed the implementation as per your suggestion. Currently I can read the status on resources 5/0/3 and 5/0/5. An also I can execute the Firmware if the bin file is already on SD card(I tried manually putting the bin file on sd card and then flashed using leshan resource 5/0/2) but the issue I am facing now is whenever I want to download new firmware, it is giving me error download failed i.e. I see I see change of state at 5/0/3 from 0 to 8. and I am unable to figure out the reson.

Please guide me.

Best Regards,

Kedar  

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/14/18 8:39 AM as a reply to Kedar Dahivale.
Hello Kedar,

it is hard to diagnose the issue without knowing the current code. Would it be possible for you to upload your current version on github (or a code-sharing platform of your choosing)?

Otherwise, I would like you to give me a brief description of what your code implements in regards to Fota. Did you integrate the Fota-Related codes from the BoschXdkCloudConnectivity example's source files Lwm2mClient.c , Lwm2mInterface.c and Lwm2mObjects_Device.c ?

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/14/18 12:58 PM as a reply to Alexander Sawtschuk.

Hello Sir,

    I have uploaded the project files on github link for the same is https://github.com/kedardahivale/xdk

I have tried my best and mimicked all the FOTA related implementation from  BoschXdkCloudConnectivity example . Please check the implementation. 

Thanks and Regards,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/15/18 2:48 PM as a reply to Kedar Dahivale.
Hello Kedar,

Thank you for providing your source code on Github.

Unfortunately, I was not able to identify the issue with your code. This might be related to FOTA API, since I am almost always getting the error Error in package ID: 26 Severity code: 3 Error code: 89, module ID : 5 after a sucessful registration attempt before the FOTA initialization is done. On that behalf, could you please tell me if you are receiving the same error after a successful registration?

Otherwise, an alternative approach would be to downsize the BoschXdkCloudConnectivity example and remove every sensor object and their implementation. I.e., instead of building the code up, you could tear it down. Removing sensors should be easy enough, but with anything else, side-effects may occur that prevent Fota from working.

Additionally, could you share the implementation of your CoaP server? I have tried to test Fota myself, but apparently, even with the original code, the download does not start. It may be an issue with my setup, though.

On a side-note, the next XDK update will introduce new FOTA API, which will be completely independent of any network protocol (The new API basically looks for firmware.bin on the SD card and tries to flash it). Depending on the use-case, I would recommend to wait for that new API.

Again, I am sorry that I was not able to find the issue, but if there is anything else I can help you with, feel free to ask, as always.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/18/18 10:59 AM as a reply to Alexander Sawtschuk.

Hello Sir,

     I have not received any error like the one you mentioned, I get message of succesful regestraion and FOTA Init done. I will try to downsize the BoschXdkCloudConnectivity example and about CoAP server I am using californium coAP server(simple file server) implementation can be found here https://github.com/eclipse/californium/tree/2.0.x . I will try to work on BoschXdkCloudConnectivity example if I succeed I will let you know otherwise I will wait for new FOTA API.

Thanks and  Regards,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/18/18 2:40 PM as a reply to Kedar Dahivale.
Hello Kedar, thank you for the information regarding the CoAP file server. I will wait for the results of your attempt at downsizing the BoschXdkCloudConnectivity example. Kind regards, Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/19/18 6:35 AM as a reply to Alexander Sawtschuk.

Hello Sir,

 I am trying to downsize the BoschXdkCloudConnectivity example; I have removed all the unnecessary but whenever I am building the project I am getting error

 make[1]: *** No rule to make target '/root/XDK-Workspace/CloudConnect/debug/objects/Lwm2mObjects/Lwm2mObject_Humidity.o', needed by '/root/XDK-Workspace/CloudConnect/debug/CloudConnect.out'.  Stop.
recipe for target 'debug' failed 

I am unable to figure out the error?

Best Regards,

Kedar 

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/19/18 7:41 AM as a reply to Kedar Dahivale.

Hello ,

     I have fund the waz around that error , I needed to remove application file declaration from make file.

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/19/18 11:27 AM as a reply to Kedar Dahivale.
Hello Kedar,

I am glad to hear that you were able to solve the error.

Kind regards,
Alex
0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/20/18 1:05 PM as a reply to Alexander Sawtschuk.

Hello ,

    I would like to update on issue, currently I am facing strange issue which is as follows,

There is no FIRMWAREUPDATE.BIn file on SD card yet whenever XDK connects to leshan and if I read the resource /5/0/3 it shows me value 2 and at resource /5/0/5 = 8 attaching th escreenshot of the same.

please guide,

Best Regards,

Kedar Dahivale

0 (0 Votes)
RE: Unable to do FOTA using leshan LWM2M
Answer
6/21/18 2:13 PM as a reply to Kedar Dahivale.
Hello Kedar,

This is indeed strange behavior.

Just for clarification, you used the same Californium Server you used for Firmware Updates with the original BoschXdkCloudConnectivity example. Is that correct? Or have you made any modifications after that?

Additionally, which version of the BoschXdkCloudConnectivity are you using now? The original one, the downsized one, or the one rebuilt from scratch that only implements FOTA?

After looking into the FOTA source code of the Platform implementation, I have noticed that the implementation uses the SD Card, but it does not initialize it. Do you have code for initializing the SD Card Driver and mounting the partition on the SD Card?

If this is not the case, I would recommend to take a look into the SD Card Guide in the Learning Section . This guide features code snippets for initializing the SD Card Driver and mounting the partition.

Otherwise, I would recommend to take a look at the network traffic between your XDK and the Californium Server (using Wireshark or something similar), to determine if the firmware is being downloaded at all.

Please let me know if this was helpful and feel free to ask if you have any further questions.

Kind regards,
Alex
0 (0 Votes)