public ApplicationMessageResult Create(AuthNotifyRequest message) { var envelope = Envelope.Create(message, _cryptoService.Key, _cryptoService.Iv, _cryptoServiceProvider); envelope.ReplyKey = "MessageAuthNotify." + Guid.NewGuid(); var payload = JsonConvert.SerializeObject(envelope); return(new ApplicationMessageResult { Envelope = envelope, Message = new MqttApplicationMessageBuilder() .WithTopic("MESSAGEAUTHREQUEST") .WithPayload(payload) .WithAtLeastOnceQoS() .WithRetainFlag() .Build(), TopicFilter = new TopicFilterBuilder().WithTopic(envelope.ReplyKey) .WithAtMostOnceQoS() .Build() }); }
public async Task ConnectAsync() { if (!IsConnected) { //var value = System.Text.Encoding.Default.GetString(Convert.FromBase64String("ewogICJyZXN1bHQiOiBudWxsLAogICJtZXNzYWdlVHlwZSI6ICJPSyIsCiAgInN0YXRlIjogbnVsbCwKICAic291cmNlTWVzc2FnZUlEIjogbnVsbAp9")); using (var channel = _channelFactory.CreateGreenChannel(GatewayId)) { await channel.ConnectAsync(); var message = new AuthNotifyRequest { SecretKey = "EASYmsaBOA", Uid = GatewayId }; var result = await channel.SendAsync <AuthNotifyResponse>(message); if (!result.Success) { throw new Exception(result.ErrorMsg); } Secret = result; } _channel = _channelFactory.CreateRedChannel(Secret); await _channel.ConnectAsync(); ConfigureDevices(x => x.AddDevice("HEARTBEAT", 1, p => p.AddProperty("VALUE"))); try { await _channel.SendAsync(new RegisterGatewayFromGatewayRequest { args = new GatewayArgs { gateway = new Gateway { Secret = "EASYmsaBOA", GatewayId = GatewayId, ClientId = Secret.ClientId, Devices = _deviceSetup.ToGatewayDevices(GatewayId) // new Dictionary<string, GatewayDevice>() //{ // { // $"{GatewayId}:{DeviceInfo.Manufacturer}|{GatewayId}:HEARTBEAT|1", new GatewayDevice // { // DeviceName = $"{GatewayId}:{DeviceInfo.Manufacturer}|{GatewayId}:HEARTBEAT|1", // DeviceType = "HEARTBEAT", // Properties = new Dictionary<string, Property>() // { // { // "VALUE", new Property // { // PropertyName = "value" // } // } // } // } // }, // { // $"{GatewayId}:{DeviceInfo.Manufacturer}|{GatewayId}:GPS|1", new GatewayDevice // { // DeviceName = $"{GatewayId}:{DeviceInfo.Manufacturer}|{GatewayId}:GPS|1", // DeviceType = "GPS", // Properties = new Dictionary<string, Property>() // { // { // "Latitude", new Property // { // PropertyName = "Latitude" // } // }, // { // "Longitude", new Property // { // PropertyName = "Longitude" // } // }, // { // "Altitude", new Property // { // PropertyName = "Altitude" // } // } // } // } // }, //} } } }); } catch (Exception e) { Console.WriteLine(e); throw; } IsConnected = true; } }