Arduino默认Ethernet library class包含IPAddress
变量类型。这是什么IPAddress
?我为什么要使用它,为什么它不用于official example中的网关和子网IP?Arduino以太网库IPAddress()有什么好处?
4
A
回答
3
就像你说的那样,它只是一种可以存储IP地址的变量(如int
(整数))。使用整数,您不能在IP地址中添加所需的.
。此外,库只接受整数,因为对于字符串,事情“可能会变得混乱”。例如,如果您的字符串中有1
,则无法将其添加到另一个数字中。但是,如果您具有值为1
的整数变量类型,则会轻松添加。
我如何使用这个?:
在Arduino's EthernetIpAdress page,有这样的代码:
#include <Ethernet.h>
// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// the router's gateway address:
byte gateway[] = { 10, 0, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 0, 0 };
EthernetServer server = EthernetServer(23);
//the IP address is dependent on your network
IPAddress ip(192,168,1,1);
void setup()
{
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
void loop()
{
//print out the IP address
Serial.println(myIPaddress);
}
上线IPAddress ip(192,168,1,1);
,它会创建一个保存变量IP地址。在Ethernet.begin(mac, ip, gateway, subnet);
行中查找变量并将其提供给Ethernet
库。我不知道优点是什么,除了试图阻止人们使用整数类型并使其看起来更干净。它可以查找自动发布的IP地址,然后将其存储以备后用,如果它进入“空闲模式”,它可以请求相同的IP地址,因此它几乎就像一个动态IP,不会干扰其他设备并在重置按钮被按下时重置。我确信这有一些用处,但我想不出来。我只是想告诉你它是什么以及如何使用它。我想尽管如果你想让它易于改变或更易于用户阅读,使用#define IPadress 192.168.1.1
或类似的东西会更容易。
相关问题
- 1. Arduino和处理(PDE)通过以太网
- 2. Arduino以太网盾牌php
- 3. Arduino的以太网ENC28J60
- 4. Arduino以太网+ PHP请求
- 5. 是否有任何arduino以太网盾或IPv6库?
- 6. V13 Android支持库有什么好处?
- 7. Arduino以太网服务器问题
- 8. 以太网盾与arduino卡住
- 9. Arduino以太网获取参数
- 10. Arduino以太网字节大小问题
- 11. Arduino以太网屏蔽MAC地址
- 12. Arduino以太网盾:dhcpaddressprinter错误
- 13. Arduino以太网盾v1.1 ENC28J60 MAC地址
- 14. Arduino +以太网盾+蓝牙HC-05
- 15. Arduino以太网盾不检测断开
- 16. 元组有什么好处?
- 17. StringBuilders有什么好处?
- 18. 粘液有什么好处?
- 19. AJAX有什么好处?
- 20. “svn:externals”有什么好处?
- 21. Cakephp,它有什么好处?
- 22. cURL有什么好处?
- 23. ConcurrentSkipListMap有什么好处?
- 24. VS2010 SP1有什么好处?
- 25. AnkhSVN有什么好处?
- 26. JRebel有什么好处?
- 27. WTP有什么好处
- 28. 反射有什么好处?
- 29. Assert() - 它有什么好处?
- 30. Boost IPC有什么好处?