shamblett / coap

A Coap package for dart
Other
16 stars 13 forks source link

Problem with markobserve() in coap version 2.0.1 #16

Closed anayajoshi closed 3 years ago

anayajoshi commented 3 years ago

Hello @shamblett , I am using coap version 2.0.1 and checking markObserve() functionality for get request. But it gives following error. Please guide me.

2021-01-02 16:41:24.554 4771-4885/com.gladiance.gladiance_one I/flutter: 2021-01-02 16:41:24.553: INFO: >> Matcher - received response <<< Response Message >>> Type: 1, Code: 2.05 Content, Id: 26844, Token: 00004b74, Options = [ If-Match : Uri Host : None E-tags : ETag: 6b750232 None Uri Port : None Location Paths: Uri Paths : Content-Type : 50 Max Age : 0 Uri Queries : Accept : -1 Location Queries : Proxy Uri : None Proxy Scheme : None Block 1 : None Block 2 : None Observe : 4 Size 1 : 0 Size 2 : 0 ], Payload : {"resp":"error in query"} 2021-01-02 16:41:24.554 4771-4885/com.gladiance.gladiance_one I/flutter: 2021-01-02 16:41:24.554: SEVERE: >> Rejecting unmatchable response from Instance of 'CoapInternetAddress'

shamblett commented 3 years ago

If you look at issue 12 I wrote a test for this reproduced below -

import 'dart:async';
import 'package:coap/coap.dart';
import 'config/coap_config.dart';

FutureOr main() async {
// Create a configuration class. Logging levels can be specified in the
// configuration file.
  final conf = CoapConfig();

// Build the request uri, note that the request paths/query parameters can be changed
// on the request anytime after this initial setup.
  const host = 'wsncoap.org';

  final uri = Uri(scheme: 'coap', host: host, port: conf.defaultPort);

// Create the client.
// The method we are using creates its own request so we do not
// need to supply one.
// The current request is always available from the client.
  final client = CoapClient(uri, conf);

// Adjust the response timeout if needed, defaults to 32767 milliseconds
//client.timeout = 10000;

// Create the request for the get request
  final request = CoapRequest.newGet();
  request.addUriPath('obs');
// Mark the request as observable
  request.markObserve();

  // Getting responses form the observable resource
  request.responses.listen((CoapResponse response) {
    print('EXAMPLE - payload: ${response.payloadString}');
  });

  client.request = request;

  print('EXAMPLE - Sending get observable request to '
      '$host, waiting for responses ....');
  await client.get();
}

This still works for me in version 2.0.1. Please run this test to verify operation then re try what you are doing but post a full log, I need to see all the messages exchanged, not just a fragment.

anayajoshi commented 3 years ago

Okay, please check the full log outout:

