public static void Main() { var networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0]; if (!networkInterface.IsDhcpEnabled || !networkInterface.IsDynamicDnsEnabled) { networkInterface.EnableDhcp(); networkInterface.EnableDynamicDns(); networkInterface.RenewDhcpLease(); Debug.Print("Interface set to " + networkInterface.IPAddress); } if (DateTime.Now < new DateTime(2012, 01, 01)) { var networkTime = NtpClient.GetNetworkTime(); Utility.SetLocalTime(networkTime); } var queueTests = new QueueTests(AccountName, AccountKey); queueTests.Run(); var tableTests = new TableTests(AccountName, AccountKey); tableTests.Run(); }
private void timer_syncNetworkTime_Elapsed(object sender, EventArgs e) { try { DateTime gottonNetworkTime = NtpClient.GetNetworkTime(); // Success get Network time, assign to ProgramData.CurrentNetworkTime ProgramData.CurrentNetworkTime = gottonNetworkTime; // Sync network time per 5 mins _timerSyncNetworkTime.Interval = 300000; } catch (Exception ex) { Debug.Print(ex.Message); // Sync fail, try again after 5 seconds later _timerSyncNetworkTime.Interval = 5000; } finally { // For Debugger Debug.Print(DateTime.Now.ToLongTimeString() + "- Sync network time."); } }
public static void Main() { var mode = SharksLaserPlayerMode.AustinWithSharkWithAFreakinLaserOnSameFreakinDevice; //retrive and set device time via NTP if current value is shipdate (in 2011) if (DateTime.Now < new DateTime(2012, 01, 01)) { var networkTime = NtpClient.GetNetworkTime(); Utility.SetLocalTime(networkTime); } var queueClient = new QueueClient("netmf", "UstPuYqYwj1EEIc815wcVxV6oItRmrvRVByl7A152XoVeDJMr7vn1cahO5xXg0q8z5rSjd6SmQRWJliGQH9j0Q=="); _ledStrip = new LEDStripSpi(); _ledStrip.Initialize(); if (mode == SharksLaserPlayerMode.Austin) { GuyInTuxedo austin = new GuyInTuxedo(queueClient); Timer healingMojo = new Timer(austin.Heal, 4, 0, 1000);//austin's mojo heals him 4 points a second. groovy baby. while (true) { austin.GetDamage(); Debug.Print("How's austin feeling? : " + austin.HitPoints); UpdateLEDStrip(austin.HitPoints); } } else if (mode == SharksLaserPlayerMode.SharkWithAFreakinLaser) { SharkWithAFreakinLaser drEvilsBirthdayPresent = new SharkWithAFreakinLaser(queueClient); while (true) { drEvilsBirthdayPresent.ZAP(); drEvilsBirthdayPresent.CHOMP(); } } else if (mode == SharksLaserPlayerMode.AustinWithSharkWithAFreakinLaserOnSameFreakinDevice) { GuyInTuxedo austin = new GuyInTuxedo(queueClient); SharkWithAFreakinLaser drEvilsBirthdayPresent = new SharkWithAFreakinLaser(queueClient); Timer healingMojo = new Timer(austin.Heal, healLevel, 0, 1000); //austin's mojo heals him 1 point a second. groovy baby. Timer damageRetriever = new Timer(austin.GetDamage, null, 0, 1000); //austin pats himself down every second. while (true) { Debug.Print("How's austin feeling? : " + austin.HitPoints); UpdateLEDStrip(austin.HitPoints); drEvilsBirthdayPresent.ZAP(); Debug.Print("How's austin feeling? : " + austin.HitPoints); UpdateLEDStrip(austin.HitPoints); drEvilsBirthdayPresent.CHOMP(); healingMojo = AdjustHealingEquilibrium(austin, healingMojo); } } }
public static void Main() { //tidy up File.Delete("\\SD\\Data.csv"); try { //retrive and set device time via NTP var networkTime = NtpClient.GetNetworkTime(); Utility.SetLocalTime(networkTime); _macAddress = GetMAC(); _blobClient = new BlobClient(AccountName, AccountKey); _tableClient = new TableClient(AccountName, AccountKey); _tableClient.CreateTable("netmfdata"); _onBoardButton = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh); _onBoardButton.OnInterrupt += onBoardButton_OnInterrupt; _analogInput = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); } catch (Exception ex) { Debug.Print("Error setting up Device: " + ex.ToString()); } int counter = 0; while (true) { counter++; var data = _analogInput.Read() * 40D; _tableClient.AddTableEntityForTemperature("netmfdata", _macAddress, counter.ToString(), DateTime.Now, data, "UK"); lock (Padlock) { using (FileStream fs = File.Open("\\SD\\Data.csv", FileMode.Append, FileAccess.Write)) { Debug.Print(data.ToString()); var dataBytes = Encoding.UTF8.GetBytes( StringUtility.Format("{0}, {1}, {2}\r\n", _macAddress, DateTime.Now.ToString(), data) ); fs.Write(dataBytes, 0, dataBytes.Length); fs.Flush(); } } Thread.Sleep(1000); Debug.Print("Working"); } }
public static void SetupDefault() { NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0]; if (!networkInterface.IsDhcpEnabled || !networkInterface.IsDynamicDnsEnabled) { networkInterface.EnableDhcp(); networkInterface.EnableDynamicDns(); networkInterface.RenewDhcpLease(); Debug.Print("Interface set to " + networkInterface.IPAddress); } if (DateTime.Now < new DateTime(2012, 01, 01)) { var networkTime = NtpClient.GetNetworkTime(); Utility.SetLocalTime(networkTime); } }
static bool status = false; // on board led status public static void Main() { TimeSpan elapsed = TimeSpan.Zero; // Try to get clock at system start try { var time = NtpClient.GetNetworkTime(); Utility.SetLocalTime(time); } catch (Exception ex) { // Don't depend on time Debug.Print("Error setting clock: " + ex.Message); } // On board led OutputPort onBoardLed = new OutputPort(Pins.ONBOARD_LED, false); Thread.Sleep(1000); // Web Server ServerConfiguration = new Configuration(80); ServerCredential = new Credential("Administrator", "admin", "admin"); Server = new HttpServer(ServerConfiguration, ServerCredential, @"\SD\"); Server.OnServerError += new OnServerErrorDelegate(Server_OnServerError); Server.OnRequestReceived += new OnRequestReceivedDelegate(Server_OnRequestReceived); Server.Start(); // File Server FileServer server = new FileServer(@"\SD\", 1554); while (true) { // null task onBoardLed.Write(status); Thread.Sleep(500); } }
public static void Main() { TimeCounter timeCounter = new TimeCounter(); TimeSpan elapsed = TimeSpan.Zero; int i = 0; // Try to get clock at system start try { var time = NtpClient.GetNetworkTime(); Utility.SetLocalTime(time); } catch (Exception ex) { // Don't depend on time Debug.Print("Error setting clock: " + ex.Message); } // On board led OutputPort onBoardLed = new OutputPort(Pins.ONBOARD_LED, false); // Humidity and Temperature Sensor = new Dht22Sensor(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, PullUpResistor.Internal); //IRRX: Infrared Decoder NecProtocolDecoder decoder = new NecProtocolDecoder(Pins.GPIO_PIN_D7); NecProtocolDecoder.OnIRCommandReceived += NecDecoder_OnIRCommandReceived; //IRTX: Infrared Encoder IRCodec1 = new InfraredCodecNEC(new InfraredTransmitter(Pins.GPIO_PIN_D8)); IRCodec2 = new InfraredCodecNEC(new InfraredTransmitter(Pins.GPIO_PIN_D9)); Thread.Sleep(1000); // Web Server ServerConfiguration = new Configuration(80); ServerCredential = new Credential("Administrator", "admin", "admin"); Server = new HttpServer(ServerConfiguration, ServerCredential, @"\SD\"); Server.OnServerError += new OnServerErrorDelegate(Server_OnServerError); Server.OnRequestReceived += new OnRequestReceivedDelegate(Server_OnRequestReceived); Server.Start(); // File Server FileServer server = new FileServer(@"\SD\", 1554); while (true) { timeCounter.Start(); { elapsed += timeCounter.Elapsed; if (elapsed.Seconds >= 1) { if (Sensor.Read()) { temperature = Sensor.Temperature; humidity = Sensor.Humidity; status = "DHT Sensor: RH = " + humidity.ToString("F1") + "% Temp = " + temperature.ToString("F1") + "°C "; } elapsed = TimeSpan.Zero; onBoardLed.Write((i++ & 0x01) == 0); // blink on board led #region nulltask //if ((i & 0x01) == 0) //{ // if ((i & 0x02) == 0) // { // IRCodec1.Send(0x00, 0x00); // } // else // { // IRCodec1.Send(0xFF, 0xFF); // } //} //else //{ // if ((i & 0x02) == 0) // { // IRCodec2.Send(0x00, 0x00); // } // else // { // IRCodec2.Send(0xFF, 0xFF); // } //} //if ((i & 0x01) == 0) //{ // if ((i & 0x02) == 0) // { // IRCodec1.Send(0x10, 0x0D); // } // else // { // IRCodec1.Send(0x10, 0x1F); // } //} //else //{ // if ((i & 0x02) == 0) // { // IRCodec2.Send(0x10, 0x03); // } // else // { // IRCodec2.Send(0x10, 0x02); // } //} //if ((i & 0x01) == 0) //{ // IRCodec1.Send(0x10, 0x0D); // IRCodec2.Send(0x10, 0x03); //} //else //{ // IRCodec1.Send(0x10, 0x1F); // IRCodec2.Send(0x10, 0x02); //} //string log = "DHT Sensor: RH = " + humidity.ToString("F1") + // "% Temp = " + temperature.ToString("F1") + "°C "; //Debug.Print(log); #endregion } } timeCounter.Stop(); } }