查看“Microduino ENC Network (3)”的源代码
←
Microduino ENC Network (3)
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language | Microduino ENC网络(三)}} {| style="width: 800px;" |- | ==Objective== This tutorial will show you how to connect and retrieve data from a web site. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *'''[[Microduino-ENC28J60]]''' *'''[[Microduino-RJ45]]''' *Other equipment **USB cable ==DNS== Usually you contact a website typing its name (such as http://www.microduino.cc), your PC, using a DNS server, is able to resolve that name into the corresponding IP address to perform the connection. It’s so very important to configure in Microduino the IP address of the DNS server in your network: if the configuration comes from a DHCP server, usually Microduino will be able to automatically get also DNS server; if the configuration is entered manually, you need to include the IP address of your DNS server when calling the staticSetup() method: ==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/ENCnetworkthree ==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: To make the following example more realistic, use a simple PHP web page that sends a random aphorism everytime you connect (aphorisms from Aphorisms Galore): http://www.lucadentella.it/demo/aphorisms.php You’ll write code to get those aphorisms and print them to serial connection. You can verify if name resolution works using dnsLookup() method: EtherCard library has a very handy method to connect to a website: browseUrl(). This method prepares the connection; which is completed in following steps performed – during the loop - by the two instructions you already learned: browseUrl() method needs some parameters: prog_char *urlbuf, address’ fixed part; const char *urlbuf_varpart, address’ variable part; prog_char *hoststr,website’s name; void (*callback)(byte,word,word)), the name of a callback function, that is the function the library invokes at the end of the connection. '''Callback:''' The callback function contains the “actions” you want to execute at the end of the connection; in this example just the print of what you got through serial connection. You can choose the function name, but you have to declare it with the following parameters: static void response_callback (byte status, word off, word len) The first parameter contains the connection status, the second one the buffer offset from which the response is stored and the third one the response length. To understand the meaning of the offset parameter, you have to notice that all the data sent and received from ethernet connection is stored in the buffer we defined: byte Ethernet::buffer[700]; That buffer contains, when you receive data, the whole packet - including the fields for the header, checksum… Offset value tells you where the payload starts, that is where the website response is. A callback function to print the response is: static void response_callback (byte status, word off, word len) { Serial.print((const char*) Ethernet::buffer + off); } Step 3:Compile the code and download it. Step 4:Chek the output of the serial port. ==Result== If no other issues, you can see following result: [[File:responseCallback.jpg|600px|center|thumb]] ==Video== |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Microduino ENC Network (3)
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
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
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息