Closed jiangyoudi closed 5 years ago
So, If I am not wrong then,
try { ReadResponse response = lwServer.send(registration, new ObserveRequest(obj, inst, res)); if (response == null){ System.out.println("!!!!!response is null TIMEOUT!!!!"); return; } else if (response.isSuccess()){ if(((LwM2mResource) response.getContent()).isMultiInstances()) { System.out.println("Observe values:" + ((LwM2mResource) response.getContent()).getValues()); } else { System.out.println("Observe value:" + ((LwM2mResource) response.getContent()).getValue()); } } else { System.out.println("Failed to read:" + response.getCode() + " " + response.getErrorMessage()); } } catch (InterruptedException ex) { System.out.println(); }
Looks something like this->
If you get (response == null) try add in code coapConfig.set(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, 4); There was an issue, if your test machine running on one thread, like i got. Sorry for poorly structured answer, but its still better than wait a week :)
So, If I am not wrong then,
try { ReadResponse response = lwServer.send(registration, new ObserveRequest(obj, inst, res)); if (response == null){ System.out.println("!!!!!response is null TIMEOUT!!!!"); return; } else if (response.isSuccess()){ if(((LwM2mResource) response.getContent()).isMultiInstances()) { System.out.println("Observe values:" + ((LwM2mResource) response.getContent()).getValues()); } else { System.out.println("Observe value:" + ((LwM2mResource) response.getContent()).getValue()); } } else { System.out.println("Failed to read:" + response.getCode() + " " + response.getErrorMessage()); } } catch (InterruptedException ex) { System.out.println(); }
Looks something like this->If you get (response == null) try add in code coapConfig.set(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, 4); There was an issue, if your test machine running on one thread, like i got. Sorry for poorly structured answer, but its still better than wait a week :)
Thank you very much,i will have a try. But i have a question,is there a method that not send "lwServer.send()" to client?because previousObsersations has represent the observer information,why we just store it again?
Its just my test code, not developed enough, a lot to learn, I must. I am new here. If you got Previous observation active, they will be canceled, if you just send new Observation request, tested that! If you want a smooth code, you should check previousObsersations I think there may be an answer or maybe wait some Leshan Guru to answer that :)
Its just my test code, not developed enough, a lot to learn, I must. I am new here. If you got Previous observation active, they will be canceled, if you just send new Observation request, tested that! If you want a smooth code, you should check previousObsersations I think there may be an answer or maybe wait some Leshan Guru to answer that :)
Yes,thanks you.If possible,make a smooth code in leshan server demo in next version.Have a good day!
HI, I have a server observe client resource,it works well.But when i restart client,I find the server delete the observer relationship with the client.I want that the server not cancel observer ,although the client restart,it works well. How should i do to handle this question?
OMA-TS-LightweightM2M_Core-V1_1-20180710-A notes: Until the LwM2M Client sends a new registration, the LwM2M Server expects the LwM2M Client to remember the observation requests. If a LwM2M Client forgets the observation requests (e.g. device factory reset) it MUST perform a new "Register" operation. The LwM2M Server MUST re-initiate observation requests whenever the LwM2M Client registers.
and I use leshan 1.00-M11,the server demo :
public void registered(Registration registration, Registration previousReg, Collection previousObsersations) {
String jReg = EventServlet.this.gson.toJson(registration);
sendEvent(EVENT_REGISTRATION, jReg, registration.getEndpoint());
}
I kown the previous Obsersations param represent the previous relaship with client ,but how to use the param to re-initiate observation requests?