58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using DataServer.api;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
using HslCommunication.MQTT;
|
|
using HslCommunication;
|
|
using HslCommunication.LogNet;
|
|
using QingHaiVisualizationAPI.Utils;
|
|
|
|
namespace DongYingAPI.Controllers.api
|
|
{
|
|
public class SetLightingController : ApiController
|
|
{
|
|
static log4net.ILog log;
|
|
DataServer.BLL.device_info bll = new DataServer.BLL.device_info();
|
|
public HttpResponseMessage Get(string dev = "", string m = "",int v=0)
|
|
{
|
|
var res = new get_information();
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(dev) && !string.IsNullOrEmpty(m)&&v!=0)
|
|
{
|
|
log4net.Config.XmlConfigurator.Configure();
|
|
log = log4net.LogManager.GetLogger("loginfo");
|
|
var mqqt = new MqttClientService();
|
|
var list = new data();
|
|
list.dev = dev;
|
|
list.m = m;
|
|
list.v = v;
|
|
mqqt.MqttClientStart();
|
|
mqqt.Publish("data", JsonConvert.SerializeObject(list));
|
|
|
|
res.code= 200;
|
|
res.msg = "成功";
|
|
res.data= list;
|
|
}
|
|
else
|
|
{
|
|
res.code = 201;
|
|
res.msg = "参数为空";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
res.code = 500;
|
|
res.msg = "失败," + ex.Message;
|
|
}
|
|
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.GetEncoding("UTF-8"), "application/json") };
|
|
return result;
|
|
}
|
|
}
|
|
} |