public void Initialize(WirelessInfo info)
 {
     if (info.Security.ToLower().Contains("psk")) {
         labelTitle.LabelProp = "Enter Passphrase for " + info.ESSID;
         entryField = 1;
         labelUser.Visible = false;
         entryUser.Visible = false;
         labelPass.Visible = true;
         labelPass.LabelProp = "Phrase";
         entryPassword.Visible = true;
     } else {
         labelTitle.LabelProp = "Enter User and Password for " + info.ESSID;
         entryField = 0;
         labelUser.Visible = true;
         labelUser.LabelProp = "User";
         entryUser.Visible = true;
         labelPass.Visible = true;
         labelPass.LabelProp = "Pass";
         entryPassword.Visible = true;
     }
 }
        protected void UpdateNetworkInfo(object sender)
        {
            try {

                List<WirelessInfo> infoList = wireless.ConnectionStatus();
                WirelessInfo connect = null;
                foreach (WirelessInfo test in infoList) {
                    if (test.Active) {
                        connect = test;
                        break;
                    }
                }
                WiFi = connect;

                IpAddress = IpAddressWrapper.QueryIpAddress();

                if (timer != null) timer.Change(4000, -1);

            } catch (Exception ex) {
                Console.WriteLine("UpdateNetworkInfo: " + ex.ToString());
            }
        }
 public void Connect(WirelessInfo wireless)
 {
     if (Status != null) {
         Status(this, "Connect to " + wireless.ESSID + " (" + wireless.BSSID + ")");
     }
     List<string> body = readConnectionInfo();
     body = removeConnection(body, wireless);
     if (wireless.Encryption) {
         if (wireless.Security.ToLower().Contains("802.1x")) {
             appendLeap(body, wireless);
         } else if (wireless.Security.ToLower().Contains("psk")) {
             appendWpa(body, wireless);
         } else {
             if (Status != null) {
                 Status(this, "Unknown security: " + wireless.Security);
             }
         }
     } else {
         appendNone(body, wireless);
     }
     writeConnectionInfo(body);
     Restart();
 }
 private List<string> removeConnection(List<string> body, WirelessInfo wireless)
 {
     List<string> result = new List<string>();
     bool found = false;
     foreach (string line in body) {
         if (line.StartsWith("[")) {
             if (Status != null) {
                 Status(this, "Compare " + line + " to [" + wireless.BSSID + "]");
             }
             found = (line == "[" + wireless.BSSID + "]");
             if (Status != null) {
                 Status(this, "Remove old connection to " + wireless.ESSID + " (" + wireless.BSSID + ")");
             }
         }
         if (!found) {
             result.Add(line);
         }
     }
     return result;
 }
 private void appendWpa(List<string> body, WirelessInfo info)
 {
     body.Add("[" + info.BSSID + "]");
     body.Add("dhcphostname = beaglebone");
     body.Add("bssid = " + info.BSSID);
     body.Add("ip = None");
     body.Add("dns_domain = None");
     body.Add("gateway = None");
     body.Add("use_global_dns = 0");
     body.Add("encryption = True");
     body.Add("hidden = False");
     body.Add("channel = " + info.Channel);
     body.Add("mode = Master");
     body.Add("netmask = None");
     body.Add("key = " + info.Password);
     body.Add("usedhcphostname = 0");
     body.Add("enctype = wpa");
     body.Add("dns3 = None");
     body.Add("dns2 = None");
     body.Add("dns1 = None");
     body.Add("use_settings_globally = 0");
     body.Add("use_static_dns = 0");
     body.Add("encryption_method = WPA2");
     body.Add("essid = " + info.ESSID);
     body.Add("automatic = 1");
     body.Add("search_domain = None");
     body.Add("beforescript = None");
     body.Add("afterscript = None");
     body.Add("predisconnectscript = None");
     body.Add("postdisconnectscript = None");
 }
