static void Main(string[] args) { SensorNodeDll.SensorNodeDll dll = new SensorNodeDll.SensorNodeDll(); m_cClient = new MqttClient(IPAddress.Parse("192.168.235.163")); //m_cClient = new MqttClient(IPAddress.Parse("127.0.0.1")); m_cClient.Connect(Guid.NewGuid().ToString()); if (!m_cClient.IsConnected) { Console.WriteLine("Error connecting to message broker..."); return; } dll.Initialize(recebeDados, 3000); Console.ReadKey(); if (m_cClient.IsConnected) { m_cClient.Disconnect(); } dll.Stop(); }
static void Main(string[] args) { m_cClient = new MqttClient("127.0.0.1"); string[] m_strTopicsInfo = { "sensors" }; m_cClient.Connect(Guid.NewGuid().ToString()); if (!m_cClient.IsConnected) { Console.WriteLine("Error connecting to message broker..."); return; } //if(m_cClient.IsConnected) //{ // m_cClient.Unsubscribe(m_strTopicsInfo); // m_cClient.Disconnect(); //} // In miliseconds int dataGenerationInterval = 5000; SensorNodeDll.SensorNodeDll dll = new SensorNodeDll.SensorNodeDll(); dll.Initialize(getData, dataGenerationInterval); Console.ReadKey(); }
static void Main(string[] args) { dll = new SensorNodeDll.SensorNodeDll(); connectToMessagingChannel(); dll.Initialize(getDataFromSensor, 2000); }
static void Main(string[] args) { try { dll = new SensorNodeDll.SensorNodeDll(); dll.Initialize(readDataFromDll, Properties.Settings.Default.Delay); m_cClient.Connect(Guid.NewGuid().ToString()); if (!m_cClient.IsConnected) { Console.WriteLine("Error connecting to message broker..."); return; } } catch (Exception e) { throw new Exception(e.Message); } }
static void Main(string[] args) { SensorNodeDll.SensorNodeDll dll = new SensorNodeDll.SensorNodeDll(); dll.Initialize(NewValue, Properties.Settings.Default.Delay); }
static void Main(string[] args) { SensorNodeDll.SensorNodeDll dll = new SensorNodeDll.SensorNodeDll(); dll.Initialize(DllValues, 5000); }
static void Main(string[] args) { bool aux_m_cClient = true; //MENU int option; int delay = SmartH2O_Data_Uploader.Properties.Settings.Default.sensorTime; do { Console.Clear(); Console.ForegroundColor = ConsoleColor.Yellow; Console.SetCursorPosition(20, 0); Console.WriteLine("Welcome To SmartH2O Data Uploader"); Console.SetCursorPosition(8, 1); Console.WriteLine("Developers: Joana Vilhena | Joel Rodrigues | Sergio Batista"); Console.ResetColor(); Console.WriteLine(); Console.Write("Please Enter Your Choice: \n\n 1. Start Application \n 2. Set Delay Time \n 3. Set IP for Broker \n 0. Exit \n "); Console.WriteLine("------------------"); option = Int32.Parse(Console.ReadLine()); switch (option) { case 1: { //escolho criar a dll aqui, porque depois de um stop ela nao volta a correr o metodo Initialize dll = new SensorNodeDll.SensorNodeDll(); Console.Clear(); try { string schemaPath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "App_data\\XMLSensorDataMsgSchema.xsd"; schema.Add("", schemaPath); } catch (Exception e) { Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("error loading schema"); Console.ReadKey(); Environment.Exit(1); } // tenho de verificar se o m_cClient já existe if (aux_m_cClient) { try { aux_m_cClient = false; m_cClient = new MqttClient(SmartH2O_Data_Uploader.Properties.Settings.Default.brokerIP); } catch (Exception e) { Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("error connecting with broker"); Console.ReadKey(); Environment.Exit(1); } } try { if (!m_cClient.IsConnected) { m_cClient.Connect(Guid.NewGuid().ToString()); } Console.WriteLine("Press ESC to quit\n---------------------------------"); auxFlag = false; m_cClient.MqttMsgPublished += m_cClient_MsgPublished; dll.Initialize(sendData, delay); do { //fica a escrever na janela até clicar na tecla ESC } while (Console.ReadKey(true).Key != ConsoleKey.Escape); dll.Stop(); auxFlag = true; } catch (Exception e) { Console.WriteLine("cannot send message"); Console.WriteLine(e); Console.ReadKey(); Environment.Exit(1); } m_cClient.MqttMsgPublished -= m_cClient_MsgPublished; Console.Clear(); } break; case 2: { Console.Clear(); //ponderar passar a mostrar valor em segundo e ler em segundos - tlv minutos! falar com colegas Console.WriteLine("Delay Time value (ms): " + delay.ToString()); Console.Write("\nSet new Delay time (ms): "); //verificar se o que foi escrito é numerico int value; string delayString = Console.ReadLine(); if (int.TryParse(delayString, out value)) { delay = Int32.Parse(delayString); } else { Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\n\n" + delayString + " is not a valid value"); Console.ResetColor(); Console.ReadKey(); } //guardar valor delay do ecra SmartH2O_Data_Uploader.Properties.Settings.Default.sensorTime = delay; SmartH2O_Data_Uploader.Properties.Settings.Default.Save(); } break; case 3: { Console.Clear(); Console.WriteLine("Brokers IP: " + SmartH2O_Data_Uploader.Properties.Settings.Default.brokerIP); Console.Write("\nSet the new IP for the Broker: "); string broker = Console.ReadLine(); if (ValidateIPv4(broker)) { if (!aux_m_cClient) { aux_m_cClient = true; if (m_cClient.IsConnected) { m_cClient.Disconnect(); } } SmartH2O_Data_Uploader.Properties.Settings.Default.brokerIP = broker; SmartH2O_Data_Uploader.Properties.Settings.Default.Save(); } else { Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\n\n" + broker + " is not a valid IP"); Console.ResetColor(); Console.ReadKey(); } } break; case 0: { Console.Clear(); Console.WriteLine("\nThank you for using our program"); Console.ReadKey(); //fazer uma mensagem para sair } break; } }while (option != 0); Environment.Exit(0); }