private async void btInserir_Click(object sender, EventArgs e) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(tbRequest.Text); ConfigSensor config = new ConfigSensor(); config.IdSensor = Convert.ToInt32(tbIdSensor.Text); config.Descricao = tbDescricao.Text; config.Min = 4.1; //Convert.ToDouble(tbMin.Text); config.Max = 15.2; //Convert.ToDouble(tbMax.Text); config.UnidadeMedida = tbUnidadeMedida.Text; config.Metodo = tbMetodo.Text; config.VizinhosPadrao = Convert.ToInt32(cbNumViz.SelectedItem.ToString()); //config.Data = DateTime.Now; /*client.DefaultRequestHeaders.Accept.Add( * new MediaTypeWithQualityHeaderValue("application/json")); * * var resposta = await client.PostAsync(tbRequest.Text,config);*/ client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //StringContent content = new StringContent(JsonConvert.SerializeObject(config)); StringContent content = new StringContent(JsonConvert.SerializeObject(config), Encoding.UTF8, "application/json"); // HTTP POST HttpResponseMessage response = await client.PostAsync("", content); if (response.IsSuccessStatusCode) { string data = await response.Content.ReadAsStringAsync(); config = JsonConvert.DeserializeObject <ConfigSensor>(data); } /* * using (var client = new HttpClient()) * { * client.BaseAddress = new Uri("http://localhost:99999/"); * client.DefaultRequestHeaders.Accept.Clear(); * client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); * * StringContent content = new StringContent(JsonConvert.SerializeObject(product)); * // HTTP POST * HttpResponseMessage response = await client.PostAsync("api/products/save", content); * if (response.IsSuccessStatusCode) * { * string data = await response.Content.ReadAsStringAsync(); * product = JsonConvert.DeserializeObject<Product>(data); * } * } */ } }
protected override void onInitialize() { ConfigSensor cfg = getConfig <ConfigSensor>(); topicState = cfg.getParameterValue(ConfigCore.PARAMETER_TOPIC_STATE); sensorType = cfg.getParameterValue(ConfigCore.PARAMETER_TYPE); ServiceMQTT serviceMQTT = (ServiceMQTT)getManager().getServiceByName(CoreDaemonService.SERVICE_ID_MQTT); if (serviceMQTT != null) { serviceMQTT.Subscribe(topicState, this.onMqttMessage); } }
public void PublishClientConfig(ConfigSensor cs) { //TODO:: MIGRATE //ServiceMQ.Publish(ServiceMQ.EXCHANGE_CONTROL, cs.NodeId.ToString(), cs.toJSON()); }
public SensorMQTT(ConfigSensor config, IManager manager) : base(config, manager) { Triggered = false; }
public SensorProxy(ConfigSensor config, IManager manager) : base(config, manager) { }
private async Task LoadFromDatabase() { ZoneGuardConfigContextFactory factory = new ZoneGuardConfigContextFactory(); using (ZoneGuardConfigContext context = factory.CreateDbContext()) { /*************************************************************** * * Load Sensors * ***************************************************************/ List <ThingDAL> things = await context.Thing .Where <ThingDAL>(t => t.ThingType == ThingType.Sensor) .Include(p => p.Parameters) .ToListAsync <ThingDAL>(); foreach (ThingDAL thing in things) { Console.WriteLine(thing.Name); ConfigSensor configSensor = ZoneGuardConfigContextFactory.CreateThingFromDAL <ConfigSensor>(thing); Console.WriteLine(configSensor.toJSON()); //TODO:: More Dynamic addMQTTSensor(new SensorMQTT(configSensor, this), true); addProxySensor(new SensorProxy(configSensor, this), false); } /*************************************************************** * * Load AlarmZones * ***************************************************************/ List <AlarmZoneDAL> alarmZones = await context.AlarmZone .Include(az => az.Sensors) .ThenInclude(pa => pa.Thing) .ToListAsync <AlarmZoneDAL>(); foreach (AlarmZoneDAL zone in alarmZones) { ConfigAlarmZone configAlarmZone = ZoneGuardConfigContextFactory.CreateConfigAlarmZoneFromDAL(zone); AlarmZone alarmZone = new AlarmZone(configAlarmZone, this); alarmManager.addAlarmZone(alarmZone); /* * //if (zone.Enabled == 1) * { * Console.WriteLine("Creating Alarm Zone {0}", zone.Name); * foreach (AlarmZoneThingDAL sensor in zone.Sensors) * { * SensorCore sensorProxy = getSensorByName(sensor.Thing.Name); * SensorLink sensorLink = new SensorLink(sensorProxy, alarmZone, this); * * * //ConfigLink configLink = new ConfigLink(); * * //SensorProxy sensorProxy = new SensorProxy(configSensor, this); * //HEST * //alarmZone.addSensor(sensorProxy); * //if (sensor.Enabled == 1) * //{ * // Console.WriteLine(" Adding Sensor '{0}'", sensor.Thing.Name); * // } * * } * }*/ } } }
protected SensorCore(ConfigSensor config, IManager manager) : base(config, manager) { NodeId = config.NodeId; }