Example #6
0
	protected void backgroundTick (object sender) {
		Gtk.Application.Invoke(delegate {

			try {

				string test = "";
				if (recognizer.TimeRecognized != DateTime.MinValue) {
					test = recognizer.TimeRecognized.ToShortTimeString() + ": " + recognizer.KeywordRecognized;
				}
				if (test != lastRecognized || 
					recognizer.Noise != lastNoise || 
					recognizer.BufferSize != lastBuffer ||
					status != lastStatus) {
					drawWiFi.QueueDraw();
				}

				activeConnection = network.WiFi;
				ipAddress = network.IpAddress;

				if (prevIpAddress != ipAddress) {
					Console.WriteLine("IP Address changed to " + ipAddress);
					drawWiFi.QueueDraw();
				}
				prevIpAddress = ipAddress;

				if (ipAddress != "") {
					if (DateTime.Now.Subtract(weatherview.Weather.LastSuccess).TotalHours > 4) {
						weatherview.UpdateWeather();
					}
				}

				if (intercomView.IsBusy) {
					ChangeTab(4);
					stationIndex = 0;
					station = null;
				}

				if (recognizer.Status == "Ready" && station != null && playingStation == null) {
					if (ipAddress.Length > 0) {
						status = "Radio " + station.CallLetters;
						Console.WriteLine("Start playing radio station " + station.CallLetters);
						radio.Start(station.Url);
						playingStation = station;
					}
				} else if (playingStation != null && playingStation != station) {
					Console.WriteLine("Start playing radio station " + playingStation.CallLetters);
					radio.Stop();
					playingStation = null;
					findArtwork.Artwork = null;
					artist = "";
					song = "";
					status = "";
					ctlDrawingMeta.QueueDraw();
				} else if (recognizer.Status == "Ready" && !isAlarmActive && station == null && playingStation == null && !intercomView.IsBusy) {
					Console.WriteLine("Recognizer is ready and idle - start listening");
					recognizer.StartListening();
				} else if (recognizer.Status != "Ready" && (station != null || isAlarmActive || intercomView.IsBusy)) {
					recognizer.StopListening();
				}

				if (DateTime.Now > DateTime.Parse("08/01/2015")) {

					analogclock.AutoUpdate = true;

					if (lastMinute != DateTime.Now.Minute) {
						lastMinute = DateTime.Now.Minute;

						List<AlarmItem> alarms = clockAlarms.FindOn(DateTime.Now);
						activeAlarm = "";
						foreach (AlarmItem item in alarms) {
							activeAlarm += item.Name + " ";
						}
						if (alarms.Count > 0) {
							isAlarmActive = true;
							recognizer.StopListening();
							volumeService.SetUserLedBrightness(100);
							LightsOn();
							foreach (AlarmItem item in alarms) {
								ProcessActions(item.OnActions);
							}
							volumeService.SetUserLedBrightness(0);
							isAlarmActive = false;
						}

						alarms = clockAlarms.FindOff(DateTime.Now);
						activeAlarm = "";
						foreach (AlarmItem item in alarms) {
							activeAlarm += item.Name + " ";
						}
						if (alarms.Count > 0) {
							isAlarmActive = true;
							recognizer.StopListening();
							volumeService.SetUserLedBrightness(100);
							foreach (AlarmItem item in alarms) {
								ProcessActions(item.OffActions);
							}
							volumeService.SetUserLedBrightness(0);
							isAlarmActive = false;
						}

						nextAlarm = "";
						DateTime nextTime = clockAlarms.NextActiveAlarm();
						if (nextTime != DateTime.MaxValue) {
							nextAlarm = nextTime.ToShortDateString() + " " + nextTime.ToShortTimeString() + ":";
							alarms = clockAlarms.FindOn(nextTime);
							foreach (AlarmItem item in alarms) {
								nextAlarm += " " + item.Name;
							}
						}
					}
				}


			} catch (Exception ex) {
				Console.WriteLine(ex.Source);
				Console.WriteLine(ex.StackTrace);
			}
		});
	}