//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; }
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); }
private static void OnSensorUpdated(Sensor sensor) { hub.Clients.All.OnSensorUpdated(sensor); }
private static void OnNewSensor(Sensor sensor) { hub.Clients.All.OnNewSensor(sensor); }
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); }
public MySensorsNodeInput GetMySensorsNodeInput(Sensor sensor) { return GetMySensorsNodeInput(sensor.nodeId, sensor.sensorId); }
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()); } }
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); } } }
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); } }
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; }
public Sensor AddSensor(int sensorId) { Sensor sensor = GetSensor(sensorId); if (sensor != null) return sensor; sensor = new Sensor(sensorId, this); sensors.Add(sensor); return sensor; }
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(); }
public void UpdateSensor(Sensor sensor) { if (writeInterval == 0) { db.Sensors.Update(sensor); db.SaveChanges(); } else { if (!updatedSensors.Contains(sensor)) updatedSensors.Add(sensor); } }
public int AddSensor(Sensor sensor) { db.Sensors.Add(sensor); db.SaveChanges(); return sensor.Id; }