public async Task StopClientAsync() { if (client.IsConnected != false) { await client.StopAsync(); } }
private async void Disconnect(object sender, RoutedEventArgs e) { try { if (_mqttClient != null) { await _mqttClient.DisconnectAsync(); _mqttClient.Dispose(); _mqttClient = null; } if (_managedMqttClient != null) { await _managedMqttClient.StopAsync(); _managedMqttClient.Dispose(); _managedMqttClient = null; } } catch (Exception exception) { Trace.Text += exception + Environment.NewLine; } }
private async void MQTTStop() { await managedMqttClientPublisher.StopAsync(); managedMqttClientPublisher = null; Console.WriteLine("MQTT Connection has been stopped"); }
public void Dispose() { if (managedMqttClient != null) { managedMqttClient.StopAsync(); managedMqttClient.Dispose(); } }
private async void Disconnect_button_Click(object sender, EventArgs e) { await _mqttClient.StopAsync(); _timer.Stop(); _mqttClient = null; }
private async void Disconnect_Click(object sender, RoutedEventArgs e) { await client?.StopAsync(); client = null; IsConnected = false; }
/// <summary> /// Stop logic /// </summary> /// <returns></returns> public async Task Stop() { _infoTimer?.Stop(); _stopHttpListener = true; _httpListener?.Stop(); await _mqttClient?.StopAsync(); }
public async Task StopAsync() { if (IsInitialized) { return; } await _client.StopAsync(); }
private async Task DisconnectAsync() { if (MqttClient.IsConnected) { Debug("Disconnecting", 1); //await MqttClient.DisconnectAsync(); await MqttClient.StopAsync(); } }
public async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Service stopping"); await _client.StopAsync(); await _backgroundTask; _logger.LogInformation("Service stopped"); }
public Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation($"Stopping MqttListener for {Descriptor}"); ThrowIfDisposed(); if (_managedMqttClient == null) { throw new InvalidOperationException("The listener has not yet been started or has already been stopped."); } _cancellationTokenSource.Cancel(); _managedMqttClient.StopAsync().Wait(); _managedMqttClient.Dispose(); _managedMqttClient = null; return(Task.FromResult <bool>(true)); }
public async void Stop() { try { await subscriber?.StopAsync(); } catch (NullReferenceException) { //Do nothing } }
public async Task Connect(string deviceId, string password) { var options = new ManagedMqttClientOptionsBuilder() .WithAutoReconnectDelay(TimeSpan.FromSeconds(5)) .WithClientOptions(new MqttClientOptionsBuilder() .WithClientId(_mqttOptions.ClientId) .WithTcpServer(_mqttOptions.Server) .WithCredentials(deviceId, password) .Build()) .Build(); if (_client.IsStarted) { await _client.StopAsync(); } await _client.StartAsync(options); await SubscribeTopic($"{_mqttOptions.DevicesTopic}/{deviceId}/receive/#"); }
/// <summary> /// Close the MQTT connection /// </summary> public Task StopAsync() { if (_managedMqttClient == null) { return(Task.CompletedTask); } _managedMqttClient.StopAsync().Wait(); _managedMqttClient.Dispose(); _managedMqttClient = null; return(Task.CompletedTask); }
public static void StopMQTT() { Logging.WriteDebugLog("MQTT.StopMQTT()"); _timerMQTT.Dispose(); SendMessage(string.Format("{0}/status", _strClientId.ToLower()), "offline"); _mqtt.StopAsync(); _mqtt.Dispose(); _mqtt = null; }
public async Task Stop() { try { if (_mqttClient != null) { await _mqttClient.StopAsync().ConfigureAwait(false); } } finally { _mqttClient?.Dispose(); } }
public void Close() { if (client.IsConnected) { try { client.StopAsync().Wait(); } catch (Exception ex) { Log.Error("SDK.Error: Close connection error, deviceid is " + clientConf.DeviceId); } } }
protected virtual void Dispose(bool disposing) { if (_disposedValue) { return; } if (disposing) { _mqttClient.StopAsync().Wait(); _mqttClient = null; } _disposedValue = true; }
public Task StopAsync(CancellationToken cancellationToken) { _mqttClient.StopAsync().Wait(); _mqttClient.Dispose(); _allSockets.ForEach(s => { s.Close(); }); _allSockets.Clear(); _server.Dispose(); return(Task.CompletedTask); }
private void ConfiguracionToolStripMenuItem1_Click(object sender, EventArgs e) { if (EstadoCloud) { configuracionToolStripMenuItem1.Text = "Conectar"; client.StopAsync(); } else { configuracionToolStripMenuItem1.Text = "Desconectar"; Cloud cloud = new Cloud(); cloud.pasado += new Cloud.sendCred(cloudCred); cloud.ShowDialog(); } }
private async void but_Stop_Click(object sender, EventArgs e) { if (mqttClient != null) { if (mqttClient.IsStarted) { await mqttClient.StopAsync(); } mqttClient.Dispose(); } but_Subscribe.Enabled = false; but_Publish.Enabled = false; but_Stop.Enabled = false; but_Start.Enabled = true; }
/// <summary> /// Close the MQTT connection. /// </summary> public Task StopAsync() { if (_managedMqttClient == null) { return(Task.CompletedTask); } ConnectionState = ConnectionState.Disconnected; _managedMqttClient.StopAsync().Wait(); _managedMqttClient.Dispose(); _managedMqttClient = null; _messageHandler = null; return(Task.CompletedTask); }
public void Stop() { Policy .HandleResult <MqttClientPublishResult>(r => r.ReasonCode == MqttClientPublishReasonCode.UnspecifiedError) .WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(2), (exception, timespan) => _logger.LogWarning("Error sending offline message. Retrying...")) .Execute(() => { var message = _mqttClient.PublishAsync(_lwtMessage); message.Wait(); return(message.Result); }); _mqttClient.StopAsync().Wait(); _logger.LogDebug("Stopped client"); _mqttClient.Dispose(); }
public void Dispose() { if (_disposed) { return; } _disposed = true; try { _mqttClient?.StopAsync().Wait(); _mqttClient?.Dispose(); } catch (IOException ex) { _logger.LogCritical(ex.ToString()); } }
//Buttons Events private async void BTN_Save_Settings_ClickAsync(object sender, EventArgs e) { Properties.Settings.Default.MQTT_Ipaddr = TB_IPaddr.Text; Properties.Settings.Default.MQTT_Port = TB_Port.Text; Properties.Settings.Default.MQTT_User = TB_User.Text; Properties.Settings.Default.DeviceID = TB_DevID.Text; Properties.Settings.Default.MQTT_Password = TB_Password.Text; Properties.Settings.Default.ACBoot = Chk_ACBoot.Checked; Properties.Settings.Default.ACShutdown = Chk_ACshutdown.Checked; Properties.Settings.Default.Startup = ck1_startup.Checked; Properties.Settings.Default.Save(); if (Load_Setting()) { //reload credential await mqttClient.StopAsync(); string MQTT_ClientID = String.Concat("PC-", GetMACAddress()); string MQTT_IPaddr = Properties.Settings.Default.MQTT_Ipaddr; string MQTT_User = Properties.Settings.Default.MQTT_User; string MQTT_Password = Properties.Settings.Default.MQTT_Password; // Setup and start a managed MQTT client. ManagedMqttClientOptions options = new ManagedMqttClientOptionsBuilder() .WithAutoReconnectDelay(TimeSpan.FromSeconds(5)) .WithClientOptions(new MqttClientOptionsBuilder() .WithClientId(MQTT_ClientID) .WithTcpServer(MQTT_IPaddr) .WithCredentials(MQTT_User, MQTT_Password) .WithCleanSession(true) .WithKeepAlivePeriod(TimeSpan.FromSeconds(120)).Build()) .Build(); await mqttClient.StartAsync(options); Hide(); } else { Form2 testDialog = new Form2(); testDialog.ShowDialog(); } }
public async void ReplaceMqttClient(IManagedMqttClientOptions options) { this._logger.LogInformation($"Replacing Mqtt client with new config"); await _mqttClient.StopAsync(); try { await _mqttClient.StartAsync(options); } catch (MqttConnectingFailedException ex) { this._mqttClientMessage = ex.ResultCode.ToString(); Log.Logger.Error("Could not connect to broker: " + ex.ResultCode.ToString()); } catch (MqttCommunicationException ex) { this._mqttClientMessage = ex.ToString(); Log.Logger.Error("Could not connect to broker: " + ex.Message); } }
public static async Task Stop() { if (_mqtt != null) { await _mqtt.StopAsync(); } if (_quartzScheduler != null) { try { await _quartzScheduler.Shutdown(); } catch (SchedulerException) { } } _actorSystem?.Dispose(); }
public async Task StopAsync() { if (disposedValue) { throw new InvalidOperationException("Client is disposed."); } await clientLock.WaitAsync(); try { if (client == null) { return; } await client.StopAsync(); } finally { clientLock.Release(); } }
private async Task DisconnectAsync() { try { if (mClient != null) { await mClient.StopAsync(); mClient = null; } if (client != null) { await client.DisconnectAsync(); client = null; } } catch (Exception ex) { } }
public async Task Close() { _tokenSource?.Cancel(); if (_client == null || !_client.IsConnected) { return; } try { await UpdateStatus(false, CancellationToken.None); await _client.StopAsync(); } catch (Exception e) { _logger.LogError(e, "Exception while closing connection"); } finally { _client?.Dispose(); _client = null; } }