Skip to content
This repository was archived by the owner on Sep 30, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions examples/WifiConfig/WifiConfig.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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>
#include "credential.h"

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

SerialUSB.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
Serial.println("attempting to connect");
Bridge.wifiConfig(yunName, yunPsw, wifissid, wifipsw, wifiAPname, countryCode);
Serial.println("...");

}

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();
SerialUSB.print(c);
}

SerialUSB.println();

delay(5000);
}
6 changes: 6 additions & 0 deletions examples/WifiConfig/credential.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const String yunName="yourYunName";
const String yunPsw="yourYunPsw";
const String wifissid="yourWifiSSID";
const String wifipsw="yourWifiPSW";
const String wifiAPname="YUNAccessPointName"; //this is the name of the access point you want the yun to create if somethings goes wrong with the connection to the wifi
const String countryCode="yourcountrycode"; // for example IT DE US
28 changes: 28 additions & 0 deletions src/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,31 @@ SerialBridgeClass Bridge(Serial1);
SerialBridgeClass Bridge(Serial);
#endif

void BridgeClass::wifiConfig(String yunName, String yunPsw, String wifissid, String wifipsw, String wifiAPname, String countryCode){
Process p;

p.runShellCommand("blink-start 100"); //start the blue blink

p.runShellCommand("hostname " + yunName); //change the current hostname
p.runShellCommand("uci set system.@system[0].hostname='" + yunName + "'"); //change teh hostname in uci

p.runShellCommand("uci set arduino.@arduino[0].access_point_wifi_name='" + wifiAPname + "'");

//this block resets the wifi psw
p.runShellCommand("uci set wireless.@wifi-iface[0].encryption='psk2'");
p.runShellCommand("uci set wireless.@wifi-iface[0].mode='sta'");
p.runShellCommand("uci set wireless.@wifi-iface[0].ssid='" + wifissid + "'");
p.runShellCommand("uci set wireless.@wifi-iface[0].key='" + wifipsw + "'");
p.runShellCommand("uci set wireless.radio0.channel='auto'");
p.runShellCommand("uci set wireless.radio0.country='" + countryCode + "'");
p.runShellCommand("uci delete network.lan.ipaddr");
p.runShellCommand("uci delete network.lan.netmask");
p.runShellCommand("uci set network.lan.proto='dhcp'");

p.runShellCommand("echo -e \"" + yunPsw + "\n" + yunPsw + "\" | passwd root"); //change the passwors
p.runShellCommand("uci commit"); //save the mods done via UCI
p.runShellCommand("blink-stop"); //start the blue blink

p.runShellCommand("wifi ");

}
2 changes: 2 additions & 0 deletions src/Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class BridgeClass {

static const uint16_t TRANSFER_TIMEOUT = 0xFFFF;

void wifiConfig(String yunName, String yunPsw, String wifissid, String wifipsw, String wifiAPname, String countryCode);

private:
uint8_t index;
int timedRead(unsigned int timeout);
Expand Down