[转]Networking with the Arduino Yun

转自http://teachmetomake.com/wordpress/arduino-yun-networking


Arduino Yun for Intermediate Arduino Users:****Using the Onboard Linux Computer to Communicate with Other Computers and the Internet
http://teachmetomake.com/wordpress/arduino-yun-networking
Michael Shiloh****Arduino****m.shiloh@arduino.cc
Tutorial created for OSCON 20141:30pm Sunday, 07/20/2014Link on OSCON schedule
Contents [hide]
1 Please prepare for this tutorial before you arrive:
2 Arduino Yun Overview
3 Selected Yun details
4 Configuring your Yun over WiFi
5 Configuring your Yun over wired ethernet
6 Basic examples6.1 Bridge class
6.2 Process class
6.3 HttpClient class
6.4 Create a web server, and serve data from the IO pins
6.5 More on the Bridge library

7 Bidirectional Server Client exercise

Please prepare for this tutorial before you arrive:
Participants must be comfortable with the Arduino hardware and software, know how to attach sensors and LEDs to an Arduino, and know how to write programs for Arduino
An Arduino Yun, and an Arduino component kit (breadboard, wires, assorted sensors, LEDs, motors, speakers, etc.) is required in order to participate. We have sourced the kit and parts for you, and the cost of this kit is $93. There will be an additional charge of $93 when you register for this tutorial. You will be provided with the kit onsite at the conference with proof of registration.
Participants must have a laptop
Participants must install Arduino 1.6.4 or later from Arduino

Arduino Yun Overview


Selected Yun details
Linux distribution is OpenWrt, so almost anything that’s true for OpenWrt is true for the Yun. OpenWrt Technical Reference
Serial1 (pins 0 and 1) of Arduino environment is connected to console of the Linux environment and so can’t be used otherwise
No built in 5V regulator, so Vin must never be above 5V. 3.3V generated internally
Best to use microSD card or thumb drive for saving data, scripts, web pages, etc.
Individual resets for WiFi, Linux, 32U432U4 reset requires 2 clicks
WiFi 3 options<5 seconds: Restart WiFi

5 and <30: Reconfigure WiFi
30: Reset OpenWrt-Yun to default state

ResourcesArduino Yun product page
Arduino Yun Getting Started Guide
Excellent set of community curated Yun notes
The Bridge library reference

Configuring your Yun over WiFi
Connect:Yun to laptop with USB cable

Access the Linux console from the Serial Monitor by uploading the YunSerialTerminal example:File->Examples->Bridge->YunSerialTerminal
Remember to select “Yun” in “Tools->Board”.
In the following steps, all the lines you type are in the top line of the serial monitor.

Open your Serial Monitor and select New line line ending and 57600 baud (down near the bottom right corner). Put your cursor in the top line and press your <ENTER> key and you should see a prompt, and possibly a banner:BusyBox v1.19.4 (2014-07-14 20:05:06 CEST) built-in shell (ash)Enter 'help' for a list of built-in commands. _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -| || | | || || | |_______|| |_____||||________||| |____| |__| W I R E L E S S F R E E D O M -----------------------------------------------------root@Arduino:/#
Wait until you see the prompt:
root@Arduino:/#

Press and hold the button labelled “WLAN RST” for at least 30 seconds.
Watch the messages in the console and wait until it finishes booting. You will have to put your cursor in the top line and press enter again to see the prompt and the banner.
Verify that the Yun is now an access point by typing:iwconfig <ENTER>
You should see something like this:
o no wireless extensions.eth1 no wireless extensions.wlan0 IEEE 802.11bgn Mode:Master Tx-Power=16 dBm RTS thr:off Fragment thr:off Power Management:off eth0 no wireless extensions.
The important thing is that wlan0 is in “Master” mode.

Find your Yun’s MAC address by typing: ifconfig <ENTER>

Look for the line that says: wlan0 Link encap:Ethernet HWaddr 90:A2:DA:F3:02:19
the code following HWaddr is your Yun’s MAC address. In this case it’s
90A2DAF30219

Using your laptop’s network manager, connect to the network with a name like Arduino Yun-90A2DAF30219. If you see more than one Arduino Yun, look for the one with your Yun’s MAC address.
In your web browser, browse to http://arduino.local****
When asked, the password is ****arduino****
Congratulations! You are connected to your Yun

Configuring your Yun over wired ethernet
Connect:Yun to laptop with USB cable
Yun to network with Ethernet cable

Access the Linux console from the Serial Monitor using the YunSerialTerminal example:File->Examples->Bridge->YunSerialTerminal