I/flutter ( 9719): Initialising client I/flutter ( 9719): Coap client instantiated: Instance of 'MyCoapClient' I/flutter ( 9719): delay = 100, unicastaddress = 4, _entityType = 1, _controlMode = 1 I/flutter ( 9719): 2021-01-05 13:45:46.057: SEVERE: >> BlockwiseLayer uses MaxMessageSize: 1024 and DefaultBlockSize: 512 I/flutter ( 9719): 2021-01-05 13:45:46.093: INFO: >> CoapNetworkUDP - binding to 0.0.0.0 I/flutter ( 9719): 2021-01-05 13:45:46.105: INFO: >> Starting endpoint bound to InternetAddress('192.168.1.3', IPv4) I/flutter ( 9719): 2021-01-05 13:45:46.173: INFO: >> Reliability - Scheduling transmission for I/flutter ( 9719): <<< Request Message >>> I/flutter ( 9719): Type: 0, Code: GET, Id: 32235, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : Uri-Host: 192.168.1.3 I/flutter ( 9719): E-tags : I/flutter ( 9719): None I/flutter ( 9719): Uri Port : 5683 I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : inline I/flutter ( 9719): Content-Type : None I/flutter ( 9719): Max Age : None I/flutter ( 9719): Uri Queries : Uri-Query: 107/0/105/116/status/4/2/1 I/flutter ( 9719): Accept : None I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): null I/flutter ( 9719): 2021-01-05 13:45:46.180: INFO: >> Reliability - sending request, failed transmission count: 0 I/flutter ( 9719): 2021-01-05 13:45:46.182: INFO: >> Reliability - Retransmission timeout is 622 ms I/flutter ( 9719): 2021-01-05 13:45:46.194: INFO: >> Matcher - Stored open request by KeyID[32235]) + KeyToken[00001126] I/flutter ( 9719): 2021-01-05 13:45:46.222: INFO: >> CoapNetworkUDP - binding to 0.0.0.0 I/flutter ( 9719): payload = null I/flutter ( 9719): Initialising client I/flutter ( 9719): Coap client old uri: coap://192.168.1.3:5683, host: 192.168.1.3 I/flutter ( 9719): 2021-01-05 13:45:46.315: INFO: >> Reliability - Scheduling transmission for I/flutter ( 9719): <<< Request Message >>> I/flutter ( 9719): Type: 0, Code: GET, Id: 16297, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : Uri-Host: 192.168.1.3 I/flutter ( 9719): E-tags : I/flutter ( 9719): None I/flutter ( 9719): Uri Port : 5683 I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : inline I/flutter ( 9719): Content-Type : None I/flutter ( 9719): Max Age : None I/flutter ( 9719): Uri Queries : Uri-Query: 107/0/105/116/status/4/2/1 I/flutter ( 9719): Accept : None I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): null I/flutter ( 9719): 2021-01-05 13:45:46.315: INFO: >> Reliability - sending request, failed transmission count: 0 I/flutter ( 9719): 2021-01-05 13:45:46.315: INFO: >> Reliability - Retransmission timeout is 619 ms I/flutter ( 9719): 2021-01-05 13:45:46.316: INFO: >> Matcher - Stored open request by KeyID[16297]) + KeyToken[00001126] I/flutter ( 9719): 2021-01-05 13:45:46.319: INFO: >> CoapNetworkUDP - binding to 0.0.0.0 I/flutter ( 9719): 2021-01-05 13:45:46.833: WARNING: >> Reliability - Retransmission timeout elapsed I/flutter ( 9719): 2021-01-05 13:45:46.835: WARNING: >> Reliability - Timeout: retransmit message, failed count: 1 message: 32235 I/flutter ( 9719): 2021-01-05 13:45:46.837: INFO: >> Reliability - Scheduling transmission for I/flutter ( 9719): <<< Request Message >>> I/flutter ( 9719): Type: 0, Code: GET, Id: 32235, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : Uri-Host: 192.168.1.3 I/flutter ( 9719): E-tags : I/flutter ( 9719): None I/flutter ( 9719): Uri Port : 5683 I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : inline I/flutter ( 9719): Content-Type : None I/flutter ( 9719): Max Age : None I/flutter ( 9719): Uri Queries : Uri-Query: 107/0/105/116/status/4/2/1 I/flutter ( 9719): Accept : None I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): null I/flutter ( 9719): 2021-01-05 13:45:46.838: INFO: >> Reliability - sending request, failed transmission count: 0 I/flutter ( 9719): 2021-01-05 13:45:46.838: INFO: >> Reliability - Retransmission timeout is 550 ms I/flutter ( 9719): 2021-01-05 13:45:46.839: INFO: >> Matcher - Stored open request by KeyID[32235]) + KeyToken[00001126] I/flutter ( 9719): 2021-01-05 13:45:46.936: WARNING: >> Reliability - Retransmission timeout elapsed I/flutter ( 9719): 2021-01-05 13:45:46.937: WARNING: >> Reliability - Timeout: retransmit message, failed count: 1 message: 16297 I/flutter ( 9719): 2021-01-05 13:45:46.938: INFO: >> Reliability - Scheduling transmission for I/flutter ( 9719): <<< Request Message >>> I/flutter ( 9719): Type: 0, Code: GET, Id: 16297, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : Uri-Host: 192.168.1.3 I/flutter ( 9719): E-tags : I/flutter ( 9719): None I/flutter ( 9719): Uri Port : 5683 I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : inline I/flutter ( 9719): Content-Type : None I/flutter ( 9719): Max Age : None I/flutter ( 9719): Uri Queries : Uri-Query: 107/0/105/116/status/4/2/1 I/flutter ( 9719): Accept : None I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): null I/flutter ( 9719): 2021-01-05 13:45:46.938: INFO: >> Reliability - sending request, failed transmission count: 0 I/flutter ( 9719): 2021-01-05 13:45:46.939: INFO: >> Reliability - Retransmission timeout is 709 ms I/flutter ( 9719): 2021-01-05 13:45:46.940: INFO: >> Matcher - Stored open request by KeyID[16297]) + KeyToken[00001126] I/flutter ( 9719): 2021-01-05 13:45:47.021: INFO: >> Matcher - received response I/flutter ( 9719): <<< Response Message >>> I/flutter ( 9719): Type: 2, Code: 2.05 Content, Id: 32235, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : None I/flutter ( 9719): E-tags : ETag: 6b750232 I/flutter ( 9719): None I/flutter ( 9719): Uri Port : None I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : I/flutter ( 9719): Content-Type : 50 I/flutter ( 9719): Max Age : 0 I/flutter ( 9719): Uri Queries : I/flutter ( 9719): Accept : -1 I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): {"resp":"error in query"} I/flutter ( 9719): 2021-01-05 13:45:47.023: INFO: >> Matcher - cleaning up KeyID[16297]) I/flutter ( 9719): 2021-01-05 13:45:47.024: WARNING: >> Matcher - Possible MID reuse before lifetime end: 00001126 expected MID 16297 but received 32235 I/flutter ( 9719): 2021-01-05 13:45:47.031: INFO: >> Reliability - Cancel retransmission for token: 00001126 id: 16297 I/flutter ( 9719): status received - payload: {"resp":"error in query"} E/flutter ( 9719): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Unexpected character (at character 26) E/flutter ( 9719): {"resp":"error in query"} I/flutter ( 9719): load status received: null I/flutter ( 9719): 2021-01-05 13:45:47.066: INFO: >> Matcher - received response I/flutter ( 9719): <<< Response Message >>> I/flutter ( 9719): Type: 2, Code: 2.05 Content, Id: 16297, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : None I/flutter ( 9719): E-tags : ETag: 6b750232 I/flutter ( 9719): None I/flutter ( 9719): Uri Port : None I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : I/flutter ( 9719): Content-Type : 50 I/flutter ( 9719): Max Age : 0 I/flutter ( 9719): Uri Queries : I/flutter ( 9719): Accept : -1 I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): {"resp":"error in query"} I/flutter ( 9719): 2021-01-05 13:45:47.066: INFO: >> Matcher - cleaning up KeyID[16297]) I/flutter ( 9719): status received - payload: {"resp":"error in query"} E/flutter ( 9719): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Unexpected character (at character 26) E/flutter ( 9719): {"resp":"error in query"} I/flutter ( 9719): 2021-01-05 13:45:47.390: WARNING: >> Reliability - Retransmission timeout elapsed I/flutter ( 9719): 2021-01-05 13:45:47.391: WARNING: >> Reliability - Timeout: retransmit message, failed count: 1 message: 32235 I/flutter ( 9719): 2021-01-05 13:45:47.392: INFO: >> Reliability - Scheduling transmission for I/flutter ( 9719): <<< Request Message >>> I/flutter ( 9719): Type: 0, Code: GET, Id: 32235, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : Uri-Host: 192.168.1.3 I/flutter ( 9719): E-tags : I/flutter ( 9719): None I/flutter ( 9719): Uri Port : 5683 I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : inline I/flutter ( 9719): Content-Type : None I/flutter ( 9719): Max Age : None I/flutter ( 9719): Uri Queries : Uri-Query: 107/0/105/116/status/4/2/1 I/flutter ( 9719): Accept : None I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): null I/flutter ( 9719): 2021-01-05 13:45:47.392: INFO: >> Reliability - sending request, failed transmission count: 0 I/flutter ( 9719): 2021-01-05 13:45:47.393: INFO: >> Reliability - Retransmission timeout is 732 ms I/flutter ( 9719): 2021-01-05 13:45:47.393: INFO: >> Matcher - Stored open request by KeyID[32235]) + KeyToken[00001126] I/flutter ( 9719): 2021-01-05 13:45:47.499: INFO: >> Matcher - received response I/flutter ( 9719): <<< Response Message >>> I/flutter ( 9719): Type: 2, Code: 2.05 Content, Id: 32235, Token: 00001126, I/flutter ( 9719): Options = I/flutter ( 9719): [ I/flutter ( 9719): If-Match : I/flutter ( 9719): Uri Host : None I/flutter ( 9719): E-tags : ETag: 6b750232 I/flutter ( 9719): None I/flutter ( 9719): Uri Port : None I/flutter ( 9719): Location Paths: I/flutter ( 9719): Uri Paths : I/flutter ( 9719): Content-Type : 50 I/flutter ( 9719): Max Age : 0 I/flutter ( 9719): Uri Queries : I/flutter ( 9719): Accept : -1 I/flutter ( 9719): Location Queries : I/flutter ( 9719): Proxy Uri : None I/flutter ( 9719): Proxy Scheme : None I/flutter ( 9719): Block 1 : None I/flutter ( 9719): Block 2 : None I/flutter ( 9719): Observe : 0 I/flutter ( 9719): Size 1 : 0 I/flutter ( 9719): Size 2 : 0 I/flutter ( 9719): ], I/flutter ( 9719): Payload : I/flutter ( 9719): {"resp":"error in query"} I/flutter ( 9719): 2021-01-05 13:45:47.500: INFO: >> Matcher - Duplicate response for open exchange I/flutter ( 9719): 2021-01-05 13:45:47.502: INFO: >> Reliability - Cancel retransmission for token: 00001126 id: 32235 I/flutter ( 9719): 2021-01-05 13:45:47.502: INFO: >> Reliability - Response is duplicate, ignoring. I/flutter ( 9719): load status received: null I/flutter ( 9719): 2021-01-05 13:45:56.093: INFO: >> Start Mark-And-Sweep with 2 entries I/flutter ( 9719): 2021-01-05 13:45:56.099: INFO: >> Mark-And-Sweep removes KeyID[32235]) I/flutter ( 9719): 2021-01-05 13:45:56.099: INFO: >> Mark-And-Sweep removes KeyID[16297]) I/flutter ( 9719): 2021-01-05 13:46:06.089: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:46:16.089: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:46:26.089: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:46:36.089: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:46:46.089: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:46:56.090: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:47:06.090: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:47:16.090: INFO: >> Start Mark-And-Sweep with 0 entries I/flutter ( 9719): 2021-01-05 13:47:26.090: INFO: >> Start Mark-And-Sweep with 0 entries

