PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DhcpAddressPrinter.ino 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. DHCP-based IP printer
  3. This sketch uses the DHCP extensions to the Ethernet library
  4. to get an IP address via DHCP and print the address obtained.
  5. using an Arduino Wiznet Ethernet shield.
  6. Circuit:
  7. Ethernet shield attached to pins 10, 11, 12, 13
  8. created 12 April 2011
  9. modified 9 Apr 2012
  10. by Tom Igoe
  11. modified 02 Sept 2015
  12. by Arturo Guadalupi
  13. */
  14. #include <SPI.h>
  15. #include <NativeEthernet.h>
  16. // Enter a MAC address for your controller below.
  17. // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  18. byte mac[] = {
  19. 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
  20. };
  21. void setup() {
  22. // You can use Ethernet.init(pin) to configure the CS pin
  23. //Ethernet.init(10); // Most Arduino shields
  24. //Ethernet.init(5); // MKR ETH shield
  25. //Ethernet.init(0); // Teensy 2.0
  26. //Ethernet.init(20); // Teensy++ 2.0
  27. //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
  28. //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
  29. // Open serial communications and wait for port to open:
  30. Serial.begin(9600);
  31. while (!Serial) {
  32. ; // wait for serial port to connect. Needed for native USB port only
  33. }
  34. // start the Ethernet connection:
  35. Serial.println("Initialize Ethernet with DHCP:");
  36. if (Ethernet.begin(mac) == 0) {
  37. Serial.println("Failed to configure Ethernet using DHCP");
  38. if (Ethernet.hardwareStatus() == EthernetNoHardware) {
  39. Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
  40. } else if (Ethernet.linkStatus() == LinkOFF) {
  41. Serial.println("Ethernet cable is not connected.");
  42. }
  43. // no point in carrying on, so do nothing forevermore:
  44. while (true) {
  45. delay(1);
  46. }
  47. }
  48. // print your local IP address:
  49. Serial.print("My IP address: ");
  50. Serial.println(Ethernet.localIP());
  51. }
  52. void loop() {
  53. switch (Ethernet.maintain()) {
  54. case 1:
  55. //renewed fail
  56. Serial.println("Error: renewed fail");
  57. break;
  58. case 2:
  59. //renewed success
  60. Serial.println("Renewed success");
  61. //print your local IP address:
  62. Serial.print("My IP address: ");
  63. Serial.println(Ethernet.localIP());
  64. break;
  65. case 3:
  66. //rebind fail
  67. Serial.println("Error: rebind fail");
  68. break;
  69. case 4:
  70. //rebind success
  71. Serial.println("Rebind success");
  72. //print your local IP address:
  73. Serial.print("My IP address: ");
  74. Serial.println(Ethernet.localIP());
  75. break;
  76. default:
  77. //nothing happened
  78. break;
  79. }
  80. }