Open your Serial Monitor and select New line line ending. Press enter and you should see a prompt, and possibly a banner:BusyBox v1.19.4 (2014-07-14 20:05:06 CEST) built-in shell (ash)Enter 'help' for a list of built-in commands. _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -| || | | || || | |_______|| |_____||||________||| |____| |__| W I R E L E S S F R E E D O M -----------------------------------------------------root@MShilohServer:~#

Get the IP address of the wired Ethernetifconfig
Look for the section that is NOT lo (loopback) and NOT wlan (wireless). It’s most likely eth1. Look for the line that starts with:
inet addr:192.168.1.145
Make note of this IP address as it is the way you will access your Yun

Open a web browser and browse to that IP address. Enter password (arduino), clickLOGIN, then click** **CONFIGURE****Change YUN NAME to e.g. YunMShiloh. I suggest you leave the password as is.
Deselect CONFIGURE in CONFIGURE A WIRELESS NETWORK(Wireless network does not allow peer-to-peer)****
At REST API ACCESS select Open
Click Configure and Restart (Might take a couple of minutes to reboot)
Close the browser window

Test by logging in to your Yun via ssh. (Linux: Terminal Mac: Applications -> Utilities -> Terminal. Windows: Download putty). Your user name is root. Accept key and enter your password:$ ssh root@192.168.1.145The authenticity of host '192.168.1.145 (192.168.1.145)' can't be established.RSA key fingerprint is 55:32:43:18:a6:99:99:55:96:74:dc:b5:3e:24:e2:14.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.1.145' (RSA) to the list of known hosts.root@192.168.1.145's password: BusyBox v1.19.4 (2014-07-14 20:05:06 CEST) built-in shell (ash)Enter 'help' for a list of built-in commands. _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -| || | | || || | |_______|| |_____||||________||| |____| |__| W I R E L E S S F R E E D O M -----------------------------------------------------root@MShilohServer:~#
Verify that the computer name is the one you set (in my case MShilohServer).

Test that you can see your neighbor’s Yun. Ask your neighbor for the IP address of their Yun, and then use ping to verify that you can see it: ping 192.168.1.107
To exit ping type <CTRL> C

Basic examples
BRIDGE CLASS
Read inputs and control outputs from a web browser. Upload this sketch:
File -> Examples -> Bridge -> Bridge
Control your pin 13 LED by visiting, with your browser, (replace IP address with yours):
http://192.168.1.145/arduino/digital/13/0orarduino.local/arduino/digital/13/0
Read an analog input by visiting:
http://192.168.1.145/arduino/analog/0orarduino.local/arduino/analog/0
More details in the bridge tutorial
Optional exercise: Add some LEDs and sensors, then read and control them from a web browser.
PROCESS CLASS
Execute commands on the Linux side, from a sketch.
File -> Examples -> Bridge -> Process
Process tutorial
HTTPCLIENT CLASS
Create an HTTP client that connects to the internet and downloads content.
File -> Examples -> Bridge -> HttpClient
HttpClient tutorial
CREATE A WEB SERVER, AND SERVE DATA FROM THE IO PINS
(requires microSD card)
File -> Examples -> Bridge -> TemperatureWebPanel
TemperatureWebPanel tutorial
MORE ON THE BRIDGE LIBRARY
Bridge library reference
Bridge tutorials: links under Bridge Libraries on the tutorial home page
Bidirectional Server Client exercise
Get code from github

Practical application
Either client or server can be replaced by process written in any other language, as long as it can open a connection to an arbitrary IP address and port
Netcat or nc
Wayne’s Android controller for an Arduino robot: Android code, Arduino code

Temboo
Create a Temboo account
Create an application name/key pair on Temboo
Create unimportant Gmail account
Open exampleFile -> Examples -> Bridge -> Temboo -> SendAnEmail

Enter Gmail account details and destination address in SendAnEmail sketch. Note that GMAIL_USER_NAME must be full email address e.g. bob@gmail.com
Click on second tab (TembooAccount.h)
Enter Temboo account and application name/key pair
Upload

Time Permitting
Adafruit tutorial
Spacebrew

Arduino Yun Kit of Parts
Cost: $93 (tax included)
1 Arduino Yun
1 USB cable
1 400 point breadboard
30 Jumper wires M-M
LED pack (3R, 3G, 3Y at 3mm and 3R, 3G at 5mm)
2 x 10K ohm trimmer potentiometers with knobs (breadboard mount)
10 x 470 ohm resistors
10 x 10K resistors
1 Light dependent resistor (CdS cell)
1 Thermistor
1 DHT11 temperature/humidity sensor (example)
1 Passive piezo element

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,033评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,725评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,473评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,846评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,848评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,691评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,053评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,700评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,856评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,676评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,787评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,430评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,034评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,990评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,218评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,174评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,526评论 2 343

推荐阅读更多精彩内容