<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
		<id>http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Microduino_ENC_Network_%288%29</id>
		<title>Microduino ENC Network (8) - 版本历史</title>
		<link rel="self" type="application/atom+xml" href="http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Microduino_ENC_Network_%288%29"/>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Microduino_ENC_Network_(8)&amp;action=history"/>
		<updated>2026-04-21T09:49:26Z</updated>
		<subtitle>本wiki的该页面的版本历史</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https//wiki.microduino.cn/index.php?title=Microduino_ENC_Network_(8)&amp;diff=2543&amp;oldid=prev</id>
		<title>Pkj：Created page with &quot;{{Language | Microduino ENC网络（八）}} {| style=&quot;width: 800px;&quot; |- | ==Objective== This tutorial will show you how to control two leds with a more stylish webpage thanks...&quot;</title>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Microduino_ENC_Network_(8)&amp;diff=2543&amp;oldid=prev"/>
				<updated>2014-05-07T13:11:39Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Language | Microduino ENC网络（八）}} {| style=&amp;quot;width: 800px;&amp;quot; |- | ==Objective== This tutorial will show you how to control two leds with a more stylish webpage thanks...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Language | Microduino ENC网络（八）}}&lt;br /&gt;
{| style=&amp;quot;width: 800px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
==Objective==&lt;br /&gt;
This tutorial will show you how to control two leds with a more stylish webpage thanks to some images&lt;br /&gt;
&lt;br /&gt;
==Equipment==&lt;br /&gt;
*'''[[Microduino-Core]]'''&lt;br /&gt;
*'''[[Microduino-FT232R]]'''&lt;br /&gt;
*'''[[Microduino-ENC28J60]]'''&lt;br /&gt;
*'''[[Microduino-RJ45]]'''&lt;br /&gt;
&lt;br /&gt;
*Other equipment&lt;br /&gt;
**USB cable &lt;br /&gt;
&lt;br /&gt;
==Images==&lt;br /&gt;
First, you need to understand what happens when, in a webpage, there are references to external resources (images, javascript…:&lt;br /&gt;
&lt;br /&gt;
*user’s browser contacts the web server and asks for HTML page;&lt;br /&gt;
*browser parses the page and finds external resources;&lt;br /&gt;
*browser asks for each resource to the web server.&lt;br /&gt;
&lt;br /&gt;
When the web server answers, it tells the browser (in response header) the type of the file it’s sending using the MIME standard. Here’s an example (sniffed using Fiddler) about a PNG image:&lt;br /&gt;
[[File:Fiddler嗅探.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
Microduino’s sketch should be able to:&lt;br /&gt;
&lt;br /&gt;
*read browser‘s request (saved in Ethernet::buffer);&lt;br /&gt;
*identify the resource the browser is requesting (HTML page, images…);&lt;br /&gt;
*create an header with the correct Content-Type;&lt;br /&gt;
*send header and resource to the browser.&lt;br /&gt;
&lt;br /&gt;
==Binary Resources==&lt;br /&gt;
Images are binary files: in our simple example we should be able to store them in our sketch, in the form of byte arrays. I found a very useful utility that helps with this conversion: bin2h.&lt;br /&gt;
&lt;br /&gt;
Conversion’s result is a text file:&lt;br /&gt;
[[File:Bin2h.jpg|600px|center|thumb]]&lt;br /&gt;
To save microcontroller’s RAM memory, we store the images in the program memory using the directive PROGMEM:&lt;br /&gt;
[[File:imagebincode.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
==Schematic==&lt;br /&gt;
&lt;br /&gt;
[[File:MicroduinoENC8原理图.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
*Microduino-ENC28J60&lt;br /&gt;
*Microduino-RJ45&lt;br /&gt;
*Microduino-Core&lt;br /&gt;
*Microduino-FT232R&lt;br /&gt;
&lt;br /&gt;
Stack all modules and then connect the ethernet cable, as follows:&lt;br /&gt;
&lt;br /&gt;
==Program==&lt;br /&gt;
https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_ENC/ENCnetworkeight&lt;br /&gt;
&lt;br /&gt;
==Debug==&lt;br /&gt;
Step 1：Download the EtherCard library and copy to your libraries fold of IDE, then restart IDE.&lt;br /&gt;
https://github.com/jcw/ethercard&lt;br /&gt;
&lt;br /&gt;
Step 2：Explain the program:&lt;br /&gt;
&lt;br /&gt;
//My sketch parses browser’s request and – if it’s asking for one of the two images – calls the method to send it back to the browser:&lt;br /&gt;
&lt;br /&gt;
        if(strstr((char *)Ethernet::buffer + pos, &amp;quot;GET /led_off.png&amp;quot;) != 0)&lt;br /&gt;
          send_png_image(led_off, sizeof(led_off));&lt;br /&gt;
        else if(strstr((char *)Ethernet::buffer + pos, &amp;quot;GET /led_on.png&amp;quot;) != 0)&lt;br /&gt;
          send_png_image(led_on, sizeof(led_on));&lt;br /&gt;
&lt;br /&gt;
//This method prepares the response with the correct header and calls emit_raw_p() method to add image’s bytes to the response; finally it sends the full response back to the browser using httpServerReply method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  BufferFiller bfill = ether.tcpOffset();&lt;br /&gt;
  bfill.emit_p(PSTR(&amp;quot;HTTP/1.0 200 OK\r\n&amp;quot;&lt;br /&gt;
    &amp;quot;Content-Type: image/png\r\n\r\n&amp;quot;));&lt;br /&gt;
  bfill.emit_raw_p(png_image, image_size);&lt;br /&gt;
  ether.httpServerReply(bfill.position());&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
//If, instead, browser’s request contains ?LEDx, led’s status is changed and the html page is created with the correct images depending on leds’ statuses:&lt;br /&gt;
&lt;br /&gt;
    if(strstr((char *)Ethernet::buffer + pos, &amp;quot;GET /?LED1&amp;quot;) != 0) {&lt;br /&gt;
      led1Status = !led1Status;&lt;br /&gt;
      digitalWrite(LED1PIN, led1Status);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Step 3: Connect the bulb, as follws:&lt;br /&gt;
[[File:MicroduinoENC8连接图.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
Step 4：Copile the code and download it.&lt;br /&gt;
&lt;br /&gt;
Step 5：Use the browser to access the Microduino's IP, then click button, observe the bulb's state.&lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
Access the Microduino's IP address, click the button, browser will request the page and add the ?LEDx suffix: Microduino will change the LED state and the button's color.&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
&lt;br /&gt;
http://v.youku.com/v_show/id_XNzA0NDEzNjUy.html&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Pkj</name></author>	</entry>

	</feed>