2

How to create a CoAP block-wise transfer on NodeJS? I use node-coap module. I send a request to:

var options = {
      host: 'coap.me',
      port: 5683,
      pathname: '/test',
      method: 'PUT',
    };

I also do this: req.setOption('Block2', new Buffer([1])); This method should create a CoAP option and mean that size of payload is 32 bytes. After that I don't know what to do. I try for cycle (body = 32 bytes):

for(var i = 0; i < 100; i++){
        if(i === 99){
            req.end(body);
        } else {
            req.write(body);
        }
    }

Everything I have is an error: Max packet size is 1280: current is 265951

Or if I should use different requests, how to map one after another? Because every request produce a response and my program ends after first request.

Tryam
  • 375
  • 2
  • 13

1 Answers1

1

I guess you want to send a big payload from client to server? This is Block1 not Block2.

RFC7959:

Both Block1 and Block2 Options can be present in both the request and response messages. In either case, the Block1 Option pertains to the request payload, and the Block2 Option pertains to the response payload.

Unfortunately, looks like there is no such out-of-box feature in node-coap.

https://github.com/mcollina/node-coap/issues/42

Community
  • 1
  • 1
eugene-nikolaev
  • 1,290
  • 1
  • 13
  • 21
  • Thanks for answer. Yeah, I noticed lack of this feature and wrote function for implementing Block1 – Tryam Feb 05 '18 at 11:35