Wake On USB

Jaromir_m

New member
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:

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
      }
    }

  }


}
 
Is this possible with a Teensy or does it just not support this?
It looks like not being possible.

Uploaded the small program below to a Teensy 4.0:
C++:
#include <Bounce.h>
Bounce button0 = Bounce(0, 10);

void setup() {
  pinMode(0, INPUT_PULLUP);
}

void loop() {
  button0.update();
  if (button0.fallingEdge()) {
    Keyboard.press(KEY_SPACE);
  }
  if (button0.risingEdge()) {
    Keyboard.release(KEY_SPACE);
  }
}
It sends out a SPACE character every time I short pin 0 to GND.
Then I put my PC into standby and tried to wake it up by sending the SPACE character. Nope, did not work.

Waking up by hitting the SPACE bar on my regualr keyboard did work.

When I checked the Windows device manager, I see this for my Logitech keyboard:
1739029173103.png
1739029183154.png


And this is what I see for my Teensy keyboard:
1739029220437.png


I think the Teensy keyboard does not expose itsself as a keyboard with wake-up capabilities.

Paul
 
Back
Top