anayajoshi commented 3 years ago

Please also check, markobserve should listen to response only after change in the state, currently it continuously retransmits the get request after setting markObserve().

shamblett commented 3 years ago

OK, firstly you are not using the server from the example above, you are using 192.168.1.3, please check first with the server I have given to you (and with coap.me also if you wish) to check that your end is doing the same as mine.

Secondly, from your first response message -

I/flutter ( 9719): Observe : 0
I/flutter ( 9719): Size 1 : 0
I/flutter ( 9719): Size 2 : 0
I/flutter ( 9719): ],
I/flutter ( 9719): Payload :
I/flutter ( 9719): {"resp":"error in query"}
I/flutter ( 9719): 2021-01-05 13:45:47.023: INFO: >> Matcher - cleaning up KeyID[16297])
I/flutter ( 9719): 2021-01-05 13:45:47.024: WARNING: >> Matcher - Possible MID reuse before lifetime end: 00001126 expected MID 16297 but received 32235
I/flutter ( 9719): 2021-01-05 13:45:47.031: INFO: >> Reliability - Cancel retransmission for token: 00001126 id: 16297
I/flutter ( 9719): status received - payload: {"resp":"error in query"}
E/flutter ( 9719): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Unexpected character (at character 26)
E/flutter ( 9719): {"resp":"error in query"}
I/flutter ( 9719): load status received: null

Please read #12 the line 'Observe : 0' looks odd, it should be something like 'Observe : 26962' or whatever number your server thinks appropriate. From this point on there are numerous errors as you can see that could stop the observer working, these need to sorted out first. your server seems not to work as it should.

anayajoshi commented 3 years ago

I will check this issue after solving issue17