private void _mqtt_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) { var msg = JsonConvert.DeserializeObject <Message>(Encoding.UTF8.GetString(e.Message)); if (msg.UserId != Setting.GetValue <int>("userid")) { var data = new Message() { DataType = msg.DataType, UserId = Setting.GetValue <int>("userid"), StartTime = msg.StartTime, EndTime = msg.EndTime }; if (msg.DataType == 0) //当前数据 { data.Body = new List <DataModel>() { new DataModel(Data) }; } else if (msg.DataType == 2) //历史数据 { data.Body = _db.Table <DataModel>().Where(p => DateTime.Compare(msg.StartTime, p.Time) < 0 && DateTime.Compare(msg.EndTime, p.Time) > 0).ToList(); } _mqtt.PostData(JsonConvert.SerializeObject(data)); } }
public void RequestData(int dataType, DateTime start, DateTime end) { var msg = new MessageBase() { DataType = dataType, UserId = Setting.GetValue <int>("userid"), StartTime = start, EndTime = end }; _mqtt.PostData(JsonConvert.SerializeObject(msg)); }