コード例 #1
0
 public void Update()
 {
     using (var dbContext = new HelloHomeDbContext())
     {
         var nodes = dbContext.Nodes
             .Include(_ => _.Ports)
             .Include(_ => _.LatestValues)
             .Where(_ => _.Configuration.EmonCmsNodeId.HasValue);
         foreach (var node in nodes)
         {
             var values = new List<float>
             {
                 node.LatestValues.VIn ?? 0,
                 node.LatestValues.Temperature ?? 0,
                 node.LatestValues.Humidity ?? 0,
                 node.LastSeen.HasValue ? (float) (DateTime.Now - node.LastSeen.Value).TotalDays : 0
             };
             foreach (var port in node.Ports.OfType<PulsePort>() .OrderBy(_ => _.Number))
             {
                 values.Add(port.PulseCount);
             }
             values.Add(node.LatestValues.Rssi);
             _emonCmsAgent.Send(node.Configuration.EmonCmsNodeId.Value, values);
         }
     }
 }
コード例 #2
0
 public IEnumerable<Node> Get()
 {
     using (var dbContext = new HelloHomeDbContext ()) {
         return dbContext.Nodes.ToList ();
     }
 }