このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Microprocessors as webservers, with input and 生産(高) across web- art5serv1 OVERALL HOME     Other 構成要素 for programmers, not Arduino 明確な/細部
ARDUINO: 最高の,を越す Page    支店 "A": Arduino Course    支店 "B": Arduino "How To"s and 事業/計画(する)s
-d-Bookmark this on Delicious   Recommend to StumbleUpon

Microprocessors as Web Servers

With input and 生産(高) across the web (or LAN)

This page is browser friendly, by the way. Make your browser's window いっそう少なく wide than your whole 審査する and you will find the narrower columns much easier to read. For more tips like that, see my 力/強力にする Browsing hints.

Why this page??

I am an unashamed Arduino zealot, but this page is going to try to 演説(する)/住所 some general points which should 適用する to using almost any microprocessor to 始める,決める up a web server. Just be 警告するd: I am a "one 注目する,もくろむd king" as far as TCP/IP 事柄s are 関心d, although I have a reasonable background in the 金物類/武器類 and ソフトウェア of using Arduinos and clones.

What can you do?

With a fair bit of work, but not much money or 器具/備品, you can 始める,決める up a microprocessor to serve web pages. Or perhaps I should say "a web page" (more on this in a moment.)

A static (unchanging) page, to 陳列する,発揮する "Hello World", is pretty 平易な, and a good place to start.

Once you have that working, you could easily proceed to a webserver that will 報告(する)/憶測 the 明言する/公表する of inputs on your webserver. You could, for instance, interface your microprocessor to a 気温 sensor, and then anyone visiting the served page could see the 現在の 気温 at the place where your server is.

And the ultimate goal, achievable, is to 始める,決める things up so people out there in Internet Land can click buttons on the page your server sends them, and have something happen... whatever you've programmed the system to do... to the 生産(高)s of the microprocessor hosting the served page.

You can see such a system in 活動/戦闘 at one of my デモs. The links to them are on my ArduServer-How to page. (A 気温 sensor, readable across the internet, is a 最近の 新規加入 to the ArduServer2.)

What do you need?

(Apart from the patience of 職業 to get ALL the bits "権利" so that things finally WORK

** Let's start with something you don't need: A "static IP 演説(する)/住所". And you don't (for now) need to know what one is!)

** You need an "always on", reasonably 急速な/放蕩な, internet 関係. Many home 使用者s in the US and Europe now have a perfectly 適する 関係. "Dial up" won't do. Sorry.

** Another thing you don't need: You don't need to leave a "big" PC, i.e. one running Windows, on all the time.... as long as your router can 供給する DynDNS updating. If not, you do need to leave your big computer running. But that really isn't such a big 取引,協定 these days, with efficient machines. 信用 me... if you aren't doing this now, once you start, you'll never go 支援する to waiting for the thing to shut 負かす/撃墜する, waiting for it to start up. And anyway, many routers are 有能な of DynDNS updating. (More on that later.)

** You need at least a smattering of knowledge of HTML "programming". You need to be able to put something like the に引き続いて together....

 <html>
   <長,率いる>
      <肩書を与える>My Web Page</肩書を与える>
   </長,率いる>
   <団体/死体>
      <p>Hello World</p>
   </団体/死体>
 </html>

... but even THAT is more than you need! But the more you know about 令状ing HTML, the more you will be able to do with your page.

** You will need some 金物類/武器類 to connect your microprocessor to your 関係 to the internet. Most people, I 嫌疑者,容疑者/疑う, will use a LAN between that 金物類/武器類 and the router, and this "answer" has the 特別手当 that you can start with something "平易な", and then solve the next 範囲 of problems to take you to the ultimate 目的地. The "平易な problem" is creating an intra逮捕する server, i.e. something which can give a webpage to other 装置s on your LAN. If you are going this 大勝する, then you need an "Ethernet interface" for your microprocessor.

** And of course you need the microprocessor to host the page! As I said, I use an Arduino, but much of what is in this page 適用するs more 一般に.

My 初めの, little ArduServer (ArduServer1) cost me about $40 for the microprocessor and Ethernet 関係. My "big" one, ArduServer2, cost $55, 12/11.

The (longish) road to success....

First catch your rabbit. You need the さまざまな bits.

Become proficient on your microprocessor.

LAN "Hello World"

Once you have your microprocessor, know it is working, know how to work it: Connect your Ethernet interface, and try out the simplest web server デモ you can find for it. All you need is something which will do the 伝統的な "Hello World", across your LAN. I say "all"... even for that "simple" 仕事 you will have problems to solve.

One little "Gotcha" is that your server must have an IP 演説(する)/住所 that nothing else on your LAN has. Likewise, it must have a unique (to your LAN) MAC 演説(する)/住所. ("Machine 接近 支配(する)/統制する 演説(する)/住所.)

Neither is a "big 取引,協定", 特に the MAC 演説(する)/住所, but you may have to tweak the デモ code 供給(する)d for your system to fit your circumstances.

Getting "good" IP and MAC 演説(する)/住所s is one of the many "little things" you will come across on this 旅行 which "shouldn't" be a problem, but can be.

Your LAN probably has DHCP services running out of your router. To be 徹底的な, it is probably 価値(がある) telling your router not to use a whole 封鎖する of IP 演説(する)/住所s for dynamic 配分. (This "dynamic" has almost nothing to do with "DynDNS", by the way.). And then use one of the IP 演説(する)/住所s outside of that 範囲 for your Ethernet interface. In my 事例/患者, for instance, my router 問題/発行するs IP 演説(する)/住所s from 192.168.0.1 to 192.168.0.249 経由で DHCP, and never 問題/発行するs any others. That means it is "安全な" for me to make the IP 演説(する)/住所 of my microprocessor 192.168.0.250... as long as I 港/避難所't also 配分するd that IP 演説(する)/住所 to something else on my LAN.

The chance of your Ethernet interface having the same MAC 演説(する)/住所 as something else on your LAN is vanishingly small... and so why does it happen so often? Happily, all of the Ethernet interfaces for microprocessors I know about let you 割り当てる whatever MAC 演説(する)/住所 you wish to the interface.

This becomes 非,不,無-academic すぐに if you elect to put two microprocessor-driven Ethernet interfaces on one LAN. You would have to make at least one tweak to the ソフトウェア in the second one, so that it used a different MAC 演説(する)/住所.

While on the 支配する of IP 演説(する)/住所s, etc, I'll touch on and then forever hide from the topic of the anti-malware (ウイルスs, etc) 弁護s which I hope you have running on your system... It will have to be made happy about this new 装置 you are introducing. I 港/避難所't had too much trouble over this, but it is an area which can 原因(となる) trouble. Don't forget that you may have a firewall running in your router as part of your anti-malware 弁護s.

Wikipedia is 安全な for now

When I started out to create my first webserver, I already had dozens of pages published on the internet, which were held on a 商業の service's server, saving me all those 頭痛s.

Then I built my first PC based server. That was an adventure, too. Today, WAMP and the like make it so VERY much easier to 始める,決める up your own server, if you're willing to have it run in a PC.

At that point, I thought of a web server as a "box" which took care of serving up pages of "stuff", pages which were 蓄える/店d on the server as separate とじ込み/提出するs. The page you are reading now resides on a server 持続するd by 1&1, for instance.

So how do we 供給(する) a bunch of とじ込み/提出するs to a microprocessor? The (first... and only one, I have, so far) answer is: We don't

The sort of "web page serving" I know how to do with a microprocessor is 限られた/立憲的な to serving one page, a page hardcoded in the program that does the serving.

That isn't a 完全にする 災害, because the page can be a little dynamic. For instance, it can show the 気温 as (悪事,秘密などを)発見するd by a sensor connected to the microprocessor.

And another thing... the page can't be very large... at least with the systems I've been playing with. The に引き続いて pretty 井戸/弁護士席 filled a system I built... but after you ちらりと見ること at it, read on to some good news...


ArduServer2, ver 1 Jan 12d

See ArduServer.com

Cmnds: ?cmd=0 and ?cmd=1
追加する "/?cmd=1" to page URL for different text here.

- -

気温, degrees C: 16.53

- -

Analog input 0 reads: 262
Connected to a phototransistor.

Light in room: 薄暗い.

- -
Analog input 1, senses LED light, reads: 73

Remember: This is just a screenshot... buttons don't work here.

Clicks since ArduServer booted: 124


(** PREVIOUSLY: AN REVOLVERMAPS IMAGE DISPLAYING HITS **)


STOP PRESS: It seems that maybe there's an element of bad advice in some of the pages this is connected to.

It may be a bad idea to use any of the に引き続いて at the same time as a W5100 based 保護物,者... although for a "プロの/賛成の Ethernet" it seems that only D10-D13 should be 避けるd. I am working on a 類似の 名簿(に載せる)/表(にあげる) for ENC28J60 interfaces... it seems it might be the same as the 名簿(に載せる)/表(にあげる) below, minus D4, An0 and An1... but your work might 同様に be W5100 friendly, too, don't you think?

... and D13, but this last one only if you "care" that on the 保護物,者 it goes to an LED, and from there through a resistor to ground. (This 単に 平行のs the same thing on many Arduino and clone boards... BUT, to digress from the digression, BE AWARE that the ソフトウェア behind "体制/機構()" and "宙返り飛行()" pulse D13 high 簡潔に before 遂行する/発効させるing whatever you 明示するd in "体制/機構()".)

Of course, I unwittingly used some of those lines in my designs. The designs SEEM to work, but it would be a good idea to take what I've put on those lines and move them どこかよそで. I will 徐々に be 改訂するing my designs as follows....

(I've done a separate page with help on the support 金物類/武器類, 含むing a PCB design for a suitable 保護物,者.)

In every 事例/患者, to 修正する the ソフトウェア is 平易な... but you will need to look carefully to see whether what is 現在/一般に online has been 修正するd or not.

To change the line used for, say, the phototransistor watching the LED in, say, ArduServer2, the line....

(弁護士の)依頼人.print("<br>Analog input 0 reads: <b>");
(弁護士の)依頼人.print(analogRead(0));

... must be changed to...

(弁護士の)依頼人.print("<br>Analog input 1 reads: <b>");
(弁護士の)依頼人.print(analogRead(1));

... and you are done! (You'll have to move one wire on your breadboard, too, if you had it wired for the 初めの design.)

(Digression: Is nothing every 平易な? In 99.0% of my code, such a change would 単に have been a 事柄 of changing something like the "const byte bLEDpin=8;" at the start of the program. But in this 事例/患者, to 避ける fighting with... not hard... getting the 誘発する to identify the channel, I took a shortcut and 明示するd the channel explicitly instead of a 全世界の variable. Sigh.

Sorry! I could have done without this, too! When will the 公式の/役人 Arduino 場所/位置 have proper documentation of the ethernet 保護物,者 and library?? I am working on getting all my pages 変えるd to the "new 基準"... in the 合間, you'll just have to stay 警報!


So. Do you see why I 長,率いるd this section "Wikipedia 安全な"? You won't with a simple microprocessor server publish 広大な 量s of (警察などへの)密告,告訴(状)... but you will be able to publish your (警察などへの)密告,告訴(状). And, if you wish, 支配(する)/統制する things around the microprocessor from any internet 終点.

The good news is that the little page I showed you above, in real life, has a graphic in place of the text "IMAGE DISPLAYING HITS". It shows the place people were in when they visited the page, it 名簿(に載せる)/表(にあげる)s the countries people visited from and it shows any 現在の 訪問者s. It is a 解放する/自由な service from RevolverMaps.com. ーするために have the Revolver 地図/計画する on my page, I had to 挿入する about 650 characters into the page, characters which could have been used for other things, had I wished.

By the way... again... Another thought for you: A simple microprocessor based web server is not going to have 層s of 安全. I would assume that anything you can do 経由で your server, other people can do, too. I don't mind people playing with the LEDs I have connected to my ArduServer... but I'm not going, say, to 設立する a way to 打ち明ける my 前線 door across the internet just yet. (I 打ち明ける my 前線 door with an RFID tag in my watchstrap... but I (or at least my watch) has to be there for that to happen.)

Understand the workings of "the internet"

As you are reading this page, I gather that you able to put a URL (the "www- thingie") into a browser (Firefox, Chrome, etc). But how much do you know about how it all 作品?

You're going to have to know (or learn) a bit, if you want to 始める,決める up a microprocessor server. Sorry.

When you put, say, http://sheepdogsoftware.co.uk, into your browser, some amazing stuff goes on. I'll try to 含む/封じ込める myself to the 必須のs.

First of all, "the system" translates the sheepdogsoftware.co.uk into a "number", something like 73.141.83.201. If that were the actual number (I just made something up), then the server for sheepdogsoftware.co.uk is (for the moment) at IP 演説(する)/住所. The 場所/位置 is 地雷, but I don't know where the server for it is just now, as I 支払う/賃金 1&1 to take care of that problem for me.

You're going to need an 演説(する)/住所 for your microprocessor based server... but it is both 複雑にするd and not 複雑にするd.

The "not 複雑にするd" part of it first:

Your server is going to "talk to" the outside world through your router. The router and your server will be talking to one another across a LAN, or at least a link that looks like a one 駅/配置する LAN. The 演説(する)/住所 for the server, at that level, will be something like 192.168.0.252

最初, I would 示唆する that you get things working just within the LAN... 解雇する/砲火/射撃 up a browser in a PC connected to the LAN, put the server's 地元の IP 演説(する)/住所 in, and you should see the page the server serves. If you don't, 直す/買収する,八百長をする whatever problems are in the way, because they'll still be there when you try the fancier things later, and still stop you 後継するing.

Your router shows a different IP 演説(する)/住所 to the outside world. Unless you have a static IP 演説(する)/住所 for that, and you will know, from the 苦痛 of 支払う/賃金ing the 法案, your router 会談 to the outside world with a dynamic IP 演説(する)/住所. It may not change very often, but it does change, whenever it 控訴s your internet service provider.

Can you see where this is going? Put together the things I've said recently.

結局, you will have a URL for your microprocessor server. Let's say it is MyServer.com. "The system" (outside your LAN) has a 機械装置 which looks up things like sheepdogsoftware.co.uk an MyServer.com in "directories", and sends 支援する the IP 演説(する)/住所 for the submitted URL. Your browser then uses the IP 演説(する)/住所 to 接触する the server. (If you happened to know the IP 演説(する)/住所, you could 接近 the server with that... but you don't usually know it.)

The part of the system that translates URLs to numbers is called the DNS (Domain 指名する System).

A little digression: There are two "IP 演説(する)/住所s" coming into this discourse: The "outside" IP 演説(する)/住所, the one the router uses with the outside world, and the IP 演説(する)/住所s of the 装置s in your LAN. For the moment, I am talking mostly about the outside IP 演説(する)/住所.

So there's the DNS. It is like a telephone directory. If sheepdogsoftware.co.uk were 現実に at 73.141.83.201, as long as it stayed at that IP 演説(する)/住所, and as long as somewhere along the line the DNS was told that was the IP 演説(する)/住所 for that URL, then all would be 罰金.

So what happens when my ISP gives me a new IP 演説(する)/住所? My 場所/位置, sheepdogsoftware.co.uk, is no longer at the old IP 演説(する)/住所. 災害. My hosting service has either to 支払う/賃金 for a static 演説(する)/住所, or keep 跡をつける of any changes, and tell the DNS about them.

When you not only edit your pages, but also 直接/まっすぐに manage the server that they come from, you have to start 取引,協定ing with the IP 演説(する)/住所 問題/発行する.

Happily, there's an answer.

DynDNS.org

DynDNS.org is not the only organization 申し込む/申し出ing the service I am about to 述べる, but it is the one I "know and love", and can recommend.

This is what they do...

You 調印する up with them and they will give you a URL. (You can't just (不足などを)補う whatever URL you want... the 配分 of 指名するs is controlled... globally. It wouldn't work to have two sheepdogsoftware.co.uk's, would it? Which one would be 陳列する,発揮するd in the browser of someone who went to "the" sheepdogsoftware.co.uk page?

"Your" 指名する, if 供給するd for 解放する/自由な by DynDNS.org will be a little constrained. I have two, and, by my choice, they are both sub-domains of DynDNS.org...

   http://mon277rr.dyndns.org/
   http://mon7nc.dyndns.org/

("mon" as in "監視する", and "277rr" and "7nc" because that tells me what is 監視するd by the web pages 大(公)使館員d to those URLs.)

Here's the 魔法 bit: Either a PC connected to your router, or your router, if it is clever enough, 絶えず (井戸/弁護士席... every so often) checks what (outside) IP 演説(する)/住所 is 現在/一般に 配分するd to you by your ISP. When that 配分 changes, your PC or your router send a message to DynDNS, who then send a message to the DNS, and your 入ること/参加(者) in the DNS (米)棚上げする/(英)提議するs gets updated. 冷静な/正味の! And while you probably don't fully understand all of that now, I'm leaving その上の discussion to the innards of the 詳細(に述べる) led tutorials about setting up servers, apart from two things...

a) "DynDNS" stands for "Dynamic DNS".

b) We've been talking about the "outside" IP 演説(する)/住所. What about the LAN IP 演説(する)/住所 of your server?

Before I 演説(する)/住所 that, I want to look at "What about the LAN IP 演説(する)/住所 of the PC you are using to 接近 the internet? Assuming you are 接近ing it though a router, which you are 接近ing across a LAN, be it wired or wireless.

Here's what happens...

You ask for the page at sheepdogsoftware.co.uk.

A message, flagged with your PC's 地元の (LAN) IP 演説(する)/住所, goes to the router. The router "makes a 公式文書,認める" as to what's going on, and 現在のs the request for sheepdogsoftware.co.uk 経由で the router's 外部の IP 演説(する)/住所

In 予定 course, the answer comes 支援する, again 経由で the router's 外部の 関係s, 外部の IP 演説(する)/住所. However, the router has a way of knowing that this answer is for your PC, and so passes it on to your PC, again using that PC's LAN IP 演説(する)/住所.

Good news: You won't have to 取引,協定 直接/まっすぐに with these things (much)... but you may need to know them to を取り引きする "stuff" as you proceed に向かって having a working server online!

So. We're getting there. You know about the parts which have to be connected. You know about the IP 演説(する)/住所 for connecting over the LAN to your router, you know that it needs an 外部の IP 演説(する)/住所, and a URL which the DNS knows about. And you know how to 持続する the DNS's idea of "where" your server is, even though the 演説(する)/住所 may change from time to time.

Hello (Internet) World

Whatever microprocessor and Ethernet interface you are using, there should be a "Hello World" example online for you to start from.

For the Arduino with the "基準" Ethernet 保護物,者, there's a デモ called "WebServer" in the Ethernet folder of the Examples which you can 接近 from the とじ込み/提出する menu item. (At least there was with Arduino.exe 0022, which was 現在の when I wrote this in August 2011.

Get the (地元の) IP 演説(する)/住所 問題/発行するs, sketched above, taken care of, and you should be able to see the デモ's "Hello World" across your LAN without much ado. You don't need to worry about DNS, the outside IP 演説(する)/住所, DynDNS, etc., for that.

Once you can see the "Hello World" デモ 地元で, get yourself a DynDNS URL, and 打ち勝つ whatever little "joys" を待つ your want (if "need" can be a noun, "want" can be a noun!) to see that "Hello World" by entering a URL. Just to be on the 安全な 味方する, phone some friends. See if they can see your server's "Hello World" from where they are. (いつかs when you use a URL from within a LAN, if the URL 株 the same outside IP 演説(する)/住所 as PC 捜し出すing the page, you can get experiences people outside your LAN don't get. You should both see the same thing.)

Whew! Whew! Whew! Whew! WHEW!

Exhausted? No? Then you've only skimmed the above. And not tried to do any of it in practice. If ever there were a battleground filled with 詳細(に述べる) devils, what we've been talking about is it.

But there's good news again!!!

Once you've got this far, the 残り/休憩(する) of our 旅行 is 比較して "平易な". If you have a "Hello World" server running, which can be seen from anywhere on the internet, you've got past the worst bits, and got 井戸/弁護士席 past half way.

The ソフトウェア

Now it is time to delve into the ソフトウェア, and how it all 作品.

In a nutshell, your server....

(So far, our reply is the stuff needed to put "Hello World" on the 受取人's 審査する, when the html is "fed" to a browser.)

The stuff needed to put "Hello World" on the 受取人's 審査する...

You might get away with nothing more than a few header lines and "Hello World".

It would be better to send the header lines, 加える at least....

 <html>
   <長,率いる>
   </長,率いる>
   <団体/死体>
      <p>Hello World</p>
   </団体/死体>
 </html>

There are many guides to 令状ing HTML out there on the internet. Don't worry... you can ignore them for now! But when you are ready to make your page nice, learn some HTML.

A digression... a different comms 計画/陰謀

Before I take you through an 輪郭(を描く) of how things pass between computers across the internet, I want to talk about something 類似の, but older. Then I will return to what I was 説 just now, explain more of it.

Once upon a time, if we 手配中の,お尋ね者 to connect two computers, we did it with a serial cable... and you can still do that today.

For those computers to "talk" here's how things were often done...

Each had a "衝撃を和らげるもの". When things arrived from the other computer, they went first and すぐに to the 衝撃を和らげるもの. The receiving computer dealt with them, from the 衝撃を和らげるもの, when it "felt like it". As long as 機械装置s were in place to 確実にする that neither 衝撃を和らげるもの became too 十分な, all was 井戸/弁護士席.

Doing such things with an Arduino as one 味方する of the "conversation" (or two Arduinos talking to one another) isn't too difficult. I wrote some web pages about serial communications with Arduinos.

In general, programs for such comms have a few "housekeeping" 半端物s and ends to do once, as the program is starting, and then something like...

scMySerialConnection.print('Hello World');

.. is enough to send the text off to the other computer's serial input 衝撃を和らげるもの, where it sits 静かに until 過程d.

Sits 静かに until 過程d...

So much for how things are sent. What happens at the receiving end. We're still talking about serial comms... internet interactions are to follow.

A program for having two computers "talk together" is either going to have an event handler which is 誘発する/引き起こすd by 後継の characters, or, in the 事例/患者 of the いっそう少なく 複雑にするd microprocessor world, a 宙返り飛行 with the に引き続いて, at a 最小限, in it. (The 宙返り飛行 will probably have other things, such as code to look at what was received, and behave accordingly... if only "behave" as far as putting what was received on a 審査する the human 使用者 can 見解(をとる).

宙返り飛行(){
if (scMySerialConnection.NotEmpty)
  {bTmp=scMySerialConnection.DeliverByte;
    //use byte somehow
}
}

The two hypothetical things in that, NotEmpty and DeliverByte will be things that are 供給するd, somehow, by the particular ソフトウェア and libraries you are using in your 環境.

The first returns a boolean "true" or "誤った", depending on whether there is something waiting in the receive 衝撃を和らげるもの. The second takes the oldest byte out of the 衝撃を和らげるもの, and puts it in bTmp, in the code above.

The "use byte" part may 井戸/弁護士席 伴う/関わる collecting up several bytes into an array or string, and 過程ing the whole message once it has arrived. How do you know it has arrived? Either by arranging things so that all messages are of the same length, or by having some character 始める,決める aside to "say" "that's it, message 完全にする."

So... that's life when you're doing serial comms.

Internet Comms

I may be 乱用ing the 条件 わずかに, but I think the 権利 指名する for what I've called "internet comms" is TCP/IP: "伝達/伝染 支配(する)/統制する 議定書 / Internet 議定書"

"議定書" means "支配するs, ways of doing things".

Our serial comms example wasn't trivial, but it was helped by a few things. It could have been worse... but it was 限られた/立憲的な. TCP/IP is "worse".... but it is 価値(がある) it, for the extra fun it gives you!

Serial comms, as 述べるd above, was for Computer A to talk to Computer B, over an already 設立するd, always 利用できる, "私的な" channel.

With TCP/IP, there may be more than two computers, but more than two at the same time is an "前進するd" topic for another time. However, even for the simple things we'll discuss here, while it will be two computers at a time, the computer from out there in Internet Land which is talking to your server today may 井戸/弁護士席 be different from the one which was talking to it yesterday.

All a bit more コンビナート/複合体 than the simple two- computers- wired- together of the serial comms 事例/患者. And so, I 恐れる, a わずかに more コンビナート/複合体 シナリオ... but don't worry! Serial wasn't too コンビナート/複合体, and TCP/IP remains do- able.

An aside: In the simple シナリオ we are 取引,協定ing with here, the two computers in "conversation" do not "remember" each other, beyond the に引き続いて:

Computer "A" says to Computer "B", "Please send me the page called GoodStuff.htm". Computer B "remembers" Computer A just long enough to 答える/応じる. If A asks for some その上の (警察などへの)密告,告訴(状) a moment later, B doesn't "realize" that they've talked before. And our little microprocessor driven server can't even 受託する a request for a 明確な/細部 page... it can only send one (公正に/かなり small) page.... but the page's content is dynamic, which makes all the difference.

Simple ソフトウェア for web page serving

If you visit either of my pages with code for Arduino based web servers, you may be daunted by the sourcecode.

You don't need to be. The code isn't as bad as it looks.

The に引き続いて is a bit general, and I don't even 約束 that it is 100% 訂正する... but these are the 概念s which got me to the end of programming my working ArduServers. (There are two まず第一に/本来 so that I could 調査する the プロの/賛成のs and 反対/詐欺s of two different Ethernet interfaces.

First, as with the programs for serial comms, there are a few things which must be done once at the start of the program's 死刑執行, to "始める,決める the scene" for the communications. In the 事例/患者 of the programs for serial comms, one of the things you did once at the beginning was to 知らせる the 決まりきった仕事s you would use of the baud 率 you 手配中の,お尋ね者. In the 事例/患者 of the programs for TCP/IP you will 知らせる the 決まりきった仕事s of the IP 演説(する)/住所 and MAC 演説(する)/住所 to be used.

The IP 演説(する)/住所 I am speaking of here is the 地元の, or 内部の, IP 演説(する)/住所. The one used to 位置を示す your server within your LAN, the 演説(する)/住所 which probably starts 192.168...

Neither you nor your program needs to know what "outside" IP 演説(する)/住所 the router is using to pass on your requests to the outside world, and receive the answers... which it passes 支援する to you 経由で the 地元の IP 演説(する)/住所.

With TCP/IP programming things are a little more コンビナート/複合体 that the programming for the serial comms.

The main "do it again and again" part of your server program watches out for an 後継の request. Should one be seen, a "関係" is 始める,決める up, and the request flows into 衝撃を和らげるものs. In some 事例/患者s, you will send an answer 支援する, 経由で the 関係. In any 事例/患者, not long after the 過程 started, the 関係 will be shut 負かす/撃墜する again.

(I am really "winging it" there... if any 専門家s would be good enough to send me 建設的な 批評, I would be delighted to 改善する the above, as necessary!!)

That, as best as my 限られた/立憲的な knowledge 許すs, re-covers the idea of "the program watches for someone to come knocking at the door"

All I know about 扱うing so far is a "GET" request... but that's okay, because it is "GET requests" that browsers send.

I you look into the code for ArduServer2, you will see that the authors of the program I based that on say that you can tell when a page request has come in, because the last line (before you run out of sent stuff) will be a blank line. Their code watches for this, and if it sees it, it assumed a GET request(?) and moves on to 答える/応じるing to it.

My own 研究s 示唆するd that the "stuff" sent with a GET request 含むd a line which might look like...

GET / HTTP/1.1

The デモ code I adapted already ignored requests which didn't end with a blank line. I 追加するd 監視するing of a 確かな character within the "GET" line... more on this later.

My reply... it's a bit scrumpled...

認める the 引用する? (Not important if you don't)

So... we've talked through the 早期に 行う/開催する/段階s of a TCP/IP interaction. Assuming everything points to the need for a reply, how do we go about that?

Happily, in both of the ArduServer programs I've written, you just do a bunch of lines a bit like....

printtolan('<html>');
printtolan('<長,率いる>);
printtolan('</長,率いる>);
printtolan('<団体/死体>);
printtolan('<p>Hello World</p>);
printtolan('</団体/死体>);
printtolan('</html>);

The word isn't 現実に "printtolan", but the code fragment above illustrates what you are going to do.

It is a little strange, at first, 令状ing the web page text (in HTML) while at the same time 令状ing the program code, in a second language.

Be that as it may... 深い within your server program is a 封鎖する of code which, in essence, is just a bunch of "print" 声明s filled with HTML.

Depending on your 環境, you may be able to pass things other than strings to the web page. Suppose, for instance, in your program you had a variable called wClicksSoFar, 持つ/拘留するing the number of clicks seen by the server since it was last booted. You could almost certainly do the 同等(の) of...

(If your "printtolan" isn't very clever, you might have to do something extra to turn the number in wClicksSoFar into a string, but that isn't necessary in the Arduino language... not, at least, the language for the W5100 Ethernet interface. (I don't 解任する if what you use for the Microchip ENC28J60 is as 有能な. I think it is.)

As long as you have everything "ready" before you get to the 封鎖する of code with all the "printtolan" 声明s, much more is possible. You could, for a simple instance, 拡大する the above to...

printtolan('<html>');
printtolan('<長,率いる>);
printtolan('</長,率いる>);
printtolan('<団体/死体>);
printtolan('<p>Clicks so far: ');
printtolan(wClicksSoFar);
printtolan('</p>);

if (wClicksSoFar<100){
  printtolan('Where is everyone?');
   }
  else {
  printtolan('More than 100 clicks served!');
   }

printtolan('</団体/死体>);
printtolan('</html>);

That's a 大部分は facetious example... but it will do. Just don't underestimate the 力/強力にする of the 施設 illustrated.

If you can 報告(する)/憶測 what is in wClicksSoFar, as illustrated above, you can use your microprocessor's I/O 能力s to sense the things connected to it, and 含む that (警察などへの)密告,告訴(状) in the page served.

The Arduino has, built in, the 金物類/武器類 and ソフトウェア for ADC... analog to 数字表示式の 転換.

You can put a light sensor on, say, Analog0, and then have in your page...

printtolan('<html>');
printtolan('<長,率いる>);
printtolan('</長,率いる>);
printtolan('<団体/死体>);
printtolan('<p>Reading of light on sensor: ');
printtolan(analogRead(0));
printtolan('</p>);
printtolan('</団体/死体>);
printtolan('</html>);

There are many variations possible on these 主題s... I hope I have got you thinking about all the creative things you can do, now that you realize where to but the code behind the stuff the 使用者 of the server sees.

A little 詳細(に述べる)...

Some 訂正する (if simple) HTML headers are shown in the code above. There are more headers, which are seen by the server, which arrive before the HTML headers. In 新規加入 to the lines already given, before them, when replying to a GET request, you need to send (by the same 機械装置)....

printtolan('HTTP/1.1 200 承認する');
printtolan('Content-Type: text/html');
printtolan();

We're "halfway" there... but don't panic...

I meant "halfway" in the sense of we have covered how to 遂行する one of our two goals: A webpage with dynamic content, 報告(する)/憶測ing on what is seen at the microprocessor's inputs.

Happily, in building that, we took care of lots of things needed to 許す 使用者s of the server to send it "inputs", so we are way beyond half way through the text of this tutorial. And thanking our lucky microchips that this is the 事例/患者s!

Send in the... not the clowns... Send in your inputs

Now we will turn to how you 始める,決める things up so that the person 見解(をとる)ing the page served by your microprocessor can 原因(となる) 生産(高)s of the microprocessor to change.

When I think how many years I was perplexed by this, it is 悪化させるing that it really is very simple. (When you know how).

The first thing you need to know is that if, into the 演説(する)/住所 妨げる/法廷,弁護士業 of your browser, you enter, say...

http://sheepdogsoftware.co.uk/sc1main.htm/?HiSheepdog

... two things will happen. First all the コンビナート/複合体 魔法 of fetching the page at Sheepdog ソフトウェア about sensing and 支配(する)/統制する work will be returned to your browser.

In 新規加入, the "?HiSheepdog" part will be 利用できる to the server. In most 事例/患者s, it will just be thrown away, 特に if you pass something 予期しない. But it doesn't have to be thrown away.

I'm going to 言及する to the bit on the end as the 使用者 命令(する).

Once you know that, two questions arise:

Sending 使用者 命令(する)s

You can, of course, be 歩行者 and just type them into your browser's 演説(する)/住所 妨げる/法廷,弁護士業 (where URLs go) by 手渡す. And いつかs this is The Way To Go.

You can help 使用者s of your 場所/位置 by creating links which 含む the appropriate 使用者 命令(する). Here is some HTML to illustrate the point. You can't click on these, here. If they were "inside" a page, they would create clickable links which would do what they say, assuming there was a server at MyServer with an LED 始める,決める up to turn on with the 命令(する)s shown...

<a href="http://www.yansite.逮捕する/etoj.cgi?sw=j&URL=http://MyServer.com/MainPg.htm?SetLEDOn">Turn LED On</a>
<a href="http://www.yansite.逮捕する/etoj.cgi?sw=j&URL=http://MyServer.com/MainPg.htm/?SetLEDOff">Turn LED Off</a>

(All the 使用者 would see would be two links: "Turn LED On" and "Turn LED Off")

Now 準備する yourself for, perhaps, some minor mental 体操. Although some will say that what I'm going to show you is "obvious", I don't think everyone will think so.

What would happen if the links above were on the "MainPg.htm" page of MyServer.com?

Yes! The link would re-負担 MainPg.htm, but with the 使用者 命令(する) passed to the server 同様に.

Neat?

Of course, in our simple microprocessor based web serving, we don't have the 高級な of 多重の pages at our 場所/位置s. No problem. We just have to adapt the above わずかに. If the page at MyMicroServer.com, served by a microprocessor, had the link...

<a href="http://MyMicroServer.com/?cmd=SetLEDOn">Turn LED On</a>

.. then that link would reload the 選び出す/独身 page that MyMicroServer.com would 負担, but the 使用者 命令(する) "?cmd=SetLEDOn" would be passed to the server at the same time as the request for the page.

There's nothing "special" about the text "?cmd=". The computer doesn't "know" what it means. But for the next thing we'll discuss, buttons, it is easier if the 使用者 命令(する) is in two parts joined by an equals 調印する.

The question 示す is at least 伝統的な, and may be necessary in some circumstances, so I'm putting one in, just in 事例/患者.

So far so good, so 適する. But "I want a button!", I hear you cry. "Links are so... basic."

I was mystified by buttons, and the forms that 配達する them. I still know next to nothing about them. But in the デモ for the nuElectronics Ethernet 保護物,者 I saw a button used as follows. It really doesn't do more than create a button to make the request made by the link we have just discussed. Again, what you see below is the HTML to go into a page.

<form METHOD=get 活動/戦闘="http://MyMicroServer.com/">
<input type=hidden 指名する="cmd" value="SetLEDOn">
<input type=服従させる/提出する value="Turn LED On">
</form>

挿入するing that in your page's HTML creates a button with "Turn LED On" on it. When you click the button, it will be as if you had entered....

http://MyMicroServer.com/?cmd=SetLEDOn

Into your browser's 演説(する)/住所 妨げる/法廷,弁護士業.

Using 使用者 命令(する)s

When your server begins to 過程 a request from a browser, it not only receives the 使用者 命令(する), if any, sent from the browser, but a whole bunch of other stuff arrives 同様に. Here is a 見本 of what a server at MyMicroServer.com might receive if a browser asked for what http://MyMicroServer.com is serving:

GET / HTTP/1.1
Host: MyMicroServer.com
使用者-スパイ/執行官: Mozilla/5.0 (Windows; U; Windows NT 5.1;
    en-US; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18
    ( .NET CLR 3.5.30729; .NET4.0C)
受託する: text/html,使用/適用/xhtml+xml,
    使用/適用/xml;q=0.9,*/*;q=0.8
受託する-Language: en-us,en;q=0.5
受託する-Encoding: gzip,deflate
受託する-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
関係: keep-alive

The only part of that which 利益/興味s us for our needs is the "GET" line.

If the 使用者 had entered http://MyMicroServer.com/?cmd=SetLEDOn, then the GET line would be....

GET /?cmd=SetLEDOn HTTP/1.1

That's most of "the secret" of 扱うing 使用者 命令(する)s. The 残り/休憩(する) is just tedious 詳細(に述べる).

You need to 位置を示す the part of your system where what is coming in from the requester is fetched. In simple 使用/適用s, the program is probably just fetching a character from a 衝撃を和らげるもの, and another, and another, etc, until the 衝撃を和らげるもの is empty.

To 過程 使用者 命令(する)s, you need to watch that stream of characters. I think you can rely on the GET 存在 the first line of the message you might want to 答える/応じる to. I hadn't thought of that when I created ArduServe2 from the 基準 (at 7/11) Arduino "WebServer" デモ. In my program I looked at each line as it (機の)カム in, and saved the most 最近の one to begin with "GET". (I don't 推定する/予想する there would be more than one, but what the program and the system does is always more important that what you are assuming.)

I waited until all of the request had arrived, and then, just before 生成するing the 返答, I looked at what was in the GET line.

I cheated. Instead of looking at the line in 詳細(に述べる), I only looked at the 10th character. As I had 明示するd that the 命令(する)s I would 過程 were...

   /?cmd=0
... or...
   /?cmd=1

... I could just look at the 11th character in....

   GET /?cmd=0 HTTP/1.1/
... or...
   GET /?cmd=0 HTTP/1.1/
... or...
   GET / HTTP/1.1/

.. and 行為/法令/行動する on whether I saw a 0 or a 1 or a /, the latter arising when the 使用者 did not 供給(する) a 使用者 命令(する).

This 天然のまま answer is fraught with ways to go wrong when you try to 延長する the program... but it 作品 for simple needs!

Two servers on one IP 演説(する)/住所: The 魔法 of ports

Many of you won't need this little 付加 gem... but if you already have a server on your internet 関係, this is how you can 始める,決める up another, without 乱すing the first.

When I said "server" just now, I meant a server which is accessible from the outside world.

As we discussed どこかよそで, people in the outside world will 接近 your server with a URL... "MyServer.com", or somesuch. Probably something arcane. One of my servers, for instance, is 接近d 経由で

http://mon277rr.dyndns.org/

Somehow... in my 事例/患者, with a little help from the nice people at DynDNS.org, the DNS has an internet 演説(する)/住所 for every URL on the 惑星. At the moment, the IP 演説(する)/住所 for the above is 71.235.6.85, for instance. But that could have changed by the time you read this. I don't care, though, because everything is 始める,決める up to を取り引きする those 問題/発行するs automatically. Now. And I've told you どこかよそで how to get things 始める,決める up thus.

When someone sends a request to http://mon277rr.dyndns.org/, that request turns up on the "outside" half of my router. It then 今後s the request to a computer on my LAN, at some 演説(する)/住所 like 192.168.0.251. That computer is running the server which 配達するs my FarWatch pages. The computer 組み立てる/集結するs what is needed, passes it to the router, over 192.168.0.251. The router sends the 構成要素 off to whoever asked for it 経由で, at the moment, 71.235.6.85.

How do I put an ArduServer on my LAN "along 味方する" of the FarWatch server? How to I make FarWatch's traffic go to the FarWatch server, and the ArduServer traffic go there.

It is all about "ports".

The default port for http is port 80. You can say, explicitly, that you want to talk on port 80 by 追加するing ":80" to the end of the URL, like so:

http://mon277rr.dyndns.org:80/

... but there'd be no 推論する/理由 to.

"Port": In 国民 禁止(する)d 無線で通信する 条件, it is a bit like a "channel".

If you put the に引き続いて into your browser...

http://mon277rr.dyndns.org:81/

... the browser will send a "GET" request to the same IP 演説(する)/住所, but it will 追加する "And please see what is 利用できる on port 81" to the request.

On many servers, nothing will be 利用できる on port 81. When I tried...

http://bbc.co.uk:81/

...I was told "Firefox can't 設立する a 関係 to the server at bbc.co.uk:81"

Fair enough. No 推論する/理由 for the BBC to 申し込む/申し出 us a second treasure trove of good web pages 経由で a second port.

However, for me, with my 選び出す/独身 外部の IP 演説(する)/住所 and a want to put two servers online, ports were the answer.

Have a think... what needs to be tweaked to make it all work? We want the computer on 192.168.0.251 to serve all requests for the FarWatch server, and the Arduino, on 192.168.0.254 to 扱う the requests for the ArduServer. Who 'ya gonna call??

(answer その上の 負かす/撃墜する page....)




Have you thought about it?




....




Come on! What's your answer?




I've given you several 手がかり(を与える)s. Answer coming up... don't scroll 負かす/撃墜する until you've でっちあげる,人を罪に陥れるd your own answer.




....




Did you say the 魔法 is in the router? 井戸/弁護士席 done you, if so!

The 詳細(に述べる)s of how you say "Send any http traffic for port 81 to 地元の computer 192.168.0.254" 変化させる from router to router, of course. You don't need to 利用する the unnecessarily powerful "非武装地帯" features of some routers. You don't need to get into the 複雑化s of VPNs. What you want to do isn't ロケット/急騰する science. Beware: Your anti-malware system may baulk at sending things to a 非,不,無-基準 port until you tell the system that you don't mind.



Finally, because you've been good, I have put the 十分な code for the ArduServer2, the 装置 現在のd in this tutorial, on a separate page for you.

That is the sourcecode for setting up a server in an Arduino connected to a "new" (at 7/11) Arduino Ethernet 保護物,者, one of the ones based on the W5100 Ethernet 監査役.

This code will be moved to a page with a discussion of it's 明確な/細部s in 予定 course. For now, here it is, even if it isn't in the 権利 place, or explained in 詳細(に述べる). All of the above is explanation of what is in that code.

(I 申し込む/申し出 a page about choosing and connecting light level sensors, if you want help with that.)



I hope that was useful...

I hope that was useful. Please let me know if there are areas where you are "stuck"... at least "stuck" at the "what is the question?" 行う/開催する/段階. For 詳細(に述べる)s of Making It Work, if you are an Arduino 使用者, I have other pages for you. If you work with a different microprocessor, you will need to turn to your own community for 明確な/細部s.

Please remember that the (警察などへの)密告,告訴(状) here is 完全に 非公式の.




Search for other things...


Please 公式文書,認める that I have two other 場所/位置s, and that the に引き続いて search will not 含む them. They have their own search buttons.

My Sheepdog Guides 場所/位置.
My Arunet 場所/位置.

   Search this 場所/位置 or the web        力/強力にするd by FreeFind
 
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search
The search engine 単に looks for the words you type, so....
*    (一定の)期間 them 適切に.
*    Don't bother with "How do I get rich?" That will 単に return pages with "how", "do", "I"....

You can also search this 場所/位置 without using forms.
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.


Want a 場所/位置 hosted, or email? You can also help me if you 調印する up 経由で this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their 顧客s, but yes, they do 支払う/賃金 me if you use this link! As do the Google advertisers, about whom I know nothing, of course.)



Valid HTML 4.01 Transitional Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org

CSS behind the page checked, at least once upon a time!, with http://jigsaw.w3.org/css-validator/
Why does this page 原因(となる) a script to run? Because of the Google パネル盤s, and the code for the search button. Also, I have some of my pages' traffic 監視するd for me by eXTReMe tracker. They 申し込む/申し出 a 解放する/自由な tracker. If you want to try one, check out their 場所/位置. Why do I について言及する the script? Be sure you know all you need to about spyware.


Editor's Main Homepage
How to email or 令状 this page's editor, Tom Boyd

....... P a g e . . . E n d s .....