コード例 #1
0
        //public SensorData(int nodeId, int sensorId, SensorDataType? dataType, string state)
        //{
        //    this.nodeId = nodeId;
        //    this.sensorId = sensorId;
        //    this.dataType = dataType;
        //    this.state = state;
        //    dateTime = DateTime.Now;
        //}

        public SensorData(Sensor sensor)
        {
            this.nodeId = sensor.nodeId;
            this.sensorId = sensor.sensorId;
            this.dataType = sensor.dataType;
            this.state = sensor.state;
            dateTime = DateTime.Now;
        }
コード例 #2
0
        public void AddInputAndOutput(Sensor sensor)
        {
            MySensorsNodeInput input = new MySensorsNodeInput { Name = sensor.sensorId.ToString() };
            input.sensorId = sensor.sensorId;
            input.nodeId = sensor.nodeId;
            input.SlotIndex = sensor.sensorId;
            AddInput(input);

            MySensorsNodeOutput output = new MySensorsNodeOutput { Name = sensor.GetSimpleName3() };
            output.sensorId = sensor.sensorId;
            output.nodeId = sensor.nodeId;
            //todo output.Value = sensor.state;
            output.SlotIndex = sensor.sensorId;
            AddOutput(output);
        }
コード例 #3
0
 private static void OnSensorUpdated(Sensor sensor)
 {
     hub.Clients.All.OnSensorUpdated(sensor);
 }
コード例 #4
0
 private static void OnNewSensor(Sensor sensor)
 {
     hub.Clients.All.OnNewSensor(sensor);
 }
コード例 #5
0
 private void SendSensorState(Sensor sensor)
 {
     Message message = new Message
     {
         ack = false,
         messageType = MessageType.C_SET,
         nodeId = sensor.nodeId,
         payload = sensor.state,
         sensorId = sensor.sensorId,
         subType = (int)sensor.dataType
     };
     SendMessage(message);
 }
コード例 #6
0
 public MySensorsNodeInput GetMySensorsNodeInput(Sensor sensor)
 {
     return GetMySensorsNodeInput(sensor.nodeId, sensor.sensorId);
 }
コード例 #7
0
        private void CreateOrUpdateSensor(Sensor sensor)
        {
            MySensorsNodeOutput output = GetMySensorsNodeOutput(sensor);
            if (output == null)
            {
                MySensorsNode node = GetMySensorsNode(sensor.nodeId);
                node.AddInputAndOutput(sensor);
                engine.UpdateNodeInEditor(node);
                engine.UpdateNodeInDb(node);
            }
            else
            {
                engine.UpdateOutput(output.Id, sensor.state, sensor.GetSimpleName3());
            }

        }
コード例 #8
0
        private void WriteUpdated()
        {
            if (!updatedNodes.Any() && !updatedSensors.Any())
                return;

            if (updatedNodes.Any())
            {

                //to prevent changing of collection while writing to db is not yet finished
                Node[] nodesTemp = new Node[updatedNodes.Count];
                updatedNodes.CopyTo(nodesTemp);
                updatedNodes.Clear();

                using (var db = new SqlConnection(connectionString))
                {
                    var sqlQuery =
                        "UPDATE MySensorsNodes SET " +
                        "registered = @registered, " +
                        "lastSeen = @lastSeen, " +
                        "isRepeatingNode = @isRepeatingNode, " +
                        "name = @name, " +
                        "version = @version, " +
                        "batteryLevel = @batteryLevel " +
                        "WHERE Id = @Id";
                    db.Execute(sqlQuery, nodesTemp);
                }
            }

            if (updatedSensors.Any())
            {

                //to prevent changing of collection while writing to db is not yet finished
                Sensor[] sensorsTemp = new Sensor[updatedSensors.Count];
                updatedSensors.CopyTo(sensorsTemp);
                updatedSensors.Clear();

                using (var db = new SqlConnection(connectionString))
                {
                    var sqlQuery =
                        "UPDATE MySensorsSensors SET " +
                        "nodeId = @nodeId, " +
                        "sensorId  = @sensorId, " +
                        "type = @type, " +
                        "dataType = @dataType, " +
                        "state = @state, " +
                        "description = @description " +
                        "WHERE nodeId = @nodeId AND sensorId = @sensorId";
                    db.Execute(sqlQuery, sensorsTemp);
                }
            }
        }
コード例 #9
0
        public void UpdateSensor(Sensor sensor)
        {
            if (writeInterval == 0)
            {
                using (var db = new SqlConnection(connectionString))
                {
                    db.Open();

                    var sqlQuery =
                        "UPDATE MySensorsSensors SET " +
                        "nodeId = @nodeId, " +
                        "sensorId  = @sensorId, " +
                        "type = @type, " +
                        "dataType = @dataType, " +
                        "state = @state, " +
                        "description = @description " +
                        "WHERE nodeId = @nodeId AND sensorId = @sensorId";
                    db.Execute(sqlQuery, sensor);
                }
            }
            else
            {
                if (!updatedSensors.Contains(sensor))
                    updatedSensors.Add(sensor);
            }
        }
コード例 #10
0
        public int AddSensor(Sensor sensor)
        {
            int id;
            using (var db = new SqlConnection(connectionString))
            {

                var sqlQuery = "INSERT INTO MySensorsSensors (nodeId, sensorId, type, dataType,state, description) "
                               +
                               "VALUES(@nodeId, @sensorId, @type, @dataType ,@state, @description); "
                               + "SELECT CAST(SCOPE_IDENTITY() as int)";
                id = db.Query<int>(sqlQuery, sensor).Single();

            }
            return id;
        }
コード例 #11
0
ファイル: Node.cs プロジェクト: nickpirrottina/MyNetSensors
        public Sensor AddSensor(int sensorId)
        {
            Sensor sensor = GetSensor(sensorId);
            if (sensor != null) return sensor;

            sensor = new Sensor(sensorId, this);
            sensors.Add(sensor);
            return sensor;
        }
コード例 #12
0
        private void WriteUpdated()
        {
            if (!updatedNodes.Any() && !updatedSensors.Any())
                return;

            if (updatedNodes.Any())
            {

                //to prevent changing of collection while writing to db is not yet finished
                Node[] nodesTemp = new Node[updatedNodes.Count];
                updatedNodes.CopyTo(nodesTemp);
                updatedNodes.Clear();

                db.Nodes.UpdateRange(nodesTemp);
            }

            if (updatedSensors.Any())
            {

                //to prevent changing of collection while writing to db is not yet finished
                Sensor[] sensorsTemp = new Sensor[updatedSensors.Count];
                updatedSensors.CopyTo(sensorsTemp);
                updatedSensors.Clear();

                db.Sensors.UpdateRange(sensorsTemp);
            }

            db.SaveChanges();
        }
コード例 #13
0
 public void UpdateSensor(Sensor sensor)
 {
     if (writeInterval == 0)
     {
         db.Sensors.Update(sensor);
         db.SaveChanges();
     }
     else
     {
         if (!updatedSensors.Contains(sensor))
             updatedSensors.Add(sensor);
     }
 }
コード例 #14
0
 public int AddSensor(Sensor sensor)
 {
     db.Sensors.Add(sensor);
     db.SaveChanges();
     return sensor.Id;
 }