background image

[Get Code]

 

Instantiate a server enabling the the Yun to listen for connected clients.  

YunServer server;

  

In 

setup()

, start serial communication for debugging purposes, and turn the built-in LED on pin 

13 high while Bridge begins. 

Bridge.begin()

 is blocking, and should take about 2 seconds to 

complete. Once Bridge starts up, turn the LED off.  

void setup() { 
  Serial.begin(9600); 
  pinMode(13,OUTPUT); 
  digitalWrite(13, LOW); 
  Bridge.begin(); 
  digitalWrite(13, HIGH); 

[Get Code]

 

In the second part of 

setup()

, tell the instance of YunServer to listen for incoming connections 

only coming from localhost. Connections made to Linino will be passed to the 32U4 processor 
for parsing and controlling the pins. This happens on port 5555. Start the server with 

server.begin()

.  

server.listenOnLocalhost(); 
  server.begin(); 

[Get Code]

 

In 

loop()

, you'll create an instance of the YunClient for managing the connection. If the client 

connects, process the requests in a custom function (described below) and close the connection 
when finished.  

Putting a delay at the end of 

loop()

 will be helpful in keeping the processor from doing too 

much work.  

void loop() { 
  YunClient client = server.accept(); 
 
  if (client) { 
    process(client); 
    client.stop(); 
  } 
 
  delay(50);  

[Get Code]

 

Create a function named 

process

 that accepts the YunClient as its argument. Read the command 

by creating a string to hold the incoming information. Parse the REST commands by their 
functionality (digital, analog, and mode) and pass the information to the appropriately named 
function.  

Summary of Contents for Yun

Page 1: ...ta to the board When programming the Y n you must choose Arduino Y n from the Tools Board menu in the Arduino IDE The Y n is only supported by Arduino IDE 1 5 4 and later Differences from the Arduino...

Page 2: ...you power your Y n with more than 5V you will likely damage it If you are not powering the Y n from the micro USB connection you can apply power to the Vin and 5V pins on the board It is recommended t...

Page 3: ...There are several status LEDs on the Y n indicating power WLAN connection WAN connection and USB Additionally pin 13 is connected to one of the status lights Linino...

Page 4: ...ons or scripts For more on Python visit the Python 2 7 documentation pages If you re getting started with Python for the first time there are a number of excellent resources on line Learn Python the H...

Page 5: ...by pressing the Wifi reset button for longer longer than 5 seconds but less than 30 the AR9331 processor will reboot The WiFi configuration will be reset and the Y n will start its own wiFi network Ar...

Page 6: ...This means that if you re using any Serial or Console print println or write statements in setup they won t show up when you open the serial monitor or Console connection To work around this you can c...

Page 7: ...nloa Once yo comes with ad Arduino u ve read th an installer IDE 1 5 4 i he license a r for the IDE installer or l and if you ag E and driver later and do gree with it rs ouble click click the the ins...

Page 8: ...By default all available components are selected These include the IDE drivers and shortcuts Select the location you wish to install the IDE...

Page 9: ...The installer will display its progress as it extracts the files to the proper locations if you chose to install the drivers a pop up window will confirm your selection...

Page 10: ...ng blocked by a firewall Configuring the onboard WiFi The Y n has the ability to act as an Access Point but it can also connect to an existing network These instructions walk you through connecting yo...

Page 11: ...will find a page with some diagnostic information about the current network connections The first is your WiFi interface the second is your ethernet connection Press the Configuration button to proce...

Page 12: ...of 8 or more characters for your Arduino If you leave this field blank the system retains the default password of arduino If you wish you can set the timezone and country It is recommended to set thes...

Page 13: ...When you press the Configure Restart button the Arduino will reset itself and join the specified network The Arduino network will shut down after a few moments...

Page 14: ...ation screen Once the program is uploaded the 32U4 processor will restart You should see the LED connected to pin 13 blinking Using the onboard Ethernet When you connect the Yun to a wired network wit...

Page 15: ...wirelessly It creates a secure connection between the Y n and your computer via SSH Load the following onto your Y n include Console h const int ledPin 13 the pin that the LED is attached to int incom...

Page 16: ...see the Console by opening a terminal window and typing ssh root yourYunsName local telnet localhost 6571 then pressing enter NB If you are using Windows you must install a terminal emulator PuTTY is...

Page 17: ...the board through REST calls It demonstrates how you can create your own API when using REST style calls through the browser When running this example make sure your computer is on the same network a...

Page 18: ...or for parsing and controlling the pins This happens on port 5555 Start the server with server begin server listenOnLocalhost server begin Get Code In loop you ll create an instance of the YunClient f...

Page 19: ...following This value will assign a value to the pin turning it HIGH or LOW If there is no trailing read the value from the specified pin pin client parseInt if client read value client parseInt digit...

Page 20: ...D client print pin client print F set to analog client println value String key D key pin Bridge put key String value else value analogRead pin client print F Pin A client print pin client print F re...

Page 21: ...ode client readStringUntil r if mode input pinMode pin INPUT Send feedback to client client print F Pin D client print pin client print F configured as INPUT return if mode output pinMode pin OUTPUT S...

Page 22: ...r model and uses WebSockets to communicate between the two It runs a custom webserver on the Y n in python that allows for easy communication There are a number of examples for Spacebrew on the Y n in...

Reviews: