|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  AutoIt (Programación) Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  Teleco - Emisora de A.M. Visual Basic Cosas de Windows Webs interesantes
T Búsqueda en este sitio:


.

Arduino en español
Circuitos con Arduino - Juan Antonio Villalpando

-- Tutorial de iniciación a Arduino --

Volver al índice del tutorial

____________________________

104.- Arduino Shield Yun. HttpClient


_____________________________________________________
Vamos a cargar programas con el Bridge.

- HttpClient

- Estoy utilizando: IDE 1.6.7, Arduino UNO chino con CH340, Shield Yun Iduino.

- Fíjate que el Sketch se carga por Wifi, no por USB.
(Con el Leonardo o con el Arduino Yun en placa, también se puede cargar por USB)

- Cargamos el HttpClient
- Lo podemos encontrar en Archivo / Ejemplos / Bridge / HttpClient

- He modificado el original, en vez de Serial Monitor normal, he cambiado a Console que es como el Serial Monitor pero controlado por el Bridge. Por eso el comando es Console en vez de ser Serial.

- Conecta con una web y baja un archivo de texto.

- Es decir, si podemos conectarlo al USB porque tenemos el Leonardo con el Shield Yun o el Arduino Yún, podemos utilizar el Serial, ya que se puede comunicar con el Serial por el controlador USB.

- Pero si tenemos un Shield con Arduino UNO o Mega, debemos desconectar el controlador USB, ahora la comunicación con el Serial Monitor se haría por la Console.

/*
  Yún HTTP Client

 This example for the Arduino Yún shows how create a basic
 HTTP client that connects to the internet and downloads
 content. In this case, you'll connect to the Arduino
 website and download a version of the logo as ASCII text.

 created by Tom igoe
 May 2013

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/HttpClient

 */

#include <Bridge.h>
#include <HttpClient.h>
#include <Console.h>

void setup() {
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);
  Console.begin();

  // Serial.begin(9600);

  while (!Console); // wait for a serial connection
}

void loop() {
  // Initialize the client library
  HttpClient client;

  // Make a HTTP request:
  client.get("http://www.arduino.cc/asciilogo.txt");

  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Console.print(c);
  }
  Console.flush();

  delay(5000);
}

      

 

____________________________________________
____________________________________________

- ShellCommands

- Cargamos el ShellCommands
- Lo podemos encontrar en Archivo / Ejemplos / Bridge / ShellCommands

- En este caso se trata de ejecutar comandos de LINUX.

- Se ejecuta pretty-wifi-info.lua

- y se extrae Signal

- Se obtendrá en nivel de señal wifi mapeado entre 0 y 100. Además si ponemos un LED en el terminal 9 se encenderá con cierta intensidad.

- Los números aparecen muy lentamente, déjalo un buen rato.

- He modificado este Sketch para que pueda verse en el Serial Terminal, por eso he cambiado el Serial por el Console.

/*
  Running shell commands using Process class.

 This sketch demonstrate how to run linux shell commands
 using an Arduino Yún. It runs the wifiCheck script on the Linux side
 of the Yún, then uses grep to get just the signal strength line.
 Then it uses parseInt() to read the wifi signal strength as an integer,
 and finally uses that number to fade an LED using analogWrite().

 The circuit:
 * Arduino Yún with LED connected to pin 9

 created 12 Jun 2013
 by Cristian Maglie
 modified 25 June 2013
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/ShellCommands

 */

#include <Process.h>
#include <Console.h>

void setup() {
  Bridge.begin();  // Initialize the Bridge
 // Serial.begin(9600); // Initialize the Serial
  Console.begin();

  // Wait until a Serial Monitor is connected.
  while (!Console);
}

void loop() {
  Process p;
  // This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then
  // sends the result to the grep command to look for a line containing the word
  // "Signal:"  the result is passed to this sketch:
  p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal");

  // do nothing until the process finishes, so you get the whole output:
  while (p.running());

  // Read command output. runShellCommand() should have passed "Signal: xx&":
  while (p.available()) {
    int result = p.parseInt();      // look for an integer
    int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255
    analogWrite(9, signal);     // set the brightness of LED on pin 9
    Console.println(result);      // print the number as well
  }
  delay(5000);  // wait 5 seconds before you do it again
}

____________________________________________
____________________________________________

- TimeCheck

/*
  Time Check

 Gets the time from Linux via Bridge then parses out hours,
 minutes and seconds for the Arduino using an Arduino Yún.

 created  27 May 2013
 modified 21 June 2013
 By Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/TimeCheck

 */


#include <Process.h>
#include <Console.h>

Process date;                 // process used to get the date
int hours, minutes, seconds;  // for the results
int lastSecond = -1;          // need an impossible value for comparison

void setup() {
  Bridge.begin();        // initialize Bridge
  // Serial.begin(9600);    // initialize serial
    Console.begin();
  while (!Console);              // wait for Serial Monitor to open
  Console.println("Time Check");  // Title of sketch

  // run an initial date process. Should return:
  // hh:mm:ss :
  if (!date.running()) {
    date.begin("date");
    date.addParameter("+%T");
    date.run();
  }
}

void loop() {

  if (lastSecond != seconds) { // if a second has passed
    // print the time:
    if (hours <= 9) {
      Console.print("0");  // adjust for 0-9
    }
    Console.print(hours);
    Console.print(":");
    if (minutes <= 9) {
      Console.print("0");  // adjust for 0-9
    }
    Console.print(minutes);
    Console.print(":");
    if (seconds <= 9) {
      Console.print("0");  // adjust for 0-9
    }
    Console.println(seconds);

    // restart the date process:
    if (!date.running()) {
      date.begin("date");
      date.addParameter("+%T");
      date.run();
    }
  }

  //if there's a result from the date process, parse it:
  while (date.available() > 0) {
    // get the result of the date process (should be hh:mm:ss):
    String timeString = date.readString();

    // find the colons:
    int firstColon = timeString.indexOf(":");
    int secondColon = timeString.lastIndexOf(":");

    // get the substrings for hour, minute second:
    String hourString = timeString.substring(0, firstColon);
    String minString = timeString.substring(firstColon + 1, secondColon);
    String secString = timeString.substring(secondColon + 1);

    // convert to ints,saving the previous second:
    hours = hourString.toInt();
    minutes = minString.toInt();
    lastSecond = seconds;          // save to do a time comparison
    seconds = secString.toInt();
  }

}

____________________________________________
____________________________________________

- WifiStatus

- Arduino UNO chino con las R8 y R9 puestas. Shield Iduino. Wifi.

- Cable USB conectado del Arduino UNO al ordenador.

- Para cargar el Sketch al Arduino marcamos el Bridge iduino at 192.168.1.5 (Arduino Yun)

- Luego para ver la información en el Serial Monitor marcamos el COM21 correspondiente a la conexión USB.

- He cambiado el Serial.Begin(250000). Cámbialo en el Serial Monitor.

/*
  WiFi Status

 This sketch runs a script called "pretty-wifi-info.lua"
 installed on your Yún in folder /usr/bin.
 It prints information about the status of your wifi connection.

 It uses Serial to print, so you need to connect your Yún to your
 computer using a USB cable and select the appropriate port from
 the Port menu

 created  18 June 2013
 By Federico Fissore

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/YunWiFiStatus

 */

#include <Process.h>

void setup() {
  Serial.begin(250000);  // initialize serial communication
  while (!Serial);     // do nothing until the serial monitor is opened

  Serial.println("Starting bridge...\n");
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();  // make contact with the linux processor
  digitalWrite(13, HIGH);  // Led on pin 13 turns on when the bridge is ready

  delay(2000);  // wait 2 seconds
}

void loop() {
  Process wifiCheck;  // initialize a new process

  wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");  // command you want to run

  // while there's any characters coming back from the
  // process, print them to the serial monitor:
  while (wifiCheck.available() > 0) {
    char c = wifiCheck.read();
    Serial.print(c);
  }

  Serial.println();

  delay(5000);
}

 

 

 

 

 

Estaba desmarcado, he marcado Bridge interfaces.
________________________________

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información