mirror of https://github.com/noisymime/Arduino.git
delete OLDYahooWeather example
Updated pretty-wifi-info-lua path in ShellCommands and WifiStatus examples Tried to make a sense of HttpClient example by making it fetch http://arduino.cc/asciilogo.txt
This commit is contained in:
parent
0acfdbcb9c
commit
645a57359e
|
@ -5,17 +5,19 @@ void setup() {
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
digitalWrite(13, LOW);
|
digitalWrite(13, LOW);
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
Serial.begin(9600);
|
||||||
|
while(!Serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
client.get("http://my.server.address/file.php");
|
client.get("http://arduino.cc/asciilogo.txt");
|
||||||
|
|
||||||
char c = client.read();
|
while (client.available()) {
|
||||||
if (c=='1')
|
char c = client.read();
|
||||||
digitalWrite(13, HIGH);
|
Serial.print(c);
|
||||||
if (c=='0')
|
}
|
||||||
digitalWrite(13, LOW);
|
Serial.flush();
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
Yahoo Weather Forecast parser
|
|
||||||
|
|
||||||
http://developer.yahoo.com/weather/
|
|
||||||
This sketch demonstrate how to use the Linux command line tools
|
|
||||||
to parse a simple XML file on the Arduino Yún.
|
|
||||||
|
|
||||||
First thing download the XML file from the Yahoo Weather service
|
|
||||||
than use "grep" and "cut" to extract the data you want.
|
|
||||||
|
|
||||||
To find the location ID of your location, browse or search for your
|
|
||||||
city from the Weather home page. The location ID is in the URL for
|
|
||||||
the forecast page for that city.
|
|
||||||
|
|
||||||
created 21 Jun 2013
|
|
||||||
by Federico Vanzati
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <Bridge.h>
|
|
||||||
|
|
||||||
String locationID = "725003"; // Turin, Italy
|
|
||||||
|
|
||||||
// table with keywords to search in the XML file
|
|
||||||
// the third column is the tag to the field
|
|
||||||
String forecast[10][3] = {
|
|
||||||
"location", "2", "city",
|
|
||||||
"condition", "6", "temperature",
|
|
||||||
"condition", "2", "condition",
|
|
||||||
"astronomy", "2", "sunrise",
|
|
||||||
"astronomy", "4", "sunset",
|
|
||||||
"atmosphere", "2", "humidity",
|
|
||||||
"atmosphere", "6", "pressure",
|
|
||||||
"wind", "6", "wind speed",
|
|
||||||
"wind", "4", "wind direction",
|
|
||||||
"wind", "2", "chill temperature"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Bridge.begin();
|
|
||||||
Serial.begin(9600);
|
|
||||||
while(!Serial);
|
|
||||||
|
|
||||||
Serial.println("Weather Forecast for your location: \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
for(int i=0; i<10; i++) {
|
|
||||||
|
|
||||||
// Compose the request
|
|
||||||
|
|
||||||
// curl is a program that connect to an URL an download the content
|
|
||||||
// is used to get the weather forecast from yahoo in XML format
|
|
||||||
String command = "curl -s "; // -s is the silent option
|
|
||||||
command += "http://weather.yahooapis.com/forecastrss"; // yahoo weather RSS service
|
|
||||||
command += "?w="; // query for the location
|
|
||||||
command += locationID;
|
|
||||||
//command += "\\&u=c"; // ask for celsius degrees
|
|
||||||
|
|
||||||
// add a new process
|
|
||||||
// grep is used to extract a single line of content containig a search keyword form the XML
|
|
||||||
command += " | "; // pipe a new process
|
|
||||||
command += "grep ";
|
|
||||||
command += forecast[i][0]; // word to search in the XML file
|
|
||||||
|
|
||||||
// add a new process
|
|
||||||
// cut is a program that split a text in different fields
|
|
||||||
// when encouter the passed character delimiter
|
|
||||||
command += " | "; // pipe a new process
|
|
||||||
command += "cut ";
|
|
||||||
command += "-d \\\" "; // -d parameter split the string every " char
|
|
||||||
command += "-f "; // -f parameter is to return the 6th splitted element
|
|
||||||
command += forecast[i][1]; // the field are already manually calculated and inserted in the forecast table
|
|
||||||
|
|
||||||
|
|
||||||
Serial.print(forecast[i][2]);
|
|
||||||
Serial.print("= ");
|
|
||||||
|
|
||||||
// run the command
|
|
||||||
Process wf;
|
|
||||||
wf.runShellCommand(command);
|
|
||||||
|
|
||||||
while(wf.available()>0)
|
|
||||||
{
|
|
||||||
Serial.print( (char)wf.read() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//do nothing forevermore
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Running shell commands using Process class.
|
Running shell commands using Process class.
|
||||||
|
|
||||||
|
@ -32,10 +31,10 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Process p;
|
Process p;
|
||||||
// This command line runs the wifiCheck script, (lua /arduino/pretty...), then
|
// 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
|
// sends the result to the grep command to look for a line containing the word
|
||||||
// "Signal:" the result is passed to this sketch:
|
// "Signal:" the result is passed to this sketch:
|
||||||
p.runShellCommand("lua /arduino/pretty_wifi_info.lua | grep Signal");
|
p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal");
|
||||||
|
|
||||||
// do nothing until the process finishes, so you get the whole output:
|
// do nothing until the process finishes, so you get the whole output:
|
||||||
while(p.running());
|
while(p.running());
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
WiFi Status
|
WiFi Status
|
||||||
|
|
||||||
This sketch run a script already present on your Yún in the
|
This sketch run a script already present on your Yún in the
|
||||||
/arduino directory called "pretty_wifi_info.lua" that takes
|
/usr/bin directory called "pretty-wifi-info.lua" that takes
|
||||||
the informations of the WiFi interface and print it on the
|
the informations of the WiFi interface and print it on the
|
||||||
Serial monitor.
|
Serial monitor.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue