Hi,
I have a Teensy 4.1 with an ethernet kit. I want to use it to make ethrnet -> keystroke device that wake a PC by using wake on USB.
I made this simple sketch. It does work when the computer is on but the when it is off the Wake on USB does not function as expected.
With a regular keyboard it does work.
Is this possible with a Teensy or does it just not support this?
Thanks! Below my code:
I have a Teensy 4.1 with an ethernet kit. I want to use it to make ethrnet -> keystroke device that wake a PC by using wake on USB.
I made this simple sketch. It does work when the computer is on but the when it is off the Wake on USB does not function as expected.
With a regular keyboard it does work.
Is this possible with a Teensy or does it just not support this?
Thanks! Below my code:
Code:
#include <NativeEthernet.h>
#include <NativeEthernetUdp.h>
#include <cstring>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(172, 16, 1, 111);
unsigned int port = 5000; // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
//Serial.begin(9600);
delay(1000);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// start UDP
Udp.begin(port);
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
if (strcmp(packetBuffer, "wakeUp") == 0) {
for(int i = 0; i < 10; i++){
Keyboard.press(KEY_A);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
Keyboard.release(KEY_A);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
}
}
}