{"id":292,"date":"2022-07-15T17:46:50","date_gmt":"2022-07-15T09:46:50","guid":{"rendered":"https:\/\/www.dgiotcloud.cn\/en\/?p=292"},"modified":"2022-07-15T17:55:58","modified_gmt":"2022-07-15T09:55:58","slug":"dg-iot%e6%8f%92%e4%bb%b6%e6%9c%ba%e5%88%b6","status":"publish","type":"post","link":"https:\/\/www.dgiotcloud.cn\/en\/?p=292","title":{"rendered":"DG-IoT\u63d2\u4ef6\u673a\u5236"},"content":{"rendered":"<p>\u63d2\u4ef6\u673a\u5236<br \/>\n\u76ee\u5f55\u7ed3\u6784<br \/>\nrebar3\u63d2\u4ef6\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<p>dgiot<\/p>\n<p>|\u2014\u2014lib<\/p>\n<p>|-dgiot_demoplugin<\/p>\n<p>|- ebin<\/p>\n<p>|- dgiot_demopugin.app<\/p>\n<ul>\n<li>\n<p>dgiot_demoplugin.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_demoplugin_app.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_demoplugin_sup.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_demonplugin_channel.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_demonplugin_handler.beam<\/p>\n<\/li>\n<\/ul>\n<p>-dgiot_otherplugin<\/p>\n<p>|- ebin<\/p>\n<p>|- dgiot_otherplugin.app<\/p>\n<ul>\n<li>\n<p>dgiot_otherplugin.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_otherplugin_app.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_otherplugin_sup.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_otherplugin_channel.beam<\/p>\n<\/li>\n<li>\n<p>dgiot_otherplugin_handler.beam<br \/>\n\u793a\u4f8b\u4ee3\u7801<\/p>\n<\/li>\n<\/ul>\n<p>%%%-------------------------------------------------------------------<\/p>\n<p>%%% @author johnliu<\/p>\n<p>%%% @copyright (C) 2021, <COMPANY><\/p>\n<p>%%% @doc<\/p>\n<p>%%%<\/p>\n<p>%%% @end<\/p>\n<p>%%% Created : 24. 3\u6708 2021 10:17<\/p>\n<p>%%%-------------------------------------------------------------------<\/p>\n<p>-module(dgiot_demonplugin_channel).<\/p>\n<p>-author(&quot;johnliu&quot;).<\/p>\n<p>-behavior(dgiot_channelx).<\/p>\n<p>-include(&quot;dgiot_demonplugin.hrl&quot;).<\/p>\n<p>-define(TYPE, &lt;&lt;&quot;demonplugin&quot;&gt;&gt;).<\/p>\n<p>-record(state, {id}).<\/p>\n<p>%% API<\/p>\n<p>-export([<\/p>\n<p>start\/2<\/p>\n<p>]).<\/p>\n<p>%% Channel callback<\/p>\n<p>-export([init\/3, handle_init\/1, handle_event\/3, handle_message\/2, stop\/3]).<\/p>\n<p>-channel(?TYPE).<\/p>\n<p>-channel_type(#{<\/p>\n<p>type =&gt; 1,<\/p>\n<p>title =&gt; #{<\/p>\n<p>zh =&gt; &lt;&lt;&quot;demonplugin\u901a\u9053&quot;\/utf8&gt;&gt;<\/p>\n<p>},<\/p>\n<p>description =&gt; #{<\/p>\n<p>zh =&gt; &lt;&lt;&quot;demonplugin\u901a\u9053&quot;\/utf8&gt;&gt;<\/p>\n<p>}<\/p>\n<p>}).<\/p>\n<p>%% \u6ce8\u518c\u901a\u9053\u53c2\u6570<\/p>\n<p>-params(#{<\/p>\n<p>&lt;&lt;&quot;port&quot;&gt;&gt; =&gt; #{<\/p>\n<p>order =&gt; 2,<\/p>\n<p>type =&gt; integer,<\/p>\n<p>required =&gt; true,<\/p>\n<p>default =&gt; 51889,<\/p>\n<p>title =&gt; #{<\/p>\n<p>zh =&gt; &lt;&lt;&quot;\u670d\u52a1\u5668\u7aef\u53e3&quot;\/utf8&gt;&gt;<\/p>\n<p>},<\/p>\n<p>description =&gt; #{<\/p>\n<p>zh =&gt; &lt;&lt;&quot;\u670d\u52a1\u5668\u7aef\u53e3&quot;\/utf8&gt;&gt;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}).<\/p>\n<p>start(ChannelId, ChannelArgs) -&gt;<\/p>\n<p>dgiot_channelx:add(?TYPE, ChannelId, ?MODULE, ChannelArgs).<\/p>\n<p>%% \u901a\u9053\u521d\u59cb\u5316<\/p>\n<p>init(?TYPE, ChannelId, Args) -&gt;<\/p>\n<h1>{<\/h1>\n<p>&lt;&lt;&quot;ip&quot;&gt;&gt; := Ip,<\/p>\n<p>&lt;&lt;&quot;port&quot;&gt;&gt; := Port,<\/p>\n<p>&lt;&lt;&quot;total&quot;&gt;&gt; := Total} = Args,<\/p>\n<p>do_something(&lt;&lt;&quot;hello plugin&quot;&gt;&gt;),<\/p>\n<p>State = #state{<\/p>\n<p>id = ChannelId<\/p>\n<p>},<\/p>\n<p>{ok, State, []}.<\/p>\n<p>handle_init(State) -&gt;<\/p>\n<p>{ok, State}.<\/p>\n<p>%% \u901a\u9053\u6d88\u606f\u5904\u7406,\u6ce8\u610f\uff1a\u8fdb\u7a0b\u6c60\u8c03\u7528<\/p>\n<p>handle_event(_EventId, Event, State) -&gt;<\/p>\n<p>lager:info(&quot;channel ~p&quot;, [Event]),<\/p>\n<p>{ok, State}.<\/p>\n<p>handle_message(_Message, State) -&gt;<\/p>\n<p>{ok, State}.<\/p>\n<p>stop(ChannelType, ChannelId, _State) -&gt;<\/p>\n<p>ok.<\/p>\n<p>do_something(Msg) -&gt;<\/p>\n<p>io:format(&quot;Msg ~p&quot;,[Msg]).<br \/>\nCOPY<br \/>\n\u52a0\u8f7d\u673a\u5236<br \/>\n\u641c\u7d22\u5230\u6240\u6709\u5df2\u7ecf\u52a0\u8f7d\u7684\u63d2\u4ef6<br \/>\napplication:loaded_applications()<\/p>\n<p>\u901a\u8fc7App\u540d\u79f0\u641c\u7d22ebin\u4e0b\u9762\u6240\u6709\u7684beam\u6587\u4ef6<br \/>\nfile:list_dir(Dir)<\/p>\n<p>\u641c\u7d20\u5bf9\u5e94beam\u6587\u4ef6\u5185\u7684attributes\u662f\u5426\u5305\u542bchannel<br \/>\nMod:module_info(attributes)<\/p>\n<p>\u5982\u679c\u6709channele\u7684attributes\u5219\u542f\u52a8\u63d2\u4ef6<br \/>\nMod:start(ChannelId, ChannelArgs)<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>%%%-------------------------------------------------------------------<\/p>\n<p>%%% @author johnliu<\/p>\n<p>%%% @copyright (C) 2019, <COMPANY><\/p>\n<p>%%% @doc<\/p>\n<p>%%%<\/p>\n<p>%%% @end<\/p>\n<p>%%% Created : 06. \u516b\u6708 2019 18:00<\/p>\n<p>%%%-------------------------------------------------------------------<\/p>\n<p>-module(dgiot_plugin).<\/p>\n<p>-author(&quot;johnliu&quot;).<\/p>\n<p>-define(SYS_APP, [<\/p>\n<p>kernel, stdlib, sasl<\/p>\n<p>]).<\/p>\n<p>-export([start\/0])<\/p>\n<p>start() -&gt;<\/p>\n<p>check_module(<\/p>\n<p>fun({_App, _Vsn, Mod}, Acc) -&gt;<\/p>\n<p>case code:is_loaded(Mod) =\/= false of<\/p>\n<p>true -&gt;<\/p>\n<p>case lists:keyfind(channel, 1, Mod:module_info(attributes)) of<\/p>\n<p>false -&gt;<\/p>\n<p>Acc;<\/p>\n<p>{channel, ChannelTypes} -&gt;<\/p>\n<p>do_somthing()<\/p>\n<p>end;<\/p>\n<p>false -&gt;<\/p>\n<p>Acc<\/p>\n<p>end<\/p>\n<p>end, []).<\/p>\n<p>check_module(Check, Acc0) -&gt;<\/p>\n<p>Fun =<\/p>\n<p>fun({App, _Desc, Vsn}, Acc) -&gt;<\/p>\n<p>Dir = lists:concat([&quot;lib\/&quot;, App, &quot;-&quot;, Vsn, &quot;\/ebin&quot;]),<\/p>\n<p>case not lists:member(App, ?SYS_APP) andalso file:list_dir(Dir) of<\/p>\n<p>{ok, FS} -&gt;<\/p>\n<p>lists:foldl(<\/p>\n<p>fun(FileName, Acc1) -&gt;<\/p>\n<p>case filename:extension(FileName) == &quot;.beam&quot; of<\/p>\n<p>true -&gt;<\/p>\n<p>Mod = list_to_atom(filename:basename(FileName, &quot;.beam&quot;)),<\/p>\n<p>Check({App, Vsn, Mod}, Acc1);<\/p>\n<p>false -&gt;<\/p>\n<p>Acc1<\/p>\n<p>end<\/p>\n<p>end, Acc, FS);<\/p>\n<p>_ -&gt;<\/p>\n<p>Acc<\/p>\n<p>end<\/p>\n<p>end,<\/p>\n<p>lists:foldl(Fun, Acc0, application:loaded_applications()).<\/p>\n<p>do_somthing() -&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63d2\u4ef6\u673a\u5236 \u76ee\u5f55\u7ed3\u6784 rebar3\u63d2\u4ef6\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a dgiot |\u2014\u2014lib |-dgiot_demoplug [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":225,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/posts\/292"}],"collection":[{"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":2,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions\/294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=\/wp\/v2\/media\/225"}],"wp:attachment":[{"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dgiotcloud.cn\/en\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}