Exemplo n.º 1
0
        public async Task <IHttpActionResult> PostRestart(string id)
        {
            MqttService.MqttService lService = await GetMqttService();

            lService.CommandMcuReset(id);
            return(Ok(200));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PostPowerOn(string id)
        {
            MqttService.MqttService lService = await GetMqttService();

            lService.CommandMcuPower(id, 1);
            return(Ok(200));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> PostKill(string id)
        {
            MqttService.MqttService lService = await GetMqttService();

            lService.CommandMcuHardShutdown(id);
            return(Ok(200));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            /*var svc = new MqttService.MqttService();
             * var mc = new Microcontroller("aaaa", false, 64.2);
             * var ps = new PowerStrip("bbbb");
             *
             * Console.WriteLine("MC: {0}, {1}, {2}", mc.DeviceId, mc.Powered, mc.Temperature);
             * Console.WriteLine("PS: {0}, {1}", ps.DeviceId, ps.Powered);
             *
             * var repo = new SqlRepository();
             *
             * Console.WriteLine("Trying to load data");
             * List<Microcontroller> mcrs = repo.Microcontrollers.All().ToList();
             * List<PowerStrip> pwss = repo.PowerStrips.All().ToList();
             *
             * Console.WriteLine("Microcontrollers: {0}", mcrs.Count);
             * Console.WriteLine("Power Strips: {0}", pwss.Count);
             *
             * if (mcrs.Count == 0)
             *  repo.Microcontrollers.Add(mc);
             * if (pwss.Count == 0)
             *  repo.PowerStrips.Add(ps);*/
            /*
             *    Console.WriteLine("Connecting");
             *    var c = new Client("ws://mqtt-xklima22.azurewebsites.net:80/mqtt");
             *    Console.WriteLine("Connected");
             */

            MqttService.MqttService srv = new MqttService.MqttService();
            srv.ConnectClient().Wait();
            Console.WriteLine("Connected");
            List <Microcontroller> mcus = srv.GetMicrocontrollers().ToList();

            Console.ReadKey();
        }
Exemplo n.º 5
0
        public async Task <List <Microcontroller> > GetAllMcus()
        {
            MqttService.MqttService lService = await GetMqttService();

            List <Microcontroller> result = lService.GetMicrocontrollers().ToList();

            return(result);
        }
Exemplo n.º 6
0
        public async Task <List <PowerStrip> > GetAllStrips()
        {
            MqttService.MqttService lService = await GetMqttService();

            List <PowerStrip> result = lService.GetPowerStrips().ToList();

            return(result);
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> GetMcu(string id)
        {
            MqttService.MqttService lService = await GetMqttService();

            var mcus = lService.GetMicrocontrollers().ToList();
            var mcu  = mcus.FirstOrDefault((p) => p.DeviceId == id);

            if (mcu == null)
            {
                return(NotFound());
            }
            return(Ok(mcu));
        }
Exemplo n.º 8
0
        public async Task <IHttpActionResult> GetStrip(string id)
        {
            MqttService.MqttService lService = await GetMqttService();

            var strips = lService.GetPowerStrips().ToList();
            var strip  = strips.FirstOrDefault((p) => p.DeviceId == id);

            if (strip == null)
            {
                return(NotFound());
            }
            return(Ok(strip));
        }