1
Arduino Uno가 있고 UDP 연결을 사용하는 프로젝트에서 Node.js 모듈을 실행하는 Mac으로 데이터를 보내고 데이터를 인쇄합니다. 아웃. Arduino with Node.js not
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
//Import the necessary packages.
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //Arduino's MAC address.
IPAddress IP(192, 168, 1, 152); //Arduino's IP address.
unsigned int arduinoPort = 8888; //Arduino's transmission port.
IPAddress recieverIP(192, 168, 1, 77); //Mac's IP address.
unsigned int recieverPort = 6000; //Mac's transmission port.
EthernetUDP udp;
int sensorPin = 2; //The pin on the Arduino the PIR sensor is connected to.
int sensorStatus; //The PIR sensor's status.
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, IP); //Starting the Ethernet functionality.
udp.begin(arduinoPort); //Starting the UDP server's functionality.
}
void loop()
{
Serial.println("YES");
udp.beginPacket(recieverIP, recieverPort);
udp.write("YES");
udp.endPacket();
delay(10);
}
가 여기 내 Node.js를 모듈에 대한 코드입니다 :
var dgram = require('dgram');
var server = dgram.createSocket("udp4");
var fs = require('fs');
var crlf = new Buffer(2);
crlf[0] = 0xD;
crlf[1] = 0xA;
server.on("Message", function(msg, rinfo)
{
console.log("Server got : " + msg.readUInt16LE(0) + " from : " + rinfo.address + " : " + rinfo.port);
});
server.on("Listening", function()
{
var address = server.address();
console.log("Server listening @ " + address.address + " : " + address.port);
});
server.bind(6000);
내가 코드를 실행하면 터미널에 인쇄 된 값이없는
여기 내 아두 이노 코드입니다. 무슨 일있어? 감사.