Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[leshan-dev] ??????Integration into Android(Leshan-client)

Hello everybody!

I was in the process of integration to Android, made some changes.
1.I put the Californium.properties file in the assets directory.
When I was creating client, I read the configuration file from the assets directory and set it to NetworkConfig.

NetworkConfig.createStandardWithoutFile();
InputStream input = ObjectLoader.class.getResourceAsStream("/assets/Californium.properties");
if (input != null) {
NetworkConfig config = NetworkConfig.createStandardWithFile(inputstreamtofile(input,new File("Californium.properties")));
NetworkConfig.setStandard(config);
}
createAndStartClient(endpoint, localAddress, localPort, secureLocalAddress, secureLocalPort, false,
serverURI, pskIdentity, pskKey);

2.I also put the object file in the assets directory,and then load the JSON file from the assets directory to initialize LwM2mModel.
this.model = new LwM2mModel(ObjectLoader.loadDefault());
InputStream input = ObjectLoader.class.getResourceAsStream("/assets/oma-objects-spec.json");
if (input != null) {
try (Reader reader = new InputStreamReader(input)) {
models.addAll(loadJsonStream(input));
} catch (IOException e) {
LogUtils.d("Unable to load object models");
}
}

Finally, client successfully connected to the server.It finally worked.

But I think there's a problem with this step??
NetworkConfig config = NetworkConfig.createStandardWithFile(inputstreamtofile(input,new File("Californium.properties")));
NetworkConfig.setStandard(config);


Best regards 
zmsoft

------------------ ???????? ------------------
??????: "????";<1084615055@xxxxxx>;
????????: 2017??5??5??(??????) ????4:04
??????: "leshan-dev"<leshan-dev@xxxxxxxxxxx>;
????: Integration into Android(Leshan-client)

Hello everybody!


Storing standard properties in file Californium.properties

Is this step necessary?
When I was running at Android studio, I found that this file could not be created.


Here is the log from logcat

05-05 15:11:31.280 D/mwqi: Loading OMA standard object models
05-05 15:11:31.397 D/mwqi: min.zhu objectId=0
05-05 15:11:31.398 D/mwqi: min.zhu objectId=1
05-05 15:11:31.398 D/mwqi: min.zhu objectId=3
05-05 15:11:31.398 D/mwqi: min.zhu objectId=5
05-05 15:11:31.398 D/mwqi: min.zhu objectId=6
05-05 15:11:31.400 D/mwqi: min.zhu leshanClientBuilder localAddress=/0.0.0.0:0
05-05 15:11:31.401 D/mwqi: min.zhu leshanClientBuilder localSecureAddress=/0.0.0.0:0
05-05 15:11:31.401 D/mwqi: min.zhu leshanClient endpoint=min.zhuand localAddress=/0.0.0.0:0and localSecureAddress=/0.0.0.0:0
05-05 15:11:31.401 D/mwqi: min.zhu leshanClient Create CoAP non secure endpoint localAddress=/0.0.0.0:0
05-05 15:11:31.404 I/NetworkConfig: Storing standard properties in file Californium.properties
05-05 15:11:31.407 W/NetworkConfig: Error while storing properties to /Californium.properties
java.io.FileNotFoundException: Californium.properties: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileOutputStream.(FileOutputStream.java:87)
at java.io.FileOutputStream.(FileOutputStream.java:72)
at java.io.FileWriter.(FileWriter.java:42)
at org.eclipse.californium.core.network.config.NetworkConfig.store(NetworkConfig.java:218)
at org.eclipse.californium.core.network.config.NetworkConfig.store(NetworkConfig.java:205)
at org.eclipse.californium.core.network.config.NetworkConfig.createStandardWithFile(NetworkConfig.java:170)
at org.eclipse.californium.core.network.config.NetworkConfig.getStandard(NetworkConfig.java:125)
at org.eclipse.californium.core.network.CoapEndpoint.(CoapEndpoint.java:166)
at org.eclipse.leshan.client.californium.LeshanClient.(LeshanClient.java:87)
at org.eclipse.leshan.client.californium.LeshanClientBuilder.build(LeshanClientBuilder.java:120)

        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.FileOutputStream.(FileOutputStream.java:87)
at java.io.FileOutputStream.(FileOutputStream.java:72)
at java.io.FileWriter.(FileWriter.java:42)
at org.eclipse.californium.core.network.config.NetworkConfig.store(NetworkConfig.java:218)
at org.eclipse.californium.core.network.config.NetworkConfig.store(NetworkConfig.java:205)
at org.eclipse.californium.core.network.config.NetworkConfig.createStandardWithFile(NetworkConfig.java:170)
at org.eclipse.californium.core.network.config.NetworkConfig.getStandard(NetworkConfig.java:125)
at org.eclipse.californium.core.network.CoapEndpoint.(CoapEndpoint.java:166)
at org.eclipse.leshan.client.californium.LeshanClient.(LeshanClient.java:87)
at org.eclipse.leshan.client.californium.LeshanClientBuilder.build(LeshanClientBuilder.java:120)

        at android.view.View.performClick(View.java:4780) 
        at android.view.View$PerformClick.run(View.java:19866) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5254) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

05-05 15:11:31.447 D/mwqi: Starting Leshan client ...
05-05 15:11:31.448 I/CoapServer: Starting server
05-05 15:11:31.448 I/CoapEndpoint: Starting endpoint at /0.0.0.0:0
05-05 15:11:31.459 I/DTLSConnector: DTLS connector listening on [{0}] with MTU [{1}] using (inbound) datagram buffer size [{2} bytes]
05-05 15:11:31.464 I/CoapEndpoint: Starting endpoint at /0.0.0.0:0
05-05 15:11:31.475 D/mwqi: Leshan client started.

Although the client has started.But did not successfully connect to the server.
Connected clients: 0
Is it because this property file does not create the cause of success?



Back to the top