コード例 #1
0
        void IncommingData(string chipId, string topic, string msg)
        {
            try
            {
                var temp = float.Parse(msg, CultureInfo.InvariantCulture.NumberFormat);
                Log data = new Log {
                    DeviceId = 1, Data = temp, TimeStamp = DateTime.Now
                };


                string            json = SendHttpGetToRestController("apiLog/GetCommunicationUnit?chipId=" + chipId);
                CommunicationUnit c    = DeserializeLogCommunicationUnit(json);

                json = SendHttpGetToRestController("apiLog/GetDevice?comunitid=" + c.Id.ToString() + "&type=" + topic);
                Device device = DeserializeDevice(json);
                data.DeviceId = device.Id;
                // string controller = "data/{temperature}/{9}";
                // List<Log> list = DeserializeLogJson(SendHttpGetToRestController(controller));

                //  list.Add(data);



                SendHttpPostToRestController("apiLog/PostData", data);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
        public void InitNewCommunicationUnitAddIpAddress(CommunicationUnit c)
        {
            var a = _ctx.CommunicationUnits.Where(w => w.Id == c.Id).FirstOrDefault();

            a.IPAddress = c.IPAddress;
            _ctx.SaveChanges();
        }
コード例 #3
0
        public void InitDatabase()
        {
            Room r = new Room {
                Name = "Szoba"
            };
            CommunicationUnit e = new CommunicationUnit {
                Code = "espcode", IPAddress = "0.0.0.159"
            };
            Device s = new Device {
                CommunicationUnit = e, CommunicationUnitId = e.Id, Room = r, RoomId = r.Id, Type = "temperature", Name = "DHT11", IO = false
            };
            Device ss = new Device {
                CommunicationUnit = e, CommunicationUnitId = e.Id, Room = r, RoomId = r.Id, Type = "humidity", Name = "DHT11", IO = false
            };
            Device sss = new Device {
                CommunicationUnit = e, CommunicationUnitId = e.Id, Room = r, RoomId = r.Id, Type = "heater", Name = "lampa", IO = true
            };

            _ctx.Add(r);
            _ctx.Add(e);
            _ctx.Add(s);
            _ctx.Add(ss);
            _ctx.Add(sss);
            _ctx.SaveChanges();
        }
コード例 #4
0
        private void AddIpAddress(string chipId, string ipAddress)
        {
            string            json = SendHttpGetToRestController("apiLog/GetCommunicationUnit?chipId=" + chipId);
            CommunicationUnit c    = DeserializeLogCommunicationUnit(json);

            c.IPAddress = ipAddress;
            SendHttpPostToRestController("apiLog/InitNewCommunicationUnitAddIpAddress/ ", c);
        }
コード例 #5
0
        public int InsertNewCommunicationUnit(string chipId)
        {
            CommunicationUnit c = _ctx.CommunicationUnits.Where(w => w.Code == chipId).FirstOrDefault();

            if (c == null)
            {
                c = new CommunicationUnit {
                    Code = chipId
                };
                _ctx.Add(c);
                _ctx.SaveChanges();
            }
            return(c.Id);
        }
コード例 #6
0
        private void AddNewDeviceToCommunicationUnit(string chipId, string msg)
        {
            var device = msg.Split('/');

            string type = device[0];
            string name = device[1];
            bool   io   = bool.Parse(device[2]);



            string            json = SendHttpGetToRestController("apiLog/GetCommunicationUnit?chipId=" + chipId);
            CommunicationUnit c    = DeserializeLogCommunicationUnit(json);
            Device            d    = new Device {
                Name = name, IO = io, Type = type, CommunicationUnitId = c.Id
            };

            SendHttpPostToRestController("apiLog/InitDevice/ ", d);

            if (type == "temperature" || type == "humidity")
            {
                SubscribeToMqttTopic(chipId + "/" + type);
                PublishDataToTopic(chipId + "/start", true);
            }
        }
コード例 #7
0
 /// <summary>
 /// Create Communication Port for Arduino on rod if defined
 /// </summary>
 /// <param name="rodType">Rod Type</param>
 /// <param name="publisher">Publisher for arduino actions</param>
 /// <param name="onServoChangeState">Method to call on arduino servo state changed</param>
 private void Create(eRod rodType, RodActionPublisher publisher, Action<eRod, eRotationalMove> onServoChangeState)
 {
     CommunicationUnit unit = null;
     if (Configuration.Attributes.IsServoExistsWithFeedback(rodType))
     {
         unit = new CommunicationUnit(publisher, rodType, ARDUINO_PORT[rodType], onServoChangeState);
         unit.InitializeRod();
         _allArduinos.Add(rodType, unit);
     }
 }
コード例 #8
0
 public IActionResult InitNewCommunicationUnitAddIpAddress([FromBody] CommunicationUnit c)
 {
     _communicationUnitService.InitNewCommunicationUnitAddIpAddress(_mapper.Map <DataAccessLayer.Entities.CommunicationUnit>(c));
     return(Ok("InitNewCommunicationUnitAddIpAddress"));
 }