Skip to content

Commit

Permalink
Merge pull request #30 from StandaSK/master
Browse files Browse the repository at this point in the history
Add an option to specify Message ID
  • Loading branch information
hirotakaster committed Feb 25, 2022
2 parents 12d9531 + a4e54bb commit ef97248
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion coap-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ uint16_t Coap::send(IPAddress ip, int port, const char *url, COAP_TYPE type, COA
}

uint16_t Coap::send(IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenlen, const uint8_t *payload, size_t payloadlen, COAP_CONTENT_TYPE content_type) {
return this->send(ip, port, url, type, method, token, tokenlen, payload, payloadlen, content_type, rand());
}

uint16_t Coap::send(IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenlen, const uint8_t *payload, size_t payloadlen, COAP_CONTENT_TYPE content_type, uint16_t messageid) {

// make packet
CoapPacket packet;
Expand All @@ -135,7 +139,7 @@ uint16_t Coap::send(IPAddress ip, int port, const char *url, COAP_TYPE type, COA
packet.payload = payload;
packet.payloadlen = payloadlen;
packet.optionnum = 0;
packet.messageid = rand();
packet.messageid = messageid;

// use URI_HOST UIR_PATH
char ipaddress[16] = "";
Expand Down
1 change: 1 addition & 0 deletions coap-simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class Coap {
uint16_t put(IPAddress ip, int port, const char *url, const char *payload, size_t payloadlen);
uint16_t send(IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenlen, const uint8_t *payload, size_t payloadlen);
uint16_t send(IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenlen, const uint8_t *payload, size_t payloadlen, COAP_CONTENT_TYPE content_type);
uint16_t send(IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenlen, const uint8_t *payload, size_t payloadlen, COAP_CONTENT_TYPE content_type, uint16_t messageid);

bool loop();
};
Expand Down

0 comments on commit ef97248

Please sign in to comment.