IOT_GRZYBKI / Mbed 2 deprecated WIFI_BOARD

Dependencies:   mbed cantcoap WIFI_BOARD

Dependents:   WIFI_BOARD

Revision:
1:1b58077320a3
Parent:
0:73e49785c686
Child:
2:d2fd4c719ea0
--- a/main.cpp	Fri Jan 18 15:58:10 2019 +0000
+++ b/main.cpp	Sat Jan 19 21:03:47 2019 +0000
@@ -13,17 +13,31 @@
     CoapPDU *recvPDU = new CoapPDU(buff,ret,1023);
     if(recvPDU->validate()) {
         //recvPDU.printHuman();
-        // do your work
         return recvPDU;
     }
     return NULL;
 }
 
+void send_cb(int arg) {
+    (void)arg;
+    send.write(1);
+    wait(0.05);
+    send.write(0);
+    PCDBG("PoszLo!");
+}
+
 int sendd(uint8_t* buff, int len) {
-    //TODO callback for response
-    int ret = wifi.write(buff, len, NULL);
+    while(!wifi.writable()) {
+        PCDBG("Wifi not wirtable");
+        wait(0.5);
+    }
+    //not working - dunno how this works
+    //int ret = wifi.write(buff, len, event_callback_t(&send_cb));
+    PCDBG((char*)buff);
+    //seems the same as wifi.write(buff, len, NULL);
+    int ret = wifi.printf((char*)buff);
     send.write(1);
-    wait(0.2);
+    wait(0.05);
     send.write(0);
     return ret;
 }
@@ -31,6 +45,7 @@
 int main() {
     pc.baud(115200);
     wifi.baud(115200);
+    PCDBG("Started")
     CoapPDU* pdu = new CoapPDU();
     uint16_t messageID = 0;
     int ret;
@@ -38,26 +53,27 @@
         ++messageID;
         pdu->setType(CoapPDU::COAP_CONFIRMABLE);
         pdu->setCode(CoapPDU::COAP_GET);
-        pdu->setToken((uint8_t*)"\3\2\1\0",4);
+        pdu->setToken((uint8_t*)"1234",4);
         pdu->setMessageID(messageID);
         pdu->setURI((char*)"test",4);
+        pdu->setPayload((uint8_t*)"Tralalala", 9);
     
         PCDBG("Sending packet");
         // send packet 
         ret = sendd(pdu->getPDUPointer(), pdu->getPDULength());
         PCDBG("Packet send");
         
-        // get response
-        CoapPDU* res = read();
-        PCDBG("Response read");
-        CoapPDU::Code code = res->getCode();
-        uint8_t len = res->getPayloadLength();
-        // getPayloadPointerCopy to get allocated copy of payload
-        uint8_t* payload = res->getPayloadPointer();
-        //char status[10];
-        //if(code == COAP_VALID) status = "OK"; else status = "UNKNOWN";
-        PCDBG("%s, %s", code, payload);
-        delete res;
+        //// get response
+//        CoapPDU* res = read();
+//        PCDBG("Response read");
+//        CoapPDU::Code code = res->getCode();
+//        uint8_t len = res->getPayloadLength();
+//        // getPayloadPointerCopy to get allocated copy of payload
+//        uint8_t* payload = res->getPayloadPointer();
+//        //char status[10];
+//        //if(code == COAP_VALID) status = "OK"; else status = "UNKNOWN";
+//        PCDBG("%s, %s", code, payload);
+//        delete res;
         wait(1);
     }
 }
\ No newline at end of file