Ich habe gerade CoAP Client mit Arduino erstellt und bin in der Lage, Payload ("Hallo") an den Coap Browser zu senden (installiert von Mozilla Browser). Ich kann es im Browser sehen, es empfängt.Nodejs CoAP Server empfängt keine Payload
Jetzt muss ich meinen eigenen | Nodejs-Server erstellen, um meine Payload (sagen wir "Hallo") vom Arduino-Client zu erhalten. Wie kann ich es erreichen?
Server
var coap = require('coap');
var server = coap.createServer();
// At this point, I checked from mozilla coap browser, sent "hello" and I am able to receive the HEX values. Same way, I tried to send it from Arduino, but did not print anything
server.on('request', function(req, res) {
console.log(req.payload);
})
// the default CoAP port is 5683
server.listen(function() {
var req = coap.request('coap://localhost');
console.log('Listening on : 5683')
req.on('response', function(res) {
res.pipe(process.stdout);
});
req.end()
});
Arduino
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,0,11), 5683, "light","1");
Serial.println("Send Request");
//int msgid1 = coap.get(IPAddress(192, 168, 0, 11), 5683, "time");
delay(1000);
coap.loop();
}