|
|
|
@ -237,38 +237,42 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
|
|
|
|
|
|
|
|
|
|
public void Publish<T>(T data) where T : ICmd
|
|
|
|
|
{
|
|
|
|
|
Model<T> model = new Model<T>
|
|
|
|
|
if (MqttClient.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
Header = new Header()
|
|
|
|
|
Model<T> model = new Model<T>
|
|
|
|
|
{
|
|
|
|
|
cmd = data.GetCmd(),
|
|
|
|
|
cipherFlag = Encrypt,
|
|
|
|
|
id = GetIncrementId(),
|
|
|
|
|
sid = StationNo,
|
|
|
|
|
timeStamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000
|
|
|
|
|
},
|
|
|
|
|
body = data
|
|
|
|
|
};
|
|
|
|
|
Header = new Header()
|
|
|
|
|
{
|
|
|
|
|
cmd = data.GetCmd(),
|
|
|
|
|
cipherFlag = Encrypt,
|
|
|
|
|
id = GetIncrementId(),
|
|
|
|
|
sid = StationNo,
|
|
|
|
|
timeStamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000
|
|
|
|
|
},
|
|
|
|
|
body = data
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
model.dataSign = "";//SignData(model);
|
|
|
|
|
model.dataSign = "";//SignData(model);
|
|
|
|
|
|
|
|
|
|
var settings = new JsonSerializerSettings()
|
|
|
|
|
{
|
|
|
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
|
|
|
DateFormatString = "yyyy-MM-dd HH:mm:ss",
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
|
};
|
|
|
|
|
Log.Info(JsonConvert.SerializeObject(model, settings));
|
|
|
|
|
var appMsg = new MqttApplicationMessage
|
|
|
|
|
{
|
|
|
|
|
Topic = PubTopic,
|
|
|
|
|
Payload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model, settings)),
|
|
|
|
|
QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce,
|
|
|
|
|
Retain = false
|
|
|
|
|
};
|
|
|
|
|
var settings = new JsonSerializerSettings()
|
|
|
|
|
{
|
|
|
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
|
|
|
DateFormatString = "yyyy-MM-dd HH:mm:ss",
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
|
};
|
|
|
|
|
Log.Info(JsonConvert.SerializeObject(model, settings));
|
|
|
|
|
var appMsg = new MqttApplicationMessage
|
|
|
|
|
{
|
|
|
|
|
Topic = PubTopic,
|
|
|
|
|
Payload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model, settings)),
|
|
|
|
|
QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce,
|
|
|
|
|
Retain = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MqttClient.PublishAsync(appMsg);
|
|
|
|
|
MqttClient.PublishAsync(appMsg);
|
|
|
|
|
MqttClient.PublishAsync(appMsg);
|
|
|
|
|
MqttClient.PublishAsync(appMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string SignData<T>(Model<T> model) where T : ICmd
|
|
|
|
|