client version of coap

Dependencies:   nRF24L01P cantcoap3

Dependents:   client3

Revision:
5:d633e12f113f
Parent:
4:792cf53a73c4
--- a/coapClient.cpp	Fri Jan 25 02:00:42 2019 +0000
+++ b/coapClient.cpp	Fri Jan 25 12:10:49 2019 +0000
@@ -21,6 +21,7 @@
 bool CoapClient::isAck(CoapPDU& response, uint16_t message_id, char* uri) {
     if (response.validate()) {
         response.printHuman();
+        DBG("WANNA: %d %s", message_id, uri);
         if (isExpectedResponse(response, message_id, uri)) {
             return true;
         }
@@ -51,6 +52,7 @@
     Timer t;
     CoapPDU coapPDU = CoapPDU();
     uint16_t messageId = preparePDU(coapPDU);
+    this->message_counter +=4;
     coapPDU.setCode(CoapPDU::COAP_GET);
     coapPDU.setURI(uri);
 
@@ -108,6 +110,7 @@
     Timer t;
     CoapPDU coapPDU = CoapPDU();
     uint16_t messageId = preparePDU(coapPDU);
+    this->message_counter +=4;
     coapPDU.setCode(CoapPDU::COAP_POST);
 
     coapPDU.setURI(uri);
@@ -150,13 +153,12 @@
     coapPDU.setType(CoapPDU::COAP_CONFIRMABLE);
     coapPDU.setMessageID(this->message_counter);
     coapPDU.setToken(this->token, 1);
-    return this->message_counter++;
+    return this->message_counter;
 }
 
-CoapClient::CoapClient(uint8_t* token, int retransmissionLimit, int timeout, int channel, unsigned long long rx_address,
-                       unsigned long long tx_address) :
+CoapClient::CoapClient(uint16_t counter, uint8_t* token, int retransmissionLimit, int timeout, int channel, unsigned long long rx_address,
+                       unsigned long long tx_address):
         listeningTimeout(timeout), retransmissionLimit(retransmissionLimit),
-        radioWrapper(channel, rx_address, tx_address) {
+        radioWrapper(channel, rx_address, tx_address), message_counter(counter)  {
     std::memcpy(this->token, token, 1);
-    this->message_counter = 666; // set to random
 }
\ No newline at end of file