This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use the latest version of Californium

Hi, 

I am trying to following the instructions at: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.iotsdk.v0.9.0%2Fiot_sdk_user_guides_java_coaps.html

but the directory paths of Californium has deviated quite a bit since this was published. Do you have some updated instructions on how to use Californium with your IoT examples?

Thanks very much. 

Parents
  • Here is an updated version of the guide:

    (https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.iotsdk.v0.9.0%2Fiot_sdk_user_guides_java_coaps.html)

    Prerequisites:

    - Java Developlment Kit

    - Eclipse IDE for Java

    - Git

    - Californium source code. Use git to clone to a local directory. This guide is based on the 2.4.1 tag.

    - Californium Tools source code. Use git to clone to a local directory. This guide is based on the 2.4.1 tag.

    - This guide is based on nRF5 SDK version 16.0.0 but uses updated Java source files. The new files are attached at the bottom.


    Preparing the workspace

    Add supplied files to the local repositories

    1. Copy the secure CoAP client applcation (1 java source file, don't copy the directory) from coap_guide/pc_client into <Local Repositories>/californium.tools/cf-client/src/main/java/org/eclipse/californium/tools

    2. Copy the secure CoAP server application (2 Java source files, don't copy the directory) from coap_guide/pc_server into <Local Repositories>/californium/demo-apps/cf-secure/src/main/java/org/eclipse/californium/examples

    Import projects

    1. Open a blank workspace in Eclipse.

    2. Choose File menu > Import... and select Maven > Existing Maven Projects.

    3. Select the directory where you cloned the Californium repository and click Finish.

    4. Repeat steps 2 and 3 with the Californium Tools project.

    Change settings

    1. Open the following file: <Local Repositories>/californium/scandium-core/src/main/java/org/eclipse/californium/scandium/config/DtlsConnectorConfig.java

    2. On line 184 set retransmissionTimeout to 20000:

    private Integer retransmissionTimeout = 20000;

    4. Save and close DtlsConnectoConfig.java.

    5. Open the following file: <Local Repositories>/californium/californium-core/src/main/java/org/eclipse/californium/core/network/config/NetworkConfigDefaults.java

    6. On line 197 set the default value for ACK_TIMEOUT to 200000:

    config.setInt(NetworkConfig.Keys.ACK_TIMEOUT, 200000);

    7. Save and close NetworkConfigDefault.java


    Known limitations

    When trying the examples, there are some limitations and behavior that should be taken into account:

    1. When sending the first request from the nRF5x DK, the DTLS handshake phase might take up to 3 minutes to complete.

    2. Since the example has no way of knowing if a DTLS session is closed, it cannot free its resources until it is reset. if you invoke the client multiple times, the dev kit will not be able to establish a new session. From the client side, you will appear to get a timeout.

    3. If you modify the client to use an unsupported cipher suite, you will get a timeout when trying to connect.


    Running a secure CoAP server

    1. Open the secure CoAP server implementation: <Local Repositories>/californium/demo-apps/ch-secure/src/main/java/org/eclipse/californium/examples/Nrf5xSecureServer.java

    2. On line 99 set the IPv6 address of the local interface that is to be used. E.g.:

    InetAddress myIPv6Addr = Inet6Address.getByName("2001:db8:ac10:fe01::1");

    3. The secure server is ready to be started by pressing Ctrl+F11.

    The expected output of the server is as follows:

    (...)
    Secure CoAT server powered by Scandium (Sc) is listening on port 5684


    Running a secure CoAP client

    1. Open the secure CoAP client implementation: <Local Repositories>/californium.tools/cf-client/src/main/java/org/eclipse/californium/tools/Nrf5xConsoleClient.java

    2. On line 224 set the IPv6 address of the local interface that is to be used as the source of the CoAP requests. E.g.:

    InetAddress myIPv6Addr = Inet6Address.getByName("2001:db8:ac10:fe01::1");

    3. To view the documentation of the application run it without command line arguments.

    4. In Eclipse, choose the Run menu > Run configuration... item to create a run configuration for Nrf5xConsoleClient.java with the correct command line arguments. Uase coaps as URI scheme for secure requests.

    Run configuration for Nrf5xConsoleClient.java. Replace REMOTE_SERVER_IPv6_ADDRESS with actual IPv6 address of the server.

    If the DTLS handshake is successfu, the server will print the following lines to the console (these lines will be interleaved with other messages that pertain to the DTLS handshake):

    (...)
    
    16 INFO [MessageTracer]: /2001:0DB8:AC10:FE01:0:0:0:1:5694 ==> req CON-GET    MID=14675, Token=0e6e0e5d, OptionSet={"Uri-Path":[".well-known","core"], "Content-Format":"text/plain"}, "" - (org.eclipse.californium.core.network.interceptors.MessageTracer.java:54) receiveRequest() in thread pool-1-thread-2 at (2015-05-26 13:41:23)
    16 INFO [MessageTracer]: /2001:0DB8:AC10:FE01:0:0:0:1:5694 <== res ACK-2.05   MID=14675, Token=0e6e0e5d, OptionSet={"Content-Format":"application/link-format"}, "</lights>,</lights/l".. 22 bytes - (org.eclipse.californium.core.network.interceptors.MessageTracer.java:44) sendResponse() in thread pool-1-thread-2 at (2015-05-26 13:41:23)
    
    (...)

    The expected output of the client is a follows (these lines will be interleaved with other messages that pertain to the DTLS handshake):

    (...)
    
    ==[ CoAP Response ]============================================
    MID    : 14675
    Token  : 0e6e0e5d
    Type   : ACK
    Status : 2.05
    Options: {"Content-Format":"application/link-format"}
    Payload: 107 Bytes
    ---------------------------------------------------------------
    </lights>,</lights/led3>;title="nRF DK Resource",</lights/led4>;title="nRF DK Resource",</.well-known/core>
    ===============================================================
    Time elapsed (ms): 1100
    
    Discovered resources:
    </lights>,</lights/led3>;title="nRF DK Resource",</lights/led4>;title="nRF DK Resource",</.well-known/core>

    coap_guide.zip

Reply
  • Here is an updated version of the guide:

    (https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.iotsdk.v0.9.0%2Fiot_sdk_user_guides_java_coaps.html)

    Prerequisites:

    - Java Developlment Kit

    - Eclipse IDE for Java

    - Git

    - Californium source code. Use git to clone to a local directory. This guide is based on the 2.4.1 tag.

    - Californium Tools source code. Use git to clone to a local directory. This guide is based on the 2.4.1 tag.

    - This guide is based on nRF5 SDK version 16.0.0 but uses updated Java source files. The new files are attached at the bottom.


    Preparing the workspace

    Add supplied files to the local repositories

    1. Copy the secure CoAP client applcation (1 java source file, don't copy the directory) from coap_guide/pc_client into <Local Repositories>/californium.tools/cf-client/src/main/java/org/eclipse/californium/tools

    2. Copy the secure CoAP server application (2 Java source files, don't copy the directory) from coap_guide/pc_server into <Local Repositories>/californium/demo-apps/cf-secure/src/main/java/org/eclipse/californium/examples

    Import projects

    1. Open a blank workspace in Eclipse.

    2. Choose File menu > Import... and select Maven > Existing Maven Projects.

    3. Select the directory where you cloned the Californium repository and click Finish.

    4. Repeat steps 2 and 3 with the Californium Tools project.

    Change settings

    1. Open the following file: <Local Repositories>/californium/scandium-core/src/main/java/org/eclipse/californium/scandium/config/DtlsConnectorConfig.java

    2. On line 184 set retransmissionTimeout to 20000:

    private Integer retransmissionTimeout = 20000;

    4. Save and close DtlsConnectoConfig.java.

    5. Open the following file: <Local Repositories>/californium/californium-core/src/main/java/org/eclipse/californium/core/network/config/NetworkConfigDefaults.java

    6. On line 197 set the default value for ACK_TIMEOUT to 200000:

    config.setInt(NetworkConfig.Keys.ACK_TIMEOUT, 200000);

    7. Save and close NetworkConfigDefault.java


    Known limitations

    When trying the examples, there are some limitations and behavior that should be taken into account:

    1. When sending the first request from the nRF5x DK, the DTLS handshake phase might take up to 3 minutes to complete.

    2. Since the example has no way of knowing if a DTLS session is closed, it cannot free its resources until it is reset. if you invoke the client multiple times, the dev kit will not be able to establish a new session. From the client side, you will appear to get a timeout.

    3. If you modify the client to use an unsupported cipher suite, you will get a timeout when trying to connect.


    Running a secure CoAP server

    1. Open the secure CoAP server implementation: <Local Repositories>/californium/demo-apps/ch-secure/src/main/java/org/eclipse/californium/examples/Nrf5xSecureServer.java

    2. On line 99 set the IPv6 address of the local interface that is to be used. E.g.:

    InetAddress myIPv6Addr = Inet6Address.getByName("2001:db8:ac10:fe01::1");

    3. The secure server is ready to be started by pressing Ctrl+F11.

    The expected output of the server is as follows:

    (...)
    Secure CoAT server powered by Scandium (Sc) is listening on port 5684


    Running a secure CoAP client

    1. Open the secure CoAP client implementation: <Local Repositories>/californium.tools/cf-client/src/main/java/org/eclipse/californium/tools/Nrf5xConsoleClient.java

    2. On line 224 set the IPv6 address of the local interface that is to be used as the source of the CoAP requests. E.g.:

    InetAddress myIPv6Addr = Inet6Address.getByName("2001:db8:ac10:fe01::1");

    3. To view the documentation of the application run it without command line arguments.

    4. In Eclipse, choose the Run menu > Run configuration... item to create a run configuration for Nrf5xConsoleClient.java with the correct command line arguments. Uase coaps as URI scheme for secure requests.

    Run configuration for Nrf5xConsoleClient.java. Replace REMOTE_SERVER_IPv6_ADDRESS with actual IPv6 address of the server.

    If the DTLS handshake is successfu, the server will print the following lines to the console (these lines will be interleaved with other messages that pertain to the DTLS handshake):

    (...)
    
    16 INFO [MessageTracer]: /2001:0DB8:AC10:FE01:0:0:0:1:5694 ==> req CON-GET    MID=14675, Token=0e6e0e5d, OptionSet={"Uri-Path":[".well-known","core"], "Content-Format":"text/plain"}, "" - (org.eclipse.californium.core.network.interceptors.MessageTracer.java:54) receiveRequest() in thread pool-1-thread-2 at (2015-05-26 13:41:23)
    16 INFO [MessageTracer]: /2001:0DB8:AC10:FE01:0:0:0:1:5694 <== res ACK-2.05   MID=14675, Token=0e6e0e5d, OptionSet={"Content-Format":"application/link-format"}, "</lights>,</lights/l".. 22 bytes - (org.eclipse.californium.core.network.interceptors.MessageTracer.java:44) sendResponse() in thread pool-1-thread-2 at (2015-05-26 13:41:23)
    
    (...)

    The expected output of the client is a follows (these lines will be interleaved with other messages that pertain to the DTLS handshake):

    (...)
    
    ==[ CoAP Response ]============================================
    MID    : 14675
    Token  : 0e6e0e5d
    Type   : ACK
    Status : 2.05
    Options: {"Content-Format":"application/link-format"}
    Payload: 107 Bytes
    ---------------------------------------------------------------
    </lights>,</lights/led3>;title="nRF DK Resource",</lights/led4>;title="nRF DK Resource",</.well-known/core>
    ===============================================================
    Time elapsed (ms): 1100
    
    Discovered resources:
    </lights>,</lights/led3>;title="nRF DK Resource",</lights/led4>;title="nRF DK Resource",</.well-known/core>

    coap_guide.zip

Children
  • Last weekend I was also able to spend some time into that.

    The most challenging task seems to find a linux distribution with working bluetooth_6lowpan out of the box. On a Ubuntu 18.04 PC it works, for the Raspi OS it seems to disconnect after 30-40s.

    Using such "out-of-the-box" bluetooth_6lowpan kernels (newer than 4.12) requires then to compile the iot examples using BLE_6LOWPAN_LEGACY_MODE=0 in the sdk_config.h.

    After that it is easy as:

    sudo -s                   (enter su shell, execute the following commands in that shell)

    modprobe bluetooth_6lowpan

    hcitool lescan

    echo "connect 00:AA:BB:CC:DD:EE 1" > /sys/kernel/debug/bluetooth/6lowpan_control

    That's it, your device is connected and may be ping6ed. The ping6 response contains the IPv6 address of the device and the host. If you don't get a ping6 response from the device but only from the host itself, check, if the BLE_6LOWPAN_LEGACY_MODE is really set to 0.

    To use the iot dtls coap-server example, download the prebuild cf-client from Eclipse Releases - cf-client-2.4.1.jar

    With that IPv6 address from the ping6 just start the client on the same host running the bluetooth_6lowpan using:

    java -jar cf-client-2.4.1.jar --identity Client_identity --secret secretPSK 'coaps://[fe80::aa:bbff:fecc:ddee%bt0]/lights/led3' --method PUT --payload 2

    the out should be something as:

    ==[ CoAP Request ]=============================================
    MID    : 24288
    Token  : 1CDF1DDD4467DAD3
    Type   : CON
    Method : 0.03 - PUT
    Options: {"Uri-Path":["lights","led3"]}
    Payload: 1 Bytes
    ---------------------------------------------------------------
    2
    ===============================================================

    >>> DTLS([fe80:0:0:0:39:d5ff:fe9e:f2eb%bt0]:5684,ID:0E5376F5E6)
    >>> TLS_PSK_WITH_AES_256_CCM
    >>> PreSharedKey Identity [identity: Client_identity]

    Time elapsed (ms): 1352
    ==[ CoAP Response ]============================================
    MID    : 24288
    Token  : 1CDF1DDD4467DAD3
    Type   : ACK
    Status : 2.04 - CHANGED
    Options: {}
    RTT    : 1352 ms
    Payload: 0 Bytes
    ===============================================================

    and the LED 3 is switching on. That takes the 1,3 s (no 3 minutes :-) ).

    Unfortunately, it's not possible to reconnect the device's server again without disconnect the ble connection. So, if you want to play more, try out the Eclipse Releases - cf-browser-2.4.1. The browser uses javaFX, which is required to be installed ahead. Start the cf-browser similar as cf-client using:

    java --module-path /usr/share/openjfx/lib --add-modules javafx.controls,javafx.fxml -jar cf-browser-2.4.1.jar --identity Client_identity --secret secretPSK 'coaps://[fe80::39:d5ff:fe9e:f2eb%bt0]'

    (that assumes openjdk java 11 on ubuntu 18.04 using openjfx)

    The UI should be easy to use. Press DISCOVER to see the resources of the devices coap-server. Select the resource lights/led3 on the resources tree on the left. select a GET to see the state, or type a 2 and use PUT to toggle the LED.

Related