查看“Microduino ENC Network (2)”的源代码
←
Microduino ENC Network (2)
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language | Microduino ENC网络(二)}} {| style="width: 800px;" |- | ==Objective== This tutorial will show you how to use a DHCP server to automatically configure network parameters. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *'''[[Microduino-ENC28J60]]''' *'''[[Microduino-RJ45]]''' *Other equipment **USB cable ==DHCP== Usually, in local network you can find a DHCP server (Dynamic Host Configuration Protocol), that is a service which automatically configure the devices connected to the network. Without explaining too deeply the protocol, it works this way: The device (client) that needs an IP address, sends a DISCOVERY broadcast packet (that is a packet which will reach all the devices in the network), to “discover” if there are DHCP servers available; If one or more DHCP servers are alive, they answer with an OFFER packet, “proposing” an available IP address to the requesting client; The client chooses one of the offered IP addresses and sends a REQUEST packet, to ask for permission to use that address; The server that proposed it, answers with an ACK packet to confirm the IP address association. [[File:DHCPShow.jpg|600px|center|thumb]] Luckly what I described above has altready been implemented for us in the dhcp.cpp library file: I’m going to show a simple sketch using DHCP services. ==Schematic== *Microduino-ENC28J60 *Microduino-RJ45 *Microduino-Core *Microduino-FT232R Stack all modules and then connect the ethernet cable, as follows: [[File:MicroduinoENCShow.jpg|600px|center|thumb]] ==Program== Download the program: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_ENC/ENCnetworktwo ==Debug== Step 1:Download the EtherCard library and copy to your libraries fold of IDE, then restart IDE. https://github.com/jcw/ethercard Step 2:Explain the program: //First, I haven’t defined a fixed IP address anymore, just the MAC address. The controller’s initialization is still run with the usual begin() method. ether.dhcpSetup(); //The dhcpSetup() method performs all the steps detailed above: looks for a DHCP server, check its replies, choose an IP address and ask for permission to use it. That method waits for 30 seconds, after that it returns an error. ether.printIp(); //The printIp() method is an easy way to print on serial monitor an IP address (that is stored in Ethernet buffer as an array of uint8_t). Step 3:Compile the code and download it. Step 4:If everything goes right, you should be able to ping your Arduino again: [[File:DHCPcmdPing.jpg|600px|center|thumb]] ==Result== And our DHCP server will show a new device connected (EtherCard library chooses Arduino-XX as device name,with XX the last octet of MAC address): ==Video== |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Microduino ENC Network (2)
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息