Uncategorised
- Details
- Written by Sonny Yu
Since Uno and Mega has no Serial, replace Serial with Console at Bridge Sample IDE code
/* 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 2024 By Federico Fissore This example code is in the public domain. http://www.arduino.cc/en/Tutorial/YunWiFiStatus To see the Console, pick your Yún's name and IP address in the Port menu then open the Port Monitor. You can also see it by opening a terminal window and typing ssh root@ yourYunsName.local 'telnet localhost 6571' then pressing enter. When prompted for the password, enter it. */ #include <Console.h> #include <Process.h> void setup() { //Serial.begin(9600); // 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 Console.begin(); while (!Console) { ; // wait for Console port to connect. } Console.println("Starting bridge...\n"); 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); Console.print(c); } //Serial.println(); Console.println(); delay(5000); }
Write comment (0 Comments)
- Details
- Written by Sonny Yu
Since Uno and Mega has no Serial, replace Serial with Console at Bridge Sample IDE code
/* 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 2024 modified 21 June 2024 By Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/TimeCheck To see the Console, pick your Yún's name and IP address in the Port menu then open the Port Monitor. You can also see it by opening a terminal window and typing ssh root@ yourYunsName.local 'telnet localhost 6571' then pressing enter. When prompted for the password, enter it. */ #include <Console.h> #include <Process.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 //while (!Serial); // wait for Serial Monitor to open //Serial.println("Time Check"); // Title of sketch Console.begin(); while (!Console) { ; // wait for Console port to connect. } Console.println("Time Check"); // 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) Serial.print("0"); // adjust for 0-9 Serial.print(hours); Serial.print(":"); if (minutes <= 9) Serial.print("0"); // adjust for 0-9 Serial.print(minutes); Serial.print(":"); if (seconds <= 9) Serial.print("0"); // adjust for 0-9 Serial.println(seconds); */ 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(); } }
Write comment (0 Comments)
- Details
- Written by Sonny Yu
Since Uno and Mega has no Serial, replace Serial with Console at Bridge Sample IDE code
/* 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 2024 by Cristian Maglie modified 25 June 2024 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ShellCommands To see the Console, pick your Yún's name and IP address in the Port menu then open the Port Monitor. You can also see it by opening a terminal window and typing ssh root@ yourYunsName.local 'telnet localhost 6571' then pressing enter. When prompted for the password, enter it. */ #include <Console.h> #include <Process.h> void setup() { Bridge.begin(); // Initialize the Bridge //Serial.begin(9600); // Initialize the Serial // Wait until a Serial Monitor is connected. //while (!Serial); Console.begin(); while (!Console) { ; // wait for Console port to connect. } } 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 // Serial.println(result); // print the number as well Console.println(result); } delay(5000); // wait 5 seconds before you do it again }
Write comment (0 Comments)
- Details
- Written by Sonny Yu
Since Uno and Mega has no Serial, replace Serial with Console at Bridge Sample IDE code
/* Write to file using FileIO classes. This sketch demonstrate how to write file into the Yún filesystem. A shell script file is created in /tmp, and it is executed afterwards. created 7 June 2024 by Cristian Maglie This example code is in the public domain. http://www.arduino.cc/en/Tutorial/FileWriteScript To see the Console, pick your Yún's name and IP address in the Port menu then open the Port Monitor. You can also see it by opening a terminal window and typing ssh root@ yourYunsName.local 'telnet localhost 6571' then pressing enter. When prompted for the password, enter it. */ #include <Console.h> #include <FileIO.h> void setup() { // Setup Bridge (needed every time we communicate with the Arduino Yún) Bridge.begin(); // Initialize the Serial //Serial.begin(9600); //while (!Serial); // wait for Serial port to connect. //Serial.println("File Write Script example\n\n"); Console.begin(); while (!Console) { ; // wait for Console port to connect. } Console.println("File Write Script example\n\n"); // Setup File IO FileSystem.begin(); // Upload script used to gain network statistics uploadScript(); } void loop() { // Run stats script every 5 secs. runScript(); delay(5000); } // this function creates a file into the linux processor that contains a shell script // to check the network traffic of the WiFi interface void uploadScript() { // Write our shell script in /tmp // Using /tmp stores the script in RAM this way we can preserve // the limited amount of FLASH erase/write cycles File script = FileSystem.open("/tmp/wlan-stats.sh", FILE_WRITE); // Shell script header script.print("#!/bin/sh\n"); // shell commands: // ifconfig: is a command line utility for controlling the network interfaces. // wlan0 is the interface we want to query // grep: search inside the output of the ifconfig command the "RX bytes" keyword // and extract the line that contains it script.print("ifconfig wlan0 | grep 'RX bytes'\n"); script.close(); // close the file // Make the script executable Process chmod; chmod.begin("chmod"); // chmod: change mode chmod.addParameter("+x"); // x stays for executable chmod.addParameter("/tmp/wlan-stats.sh"); // path to the file to make it executable chmod.run(); } // this function run the script and read the output data void runScript() { // Run the script and show results on the Serial Process myscript; myscript.begin("/tmp/wlan-stats.sh"); myscript.run(); String output = ""; // read the output of the script while (myscript.available()) { output += (char)myscript.read(); } // remove the blank spaces at the beginning and the ending of the string output.trim(); //Serial.println(output); //Serial.flush(); Console.println(output); Console.flush(); }
Write comment (0 Comments)
Page 6 of 16