当前位置:网站首页>The DGIOT platform displays the whole process code analysis of OPC reporting data in real time
The DGIOT platform displays the whole process code analysis of OPC reporting data in real time
2022-08-10 17:18:00 【DGIOT Platform】
[小 迪 导读]:OPCSoftware is the most widely used software in the field of industrial automation,It is deeply loved by industrial controllers.But there are many cases,OPCThe software does not meet the actual needs of use:
使用场景
1.OPCOnly works on the intranet,It is hoped that the data can be transmitted to the external network,随时随地查看
2.OPCData is difficult to store
3.Hope to show the data better,进行数据分析
整体交互图

1. dgiot_dtu从kepserver获取数据
在opc与kepserver完成连接之后,dgiot_dtu通过调用GetOpcDaService函数连接kepserverImplement data callback
public OpcDaService GetOpcDaService(string host, string serviceProgId)
{
var service = hostCollection.Where(a => a.ServiceIds.Contains(serviceProgId) && a.Host == host)
.FirstOrDefault();
if (service == null)
{
return null;
}
OpcDaService service1 = null;
if (CheckServiceExisted(service, serviceProgId))
{
service1 = opcDaServices.Find(item => { return item.Host == service.Host && item.ServiceId == serviceProgId; });
}
else
{
OpcDaServer daService = new OpcDaServer(serviceProgId, service.Host);
service1 = new OpcDaService()
{
Host = service.Host,
ServiceId = serviceProgId,
Service = daService,
OpcDaGroupS = new Dictionary<string, OpcDaGroup>()
};
opcDaServices.Add(service1);
}
if (service1.Service.IsConnected == false)
{
try
{
service1.Service.ConnectionStateChanged += new EventHandler<OpcDaServerConnectionStateChangedEventArgs>(ConnectionStateChanged);
service1.Service.Connect();
}
catch (Exception e)
{
LogHelper.Log("Connect " + service1.Host + ", ServiceId " + service1.ServiceId + "error!!" + e.Message);
}
}
return service1;
}
COPY2. dgiot_dtu数据发布
dgiot_dtuAfter data collection is complete,和dgiotPlatform connection is throughmqtt来进行连接,dgiot_dtuPublish as device side、dgiotThe platform acts as a server to subscribe
public void ValueChangedCallBack(OpcDaGroup group, OpcDaItemValue[] values)
{
string groupKey = "";
JsonObject properties = new JsonObject();
values.ToList().ForEach(v =>
{
if (v.Item != null && v.Value != null)
{
properties.Add(v.Item.ItemId, v.Value);
groupKey = v.Item.UserData as string;
OpcDa.setItems(groupKey, v.Item.ItemId, properties);
}
});
string topic = "$dg/thing/" + productId + "/" + devAddr + "/properties/report";
MqttClientHelper.Publish(topic, Encoding.UTF8.GetBytes(properties.ToString()));
return;
}
COPY3.平台通过dlinkConvert data points
在dgiotWhen receiving subscription information,在dink中调用on_message_publish来匹配topictype for point-to-point conversion
on_message_publish(Message = #message{topic = <<"$dg/thing/", Topic/binary>>, payload = Payload, from = _ClientId, headers = _Headers}, _State) ->
case re:split(Topic, <<"/">>) of
[ProductId, DevAddr, <<"properties">>, <<"report">>] ->
dgiot_dlink_proctol:properties_report(ProductId, DevAddr, get_payload(Payload));
[ProductId, DevAddr, <<"firmware">>, <<"report">>] ->
dgiot_dlink_proctol:firmware_report(ProductId, DevAddr, get_payload(Payload));
_ ->
pass
end,
{ok, Message};COPY4. 平台通过task将数据存入TD,并使用mqttReport to the object model
After completing the point conversion,将数据存入TD数据库、At the same time, the data is also reported to the object model display
save_td(ProductId, DevAddr, Ack, AppData) ->
case length(maps:to_list(Ack)) of
0 ->
#{};
_ ->
NewAck = dgiot_task:get_collection(ProductId, [], Ack, Ack),
NewData = dgiot_task:get_calculated(ProductId, NewAck),
Keys = dgiot_product:get_keys(ProductId),
DeviceId = dgiot_parse_id:get_deviceid(ProductId, DevAddr),
Interval = maps:get(<<"interval">>, AppData, 3),
AllData = merge_cache_data(DeviceId, NewData, Interval),
AllDataKey = maps:keys(AllData),
case Keys -- AllDataKey of
List when length(List) == 0 andalso length(AllDataKey) =/= 0 ->
ChannelId = dgiot_parse_id:get_channelid(dgiot_utils:to_binary(?BRIDGE_CHL), <<"DGIOTTOPO">>, <<"TOPO组态通道"/utf8>>),
dgiot_channelx:do_message(ChannelId, {topo_thing, ProductId, DeviceId, AllData}),
dgiot_tdengine_adapter:save(ProductId, DevAddr, AllData),
Channel = dgiot_product:get_taskchannel(ProductId),
dgiot_bridge:send_log(Channel, ProductId, DevAddr, "~s ~p save td => ProductId ~p DevAddr ~p ~ts ", [?FILE, ?LINE, ProductId, DevAddr, unicode:characters_to_list(jsx:encode(AllData))]),
dgiot_metrics:inc(dgiot_task, <<"task_save">>, 1),
NotificationTopic = <<"$dg/user/alarm/", ProductId/binary, "/", DeviceId/binary, "/properties/report">>,
dgiot_mqtt:publish(DeviceId, NotificationTopic, jsx:encode(AllData)),
AllData;
_ ->
save_cache_data(DeviceId, AllData),
AllData
end
end.
COPY5.Platform configuration object model and data display

[小 迪 点评]
- 鉴此,dgiotSpecifically provided based onOPC通讯的OPC接口,以实现OPCSimple transfer of data,解决行业痛点.
边栏推荐
- 8.9模拟赛总结
- LeetCode-2. Add Two Numbers
- 神经网络全连接层的作用,各种神经网络的优缺点
- How to generate code using the Swift Package plugin
- LeetCode-1. Two Sum
- 剑指OfferⅡ 045.二叉树最底层最左边的值 dfs
- bp神经网络反向传播原理,BP神经网络反向传播
- 一张图快速了解 Istio 的 EnvoyFilter
- 2022 CCF China Open Source Conference Notice (Fourth Round)
- 64位 RT-Thread 移植到 Cortex-A53 系统 bug 修复笔记
猜你喜欢
随机推荐
TradingView_学习笔记
sprintboot验证码kaptcha 自定义图片样式
Embedded Development: Embedded Basics - Mapping Peripherals Using Arrays of Pointers
阿里工作7年,肝到P8就剩这份学习笔记了,已助朋友拿到10个Offer
Lua--table操作
建筑施工员证怎么考?报名条件及报考时间是什么?
MySQL数据库完全备份与增量备份怎么实现
【云原生| Docker】 部署 Django & mysql 项目
电力系统潮流计算与PowerWorld仿真(牛顿拉夫逊法和高斯赛德尔法)(Matlab实现)
shell中判断文件目录是否存在
document.title获取当前网页的标题
让页面滚动到指定位置
数学基础(五)最优化理论(最优化,无约束,有约束,拉格朗日乘子的意义,KKT条件)
【JDK】Oracle又一个JDK大版本停止扩展技术支持
事务的隔离级别,MySQL的默认隔离级别
v-model指令:获取和设置表单元素的值
leetcode:337. 打家劫舍 III
JNDI与RMI、LDAP
v-bind指令:设置元素的属性
深度学习培训二笔记









