PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

114 lines
3.1KB

  1. /*
  2. Telnet client
  3. This sketch connects to a a telnet server (http://www.google.com)
  4. using an Arduino Wiznet Ethernet shield. You'll need a telnet server
  5. to test this with.
  6. Processing's ChatServer example (part of the network library) works well,
  7. running on port 10002. It can be found as part of the examples
  8. in the Processing application, available at
  9. http://processing.org/
  10. Circuit:
  11. * Ethernet shield attached to pins 10, 11, 12, 13
  12. created 14 Sep 2010
  13. modified 9 Apr 2012
  14. by Tom Igoe
  15. */
  16. #include <SPI.h>
  17. #include <NativeEthernet.h>
  18. // Enter a MAC address and IP address for your controller below.
  19. // The IP address will be dependent on your local network:
  20. byte mac[] = {
  21. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  22. };
  23. IPAddress ip(192, 168, 1, 177);
  24. // Enter the IP address of the server you're connecting to:
  25. IPAddress server(1, 1, 1, 1);
  26. // Initialize the Ethernet client library
  27. // with the IP address and port of the server
  28. // that you want to connect to (port 23 is default for telnet;
  29. // if you're using Processing's ChatServer, use port 10002):
  30. EthernetClient client;
  31. void setup() {
  32. // You can use Ethernet.init(pin) to configure the CS pin
  33. //Ethernet.init(10); // Most Arduino shields
  34. //Ethernet.init(5); // MKR ETH shield
  35. //Ethernet.init(0); // Teensy 2.0
  36. //Ethernet.init(20); // Teensy++ 2.0
  37. //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
  38. //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
  39. // start the Ethernet connection:
  40. Ethernet.begin(mac, ip);
  41. // Open serial communications and wait for port to open:
  42. Serial.begin(9600);
  43. while (!Serial) {
  44. ; // wait for serial port to connect. Needed for native USB port only
  45. }
  46. // Check for Ethernet hardware present
  47. if (Ethernet.hardwareStatus() == EthernetNoHardware) {
  48. Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
  49. while (true) {
  50. delay(1); // do nothing, no point running without Ethernet hardware
  51. }
  52. }
  53. while (Ethernet.linkStatus() == LinkOFF) {
  54. Serial.println("Ethernet cable is not connected.");
  55. delay(500);
  56. }
  57. // give the Ethernet shield a second to initialize:
  58. delay(1000);
  59. Serial.println("connecting...");
  60. // if you get a connection, report back via serial:
  61. if (client.connect(server, 10002)) {
  62. Serial.println("connected");
  63. } else {
  64. // if you didn't get a connection to the server:
  65. Serial.println("connection failed");
  66. }
  67. }
  68. void loop() {
  69. // if there are incoming bytes available
  70. // from the server, read them and print them:
  71. if (client.available()) {
  72. char c = client.read();
  73. Serial.print(c);
  74. }
  75. // as long as there are bytes in the serial queue,
  76. // read them and send them out the socket if it's open:
  77. while (Serial.available() > 0) {
  78. char inChar = Serial.read();
  79. if (client.connected()) {
  80. client.print(inChar);
  81. }
  82. }
  83. // if the server's disconnected, stop the client:
  84. if (!client.connected()) {
  85. Serial.println();
  86. Serial.println("disconnecting.");
  87. client.stop();
  88. // do nothing:
  89. while (true) {
  90. delay(1);
  91. }
  92. }
  93. }