I want to use the Electron with the COAP protocol to visualize some data on thethings.io. Has anyone used already COAP together with thethings.io? Which library should I use? Any examples available to get started? I tried the following program, but it doesn’t work.
#include "coap.h"
// CoAP client response callback
void callback_response(CoapPacket &packet, IPAddress ip, int port);
Coap coap;
// 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(9600);
// 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() {
Serial.println("Send Request");
int msgid = coap.put(IPAddress(104, 199, 85, 211), 5683, "/v2/things/{mytoken}, "{\"values\":[{\"key\":\"C1\",\"value\":\"1\"}]}");
delay(1000);
coap.loop();
}
All info is welcome.