public bool UpdateNodeSettings(Node node) { //todo // gateway.UpdateNode(node); return true; }
private static void OnNodeUpdated(Node node) { hub.Clients.All.OnNodeUpdated(node); }
private static void OnNewNode(Node node) { hub.Clients.All.OnNewNode(node); }
private void UpdateNodeFromMessage(Message mes) { Node node = GetNode(mes.nodeId); if (node == null) { node = new Node(mes.nodeId); nodes.Add(node); db?.AddNode(node); OnNewNode?.Invoke(node); LogInfo($"Node[{node.Id}] registered."); } node.UpdateLastSeenNow(); if (mes.sensorId == 255) { if (mes.messageType == MessageType.C_PRESENTATION) { if (mes.subType == (int)SensorType.S_ARDUINO_NODE) { node.isRepeatingNode = false; OnNodeUpdated?.Invoke(node); } else if (mes.subType == (int)SensorType.S_ARDUINO_REPEATER_NODE) { node.isRepeatingNode = true; OnNodeUpdated?.Invoke(node); } } else if (mes.messageType == MessageType.C_INTERNAL) { if (mes.subType == (int)InternalDataType.I_SKETCH_NAME) { node.name = mes.payload; LogInfo($"Node[{node.Id}] name: [{node.name}]"); OnNodeUpdated?.Invoke(node); } else if (mes.subType == (int)InternalDataType.I_SKETCH_VERSION) { node.version = mes.payload; LogInfo($"Node[{node.Id}] version: [{node.version}]"); OnNodeUpdated?.Invoke(node); } else if (mes.subType == (int)InternalDataType.I_BATTERY_LEVEL) { node.batteryLevel = Int32.Parse(mes.payload); LogInfo($"Node[{node.Id}] battery level: [{node.batteryLevel}]"); OnNodeBatteryUpdated?.Invoke(node); } } } OnNodeLastSeenUpdated?.Invoke(node); db?.UpdateNode(node); }
private static void OnRemoveNode(Node node) { hub.Clients.All.OnRemoveNode(node.Id); }
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 Sensor(int sensorId, Node ownerNode) { this.sensorId = sensorId; this.nodeId = ownerNode.Id; }
public void UpdateNode(Node node) { if (writeInterval == 0) { 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, node); } } else { if (!updatedNodes.Contains(node)) updatedNodes.Add(node); } }
public int AddNode(Node node) { using (var db = new SqlConnection(connectionString)) { var sqlQuery = "INSERT INTO MySensorsNodes (Id, registered, lastSeen, isRepeatingNode, name ,version, batteryLevel) " + "VALUES(@Id, @registered, @lastSeen, @isRepeatingNode, @name, @version, @batteryLevel)"; db.Query(sqlQuery, node); } return node.Id; }
public int AddNode(Node node) { //todo EF change nodeID automaticaly!!!! db.Nodes.Add(node); db.SaveChanges(); foreach (var sensor in node.sensors) { AddSensor(sensor); } return node.Id; }
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 UpdateNode(Node node) { if (writeInterval == 0) { db.Nodes.Update(node); db.SaveChanges(); } else { if (!updatedNodes.Contains(node)) updatedNodes.Add(node); } }