Skip to content

Blockwise transfer #62

@deavmi

Description

@deavmi

Good morning, I have been working on getting a blockwise transfer working as part of a POST request.

I effectively have a large amount of data I want to send, I want the Java CoAP library to handle the block transfer, and once done have it unblock from the future to be able to obtain the fully reassembled payload.

I have been struggling to get this right, so far this is the code I have going:

/**
* Grab a hold of the resource as a target for our POST.
* 
* Then pack into the request our DLMS xAPDU with the
* DLMS content type.
* 
* Then also set the headers:
*/
String uriHostStr = (this.remoteHost.getAddress()+":"+this.remoteHost.getPort()).replace("/", "");
log.warning("Computed URI host string: '"+uriHostStr+"'");

CoapRequestTarget resourceTarget = this.client.resource(this.resourcePath)
  .payload(payloadToSend, this.contentType)
  .con()
  .host(uriHostStr)
  .token(getAToken());
//  .query("");

// Pack the headers in
resourceTarget = packHeaderOptions(resourceTarget);



log.finer("POST to be sent: '"+resourceTarget+"'");

// Now POST it and wait for it to complete
CompletableFuture<CoapPacket> postFuture = resourceTarget.post(); 

// Wait for the response Coap packet
CoapPacket postResp = postFuture.get();
log.finer("Post response: '"+postResp+"'");

byte[] responsePayload = postResp.getPayload();
log.info("Post payload: '"+Arrays.toString(responsePayload)+"'");

How could I go about this? (Below is attached one of the ways I need to accomplish this)

IMG-20230921-WA0000.jpg

IMG-20230921-WA0001.jpg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions