描述
I wrote following code using ESP8266 ESP-01. I have used CoAP protocol which runs over UDP. I now want to use CoAP with DTLS. Is there any support in ESP, please let me know ?
#include <SPI.h> #include <ESP8266WiFi.h> //http server library #include <WiFiUDP.h> //udp library #include <coap.h> const char* ssid = "AndroidAP"; const char* password = "abcde12345"; byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; IPAddress ip(192, 168, 43, 7); // CoAP client response callback void callback_response(CoapPacket &packet, IPAddress ip, int port);
// UDP and CoAP class WiFiUDP Udp; Coap coap(Udp);
// CoAP client response callback void callback_response(CoapPacket &packet, IPAddress ip, int port) { Serial.println("[Coap Response got]");
char p[packet.payloadlen + 1]; memcpy(p, packet.payload, packet.payloadlen); p[packet.payloadlen] = NULL;
Serial.println(p); }
void setup() { Serial.begin(115200);
if (WiFi.status() != WL_CONNECTED)
{
delay(1);
// Connect to WiFi network
Serial.println();
delay(10);
Serial.println();
delay(10);
Serial.print("Connecting to ");
delay(10);
Serial.println(ssid);
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP addres
Serial.print("ESP8266 IP: ");
Serial.println(WiFi.localIP());
//Serial.print("ESP8266 WebServer Port: ");
//Serial.println(SVRPORT);
delay(300);
}
// client response callback. // this endpoint is single callback. Serial.println("Setup Response Callback"); coap.response(callback_response);
// start coap server/client coap.start(); }
void loop() { // send GET or PUT coap request to CoAP server. // To test, use libcoap, microcoap server...etc int msgid = coap.put(IPAddress(192,168,43,7), 5683, "sensordata","temp 23 humid 35"); Serial.println("Send Request"); // int msgid1 = coap.get(IPAddress(192, 168, 43, 7), 5683, "time");
delay(1000); coap.loop(); }