当我使用 Ethernet.begin(mac,ip) 时,led 没有打开和关闭。但是当我不使用那条线时它会起作用。但我需要通过使用以太网和 UPP 模块来开启和关闭。我怎样才能 ?
板卡型号:Ethernet 08 Twinker 套件、Twinker 继电器
#include <TinkerKit.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
TKLed led(O5); //O0 does not work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "ackv1"; // a string to send back
EthernetUDP Udp;
void setup() {
Ethernet.begin(mac,ip);
Udp.begin(localPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize)
{
// check the switch state
delay(1000);
led.off();
delay(3000);
led.on();
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}
编辑:
$ echo "hello" | nc -4u 192.168.1.177 8888
ackv1