/// <summary> /// Writes provided settings to the config file and invokes a reconfigure to the current mqqtClient /// </summary> /// <param name="settings"></param> public async void WriteMqttBrokerSettingsAsync(MqttSettings settings) { while (this._brokerSettingsFileLocked) { await Task.Delay(500); } this._brokerSettingsFileLocked = true; using (FileStream stream = new FileStream(Path.Combine(path, "mqttbroker.json"), FileMode.Open)) { stream.SetLength(0); Log.Logger.Information($"writing configured mqttbroker to: {stream.Name}"); ConfiguredMqttBroker configuredBroker = new ConfiguredMqttBroker() { Host = settings.Host, Username = settings.Username, Password = settings.Password }; await JsonSerializer.SerializeAsync(stream, configuredBroker); stream.Close(); } this._brokerSettingsFileLocked = false; this.MqqtConfigChangedHandler.Invoke(await this.GetMqttClientOptionsAsync()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MqttSettings mqttSettings, IMqttService mqttService) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); //app.UseCors(x => x // .AllowAnyOrigin() // .AllowAnyMethod() // .AllowAnyHeader()); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); app.UseMqttEndpoint(mqttSettings, mqttService); }
/// <summary> /// Constructor /// </summary> /// <param name="commLayer">Communication layer to use (TCP)</param> /// <param name="settings">Broker settings</param> private MqttBroker(IMqttCommunicationLayer commLayer, MqttSettings settings) { // MQTT broker settings this.settings = settings; // MQTT communication layer this.commLayer = commLayer; this.commLayer.ClientConnected += commLayer_ClientConnected; // create managers (publisher, subscriber, session and UAC) this.subscriberManager = new MqttSubscriberManager(); this.sessionManager = new MqttSessionManager(); this.publisherManager = new MqttPublisherManager(this.subscriberManager, this.sessionManager); this.uacManager = new MqttUacManager(); this.clients = new MqttClientCollection(); }
public void initialize(string messageBrokerHostName, uint port, string userName, string password, string topic) { synchronizationContext = System.Threading.SynchronizationContext.Current; settings = new MqttSettings(messageBrokerHostName, port, true, userName, password, topic); Synthesizer = new SpeechSynthesizer(); Synthesizer.Volume = 100; try { Synthesizer.SelectVoice("Microsoft Szabolcs"); } catch (ArgumentException) { //The choosen voice is not installed, we use the default. } ApplicationUserName = SessionViewModel.GetUsername(); Client = new MqttClient(settings.MessageBrokerHostName, Convert.ToInt32(settings.Port), true, null, null, MqttSslProtocols.TLSv1_2); Client.MqttMsgPublishReceived += new MqttClient.MqttMsgPublishEventHandler(EventPublished); }
/// <summary> /// This writes the provided settings to the config file. /// </summary> /// <param name="settings"></param> public void WriteMqttBrokerSettingsAsync(MqttSettings settings) { this._configurationService.WriteMqttBrokerSettingsAsync(settings); }
public async void GetSettings() { MqttSettings settings = await this.client.InvokeAsync(x => x.GetMqttBrokerSettings()); ((BrokerSettingsViewModel)this.DataContext).Update(settings); }