mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-30 11:17:48 +08:00
fix:td通道gps修改
This commit is contained in:
parent
35bf461c7a
commit
63880f886d
@ -666,7 +666,7 @@ get_tddata(Channel, Acc, #{<<"objectId">> := DeviceId} = Device, #{<<"objectId">
|
||||
#{<<"properties">> := Properties} when length(Properties) > 0 ->
|
||||
case dgiot_tdengine:get_device(Channel, ProdcutId, DeviceId, DeviceId, #{<<"keys">> => <<"last_row(*)">>, <<"limit">> => 1}) of
|
||||
{ok, #{<<"results">> := [Data1 | _]}} ->
|
||||
%% lager:info("Data1 ~p",[Data1]),
|
||||
%% ?LOG(info,"Data1 ~p",[Data1]),
|
||||
[dgiot_tdengine:to_unixtime(maps:get(<<"createdat">>, Data1)), Data1];
|
||||
_ -> [0, #{}]
|
||||
end;
|
||||
|
@ -32,10 +32,9 @@
|
||||
|
||||
%% 注册通道类型
|
||||
-channel_type(#{
|
||||
|
||||
cType => ?TYPE,
|
||||
type => ?BACKEND_CHL,
|
||||
priority => 1,
|
||||
priority => 2,
|
||||
title => #{
|
||||
zh => <<"Device缓存通道"/utf8>>
|
||||
},
|
||||
|
@ -304,11 +304,11 @@ nmea0183_frame(<<"$GNRMC,", Data:60/binary, "*", _Checksum:2/binary, _/binary>>)
|
||||
|
||||
LatDu = dgiot_utils:to_float(LatDu1),
|
||||
LatFen = dgiot_utils:to_float(LatFen1),
|
||||
Latitude = dgiot_utils:to_float(LatDu + LatFen / 60, 5),
|
||||
Latitude = dgiot_utils:to_float(LatDu + LatFen / 60, 9),
|
||||
|
||||
LongDu = dgiot_utils:to_float(LongDu1),
|
||||
LongFen = dgiot_utils:to_float(LongFen1),
|
||||
Longitude = dgiot_utils:to_float(LongDu + LongFen / 60, 5),
|
||||
Longitude = dgiot_utils:to_float(LongDu + LongFen / 60, 9),
|
||||
|
||||
{dgiot_utils:to_binary(Longitude), dgiot_utils:to_binary(Latitude)};
|
||||
|
||||
|
1
apps/dgiot_jieshun
Submodule
1
apps/dgiot_jieshun
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit b3eee7b9db6f24801bf099fa0d87a5309ba02a40
|
1
apps/dgiot_mingcheng
Submodule
1
apps/dgiot_mingcheng
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a6de4b4ca4c4c6d6cbda8d834097e70612b046ae
|
@ -32,8 +32,9 @@
|
||||
%% 注册通道类型
|
||||
-channel(?TYPE).
|
||||
-channel_type(#{
|
||||
cType => ?BACKEND_CHL,
|
||||
type => 1,
|
||||
cType => ?TYPE,
|
||||
type => ?BACKEND_CHL,
|
||||
priority => 1,
|
||||
title => #{
|
||||
zh => <<"Parser Server存储通道"/utf8>>
|
||||
},
|
||||
|
6
apps/dgiot_shouyincheng/.gitignore
vendored
Normal file
6
apps/dgiot_shouyincheng/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.eunit
|
||||
deps
|
||||
*.o
|
||||
*.beam
|
||||
*.plt
|
||||
erl_crash.dump
|
201
apps/dgiot_shouyincheng/LICENSE
Normal file
201
apps/dgiot_shouyincheng/LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
24
apps/dgiot_shouyincheng/Makefile
Normal file
24
apps/dgiot_shouyincheng/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
PROJECT = shuwa_modbus
|
||||
PROJECT_DESCRIPTION = shuwa_modbus Protocol Plugin
|
||||
PROJECT_VERSION = 1.5.4
|
||||
|
||||
CUR_BRANCH := $(shell git branch | grep -e "^*" | cut -d' ' -f 2)
|
||||
BRANCH := $(if $(filter $(CUR_BRANCH), master develop), $(CUR_BRANCH), develop)
|
||||
|
||||
BUILD_DEPS = emqx cuttlefish lager
|
||||
dep_emqx = git-emqx https://github.com/emqx/emqx $(BRANCH)
|
||||
dep_cuttlefish = git-emqx https://github.com/emqx/cuttlefish v2.2.1
|
||||
dep_lager = git https://github.com/basho/lager master
|
||||
|
||||
DIALYZER_DIRS := ebin/
|
||||
DIALYZER_OPTS := --verbose --statistics -Werror_handling \
|
||||
-Wrace_conditions #-Wunmatched_returns
|
||||
|
||||
ERLC_OPTS += +'{parse_transform, lager_transform}'
|
||||
|
||||
include erlang.mk
|
||||
|
||||
app:: rebar.config
|
||||
|
||||
app.config::
|
||||
./deps/cuttlefish/cuttlefish -l info -e etc/ -c etc/shuwa_modbus.conf -d data
|
4
apps/dgiot_shouyincheng/README.md
Normal file
4
apps/dgiot_shouyincheng/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
## dgiot_shouyincheng
|
||||
|
||||
dgiot_shouyincheng
|
||||
|
0
apps/dgiot_shouyincheng/etc/dgiot_shouyincheng.conf
Normal file
0
apps/dgiot_shouyincheng/etc/dgiot_shouyincheng.conf
Normal file
16
apps/dgiot_shouyincheng/include/dgiot_shouyincheng.hrl
Normal file
16
apps/dgiot_shouyincheng/include/dgiot_shouyincheng.hrl
Normal file
@ -0,0 +1,16 @@
|
||||
-define(DGIOT_SHOUYINCHENG_TCP_DTU, dgiot_shouyincheng_tcp_dtu).
|
||||
-record(state, {
|
||||
id,
|
||||
devaddr = <<>>,
|
||||
heartcount = 0,
|
||||
regtype = <<>>,
|
||||
head = "xxxxxx0eee",
|
||||
len = 0,
|
||||
app = <<>>,
|
||||
product = <<>>,
|
||||
deviceId = <<>>,
|
||||
scale = 10,
|
||||
temperature = 0,
|
||||
env = <<>>,
|
||||
dtutype = <<>>
|
||||
}).
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"definitions": {},
|
||||
"paths": {
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"description": "dgiot_shouyincheng",
|
||||
"name": "dgiot_shouyincheng"
|
||||
}
|
||||
]
|
||||
}
|
8
apps/dgiot_shouyincheng/src/dgiot_shouyincheng.app.src
Normal file
8
apps/dgiot_shouyincheng/src/dgiot_shouyincheng.app.src
Normal file
@ -0,0 +1,8 @@
|
||||
{application, dgiot_shouyincheng,
|
||||
[{description, "DGIOT SHOUYINCHENG"},
|
||||
{vsn, "4.3.0"},
|
||||
{modules, []},
|
||||
{registered, [dgiot_shouyincheng_sup]},
|
||||
{applications, [kernel, stdlib, dgiot]},
|
||||
{mod, {dgiot_shouyincheng_app, []}}
|
||||
]}.
|
@ -0,0 +1,25 @@
|
||||
%%-*- mode: erlang -*-
|
||||
%% .app.src.script
|
||||
|
||||
RemoveLeadingV =
|
||||
fun(Tag) ->
|
||||
case re:run(Tag, "v\[0-9\]+\.\[0-9\]+\.*") of
|
||||
nomatch ->
|
||||
Tag;
|
||||
{match, _} ->
|
||||
%% if it is a version number prefixed by 'v' then remove the 'v'
|
||||
"v" ++ Vsn = Tag,
|
||||
Vsn
|
||||
end
|
||||
end,
|
||||
|
||||
case os:getenv("EMQX_DEPS_DEFAULT_VSN") of
|
||||
false -> CONFIG; % env var not defined
|
||||
[] -> CONFIG; % env var set to empty string
|
||||
Tag ->
|
||||
[begin
|
||||
AppConf0 = lists:keystore(vsn, 1, AppConf, {vsn, RemoveLeadingV(Tag)}),
|
||||
{application, App, AppConf0}
|
||||
end || Conf = {application, App, AppConf} <- CONFIG]
|
||||
end.
|
||||
|
64
apps/dgiot_shouyincheng/src/dgiot_shouyincheng.erl
Normal file
64
apps/dgiot_shouyincheng/src/dgiot_shouyincheng.erl
Normal file
@ -0,0 +1,64 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author stoneliu
|
||||
%%% @copyright (C) 2020, <COMPANY>
|
||||
%%% @doc
|
||||
%%% solarPower
|
||||
%%% @end
|
||||
%%% Created : 07. 五月 2021 12:00
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng).
|
||||
-author("stoneliu").
|
||||
-export([parse_frame/2]).
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
|
||||
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3D302E30303030203D302E303030303530303138200D0A">>).
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3D302E303230302D3D302E303130303530303138200D0A">>).
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3D302E30323030203D302E303130303530303138200D0A">>).
|
||||
%% Buff = dgiot_utils:hex_to_binary(<<"3d31312e303230203d30302e3031303530303138200D0A">>).
|
||||
%% Buff = <<"=0.0000 =0.000050018 \r\n">>.
|
||||
%% <<"=", Suttle:6/binary, " ", "=", Tare:5/binary, Y2:1/binary, F1:1/binary, K1:1/binary, K2:1/binary, B1:1/binary, B2:1/binary, C1:1/binary, CR:1/binary, LF:1/binary>> = Buff.
|
||||
parse_frame(<<"=", Suttle:6/binary, Y1:1/binary, "=", Tare:5/binary, _:9/binary>>, #state{product = ProductId}) ->
|
||||
case dgiot_product:lookup_prod(ProductId) of
|
||||
{ok, #{<<"thing">> := #{<<"properties">> := Props}}} ->
|
||||
Ack = lists:foldl(fun(X, Acc) ->
|
||||
case X of
|
||||
#{<<"identifier">> := Identifier,
|
||||
<<"dataForm">> := #{
|
||||
<<"protocol">> := <<"normal">>,
|
||||
<<"address">> := <<"0X01">>,
|
||||
<<"data">> := 6}} ->
|
||||
RelSuttle =
|
||||
case Y1 of
|
||||
<<" ">> ->
|
||||
dgiot_utils:to_float(lists:reverse(dgiot_utils:to_list(Suttle)));
|
||||
<<"-">> ->
|
||||
dgiot_utils:to_float(lists:reverse(dgiot_utils:to_list(<<Suttle/binary, "-">>)));
|
||||
_O ->
|
||||
?LOG(info, "_O ~p", [_O]),
|
||||
<<"0">>
|
||||
end,
|
||||
Acc#{Identifier => RelSuttle};
|
||||
#{<<"identifier">> := Identifier,
|
||||
<<"dataForm">> := #{
|
||||
<<"protocol">> := <<"normal">>,
|
||||
<<"address">> := <<"0X02">>,
|
||||
<<"data">> := 5}} ->
|
||||
RelTare = dgiot_utils:to_float(lists:reverse(dgiot_utils:to_list(Tare))),
|
||||
Acc#{Identifier => RelTare};
|
||||
_Other ->
|
||||
?LOG(info, "_Other ~p", [_Other]),
|
||||
Acc
|
||||
end
|
||||
end, #{}, Props),
|
||||
{params, Ack};
|
||||
_ ->
|
||||
{erroe, #{}}
|
||||
end;
|
||||
|
||||
parse_frame(_Buff, _State) ->
|
||||
{error, <<>>}.
|
||||
|
||||
|
||||
|
31
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_app.erl
Normal file
31
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_app.erl
Normal file
@ -0,0 +1,31 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(dgiot_shouyincheng_app).
|
||||
|
||||
-emqx_plugin(?MODULE).
|
||||
|
||||
-behaviour(application).
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
|
||||
%% Application callbacks
|
||||
-export([start/2, stop/1]).
|
||||
|
||||
start(_StartType, _StartArgs) ->
|
||||
dgiot_shouyincheng_sup:start_link().
|
||||
|
||||
stop(_State) ->
|
||||
ok.
|
184
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_channel.erl
Normal file
184
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_channel.erl
Normal file
@ -0,0 +1,184 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng_channel).
|
||||
-behavior(dgiot_channelx).
|
||||
-author("johnliu").
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
-define(TYPE, <<"YONGKANG">>).
|
||||
%% API
|
||||
-export([start/2]).
|
||||
|
||||
%% Channel callback
|
||||
-export([init/3, handle_init/1, handle_event/3, handle_message/2, stop/3]).
|
||||
|
||||
%% 注册通道类型
|
||||
-channel(?TYPE).
|
||||
-channel_type(#{
|
||||
type => 1,
|
||||
title => #{
|
||||
zh => <<"收银秤通道"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"收银秤通道"/utf8>>
|
||||
}
|
||||
}).
|
||||
%% 注册通道参数
|
||||
-params(#{
|
||||
<<"port">> => #{
|
||||
order => 1,
|
||||
type => integer,
|
||||
required => true,
|
||||
default => 20110,
|
||||
title => #{
|
||||
zh => <<"端口"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"侦听端口"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"regtype">> => #{
|
||||
order => 2,
|
||||
type => string,
|
||||
required => true,
|
||||
default => <<"上传Mac"/utf8>>,
|
||||
title => #{
|
||||
zh => <<"注册类型"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"上传Mac"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"regular">> => #{
|
||||
order => 3,
|
||||
type => string,
|
||||
required => true,
|
||||
default => <<"9C-A5-25-**-**-**">>,
|
||||
title => #{
|
||||
zh => <<"登录报文帧头"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"填写正则表达式匹配login"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"dtutype">> => #{
|
||||
order => 4,
|
||||
type => string,
|
||||
required => true,
|
||||
default => <<"usr">>,
|
||||
title => #{
|
||||
zh => <<"控制器厂商"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
zh => <<"控制器厂商"/utf8>>
|
||||
}
|
||||
},
|
||||
<<"ico">> => #{
|
||||
order => 102,
|
||||
type => string,
|
||||
required => false,
|
||||
default => <<"http://dgiot-1253666439.cos.ap-shanghai-fsi.myqcloud.com/shuwa_tech/zh/product/dgiot/channel/modbus.png">>,
|
||||
title => #{
|
||||
en => <<"channel ICO">>,
|
||||
zh => <<"通道ICO"/utf8>>
|
||||
},
|
||||
description => #{
|
||||
en => <<"channel ICO">>,
|
||||
zh => <<"通道ICO"/utf8>>
|
||||
}
|
||||
}
|
||||
}).
|
||||
|
||||
start(ChannelId, ChannelArgs) ->
|
||||
dgiot_channelx:add(?TYPE, ChannelId, ?MODULE, ChannelArgs).
|
||||
|
||||
%% 通道初始化
|
||||
init(?TYPE, ChannelId, #{
|
||||
<<"port">> := Port,
|
||||
<<"regtype">> := Type,
|
||||
<<"regular">> := Regular,
|
||||
<<"product">> := Products,
|
||||
<<"dtutype">> := Dtutype
|
||||
} = _Args) ->
|
||||
[{ProdcutId, App} | _] = get_app(Products),
|
||||
{Header, Len} = get_header(Regular),
|
||||
State = #state{
|
||||
id = ChannelId,
|
||||
regtype = Type,
|
||||
head = Header,
|
||||
len = Len,
|
||||
app = App,
|
||||
product = ProdcutId,
|
||||
dtutype = Dtutype
|
||||
},
|
||||
|
||||
%% dgiot_data:insert({ChannelId, heartbeat}, {Heartbeat, Port}),
|
||||
{ok, State, dgiot_shouyincheng_tcp:start(Port, State)};
|
||||
|
||||
init(?TYPE, _ChannelId, _Args) ->
|
||||
{ok, #{}, #{}}.
|
||||
|
||||
handle_init(State) ->
|
||||
{ok, State}.
|
||||
|
||||
%% 通道消息处理,注意:进程池调用
|
||||
handle_event(_EventId, _Event, State) ->
|
||||
{ok, State}.
|
||||
|
||||
% SELECT clientid, payload, topic FROM "meter"
|
||||
% SELECT clientid, disconnected_at FROM "$events/client_disconnected" WHERE username = 'dgiot'
|
||||
% SELECT clientid, connected_at FROM "$events/client_connected" WHERE username = 'dgiot'
|
||||
handle_message({rule, #{clientid := DevAddr, connected_at := _ConnectedAt}, #{peername := PeerName} = _Context}, State) ->
|
||||
?LOG(error, "DevAddr ~p PeerName ~p", [DevAddr, PeerName]),
|
||||
{ok, State};
|
||||
|
||||
handle_message({rule, #{clientid := DevAddr, disconnected_at := _DisconnectedAt}, _Context}, State) ->
|
||||
?LOG(error, "DevAddr ~p ", [DevAddr]),
|
||||
{ok, State};
|
||||
|
||||
handle_message({rule, #{clientid := DevAddr, payload := Payload, topic := _Topic}, _Msg}, #state{id = ChannelId} = State) ->
|
||||
?LOG(error, "DevAddr ~p Payload ~p ChannelId ~p", [DevAddr, Payload, ChannelId]),
|
||||
{ok, State};
|
||||
|
||||
handle_message(_Message, State) ->
|
||||
{ok, State}.
|
||||
|
||||
stop(_ChannelType, _ChannelId, _State) ->
|
||||
ok.
|
||||
|
||||
get_app(Products) ->
|
||||
lists:map(fun({ProdcutId, #{<<"ACL">> := Acl}}) ->
|
||||
Predicate = fun(E) ->
|
||||
case E of
|
||||
<<"role:", _/binary>> -> true;
|
||||
_ -> false
|
||||
end
|
||||
end,
|
||||
[<<"role:", App/binary>> | _] = lists:filter(Predicate, maps:keys(Acl)),
|
||||
{ProdcutId, App}
|
||||
end, Products).
|
||||
|
||||
|
||||
|
||||
get_header(Regular) ->
|
||||
lists:foldl(fun(X, {Header, Len}) ->
|
||||
case X of
|
||||
"**" -> {Header, Len + length(X)};
|
||||
"*" -> {Header, Len + length(X)};
|
||||
_ -> {Header ++ X, Len + length(X)}
|
||||
end
|
||||
end, {[], 0},
|
||||
re:split(dgiot_utils:to_list(Regular), "-", [{return, list}])).
|
34
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_sup.erl
Normal file
34
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_sup.erl
Normal file
@ -0,0 +1,34 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(dgiot_shouyincheng_sup).
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
|
||||
%% Supervisor callbacks
|
||||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
{ok, {{one_for_one, 5, 10}, []}}.
|
||||
|
||||
|
171
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_tcp.erl
Normal file
171
apps/dgiot_shouyincheng/src/dgiot_shouyincheng_tcp.erl
Normal file
@ -0,0 +1,171 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng_tcp).
|
||||
-author("stoneliu").
|
||||
-include("dgiot_shouyincheng.hrl").
|
||||
-include_lib("dgiot/include/dgiot_socket.hrl").
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
|
||||
-define(MAX_BUFF_SIZE, 1024).
|
||||
|
||||
-export([
|
||||
get_deviceid/2,
|
||||
start/2
|
||||
]).
|
||||
|
||||
%% TCP callback
|
||||
-export([init/1, handle_info/2, handle_cast/2, handle_call/3, terminate/2, code_change/3]).
|
||||
|
||||
start(Port, State) ->
|
||||
dgiot_tcp_server:child_spec(?MODULE, dgiot_utils:to_int(Port), State).
|
||||
|
||||
%% =======================
|
||||
%% {ok, State} | {stop, Reason}
|
||||
%%init(TCPState) ->
|
||||
%% erlang:send_after(5 * 1000, self(), login),.
|
||||
%% {ok, TCPState}.
|
||||
|
||||
init(#tcp{state = #state{id = ChannelId}} = TCPState) ->
|
||||
?LOG(info, "ChannelId ~p", [ChannelId]),
|
||||
case dgiot_bridge:get_products(ChannelId) of
|
||||
{ok, _TYPE, _ProductIds} ->
|
||||
{ok, TCPState};
|
||||
{error, not_find} ->
|
||||
{stop, not_find_channel}
|
||||
end.
|
||||
|
||||
%% 9C A5 25 CD 00 DB
|
||||
%% 11 04 02 06 92 FA FE
|
||||
handle_info({tcp, Buff}, #tcp{socket = Socket, state = #state{id = ChannelId, devaddr = <<>>, head = Head, len = Len, product = ProductId, dtutype = Dtutype} = State} = TCPState) ->
|
||||
dgiot_bridge:send_log(ChannelId, "DTU revice from ~p", [dgiot_utils:binary_to_hex(Buff)]),
|
||||
DTUIP = dgiot_utils:get_ip(Socket),
|
||||
DtuAddr = dgiot_utils:binary_to_hex(Buff),
|
||||
List = dgiot_utils:to_list(DtuAddr),
|
||||
List1 = dgiot_utils:to_list(Buff),
|
||||
#{<<"objectId">> := DeviceId} =
|
||||
dgiot_parse:get_objectid(<<"Device">>, #{<<"product">> => ProductId, <<"devaddr">> => DtuAddr}),
|
||||
case re:run(DtuAddr, Head, [{capture, first, list}]) of
|
||||
{match, [Head]} when length(List) == Len ->
|
||||
{DevId, Devaddr} =
|
||||
case create_device(DeviceId, ProductId, DtuAddr, DTUIP, Dtutype) of
|
||||
{<<>>, <<>>} ->
|
||||
{<<>>, <<>>};
|
||||
{DevId1, Devaddr1} ->
|
||||
{DevId1, Devaddr1}
|
||||
end,
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{devaddr = Devaddr, deviceId = DevId}}};
|
||||
_Error ->
|
||||
case re:run(Buff, Head, [{capture, first, list}]) of
|
||||
{match, [Head]} when length(List1) == Len ->
|
||||
create_device(DeviceId, ProductId, Buff, DTUIP, Dtutype),
|
||||
{noreply, TCPState#tcp{buff = <<>>, state = State#state{devaddr = Buff}}};
|
||||
Error1 ->
|
||||
?LOG(info, "Error1 ~p Buff ~p ", [Error1, dgiot_utils:to_list(Buff)]),
|
||||
{noreply, TCPState#tcp{buff = <<>>}}
|
||||
end
|
||||
end;
|
||||
|
||||
%% 3D302E30303030203D302E303030303530303138200D0A
|
||||
handle_info({tcp, Buff}, #tcp{state = #state{id = ChannelId, devaddr = DevAddr, product = ProductId} = State} = TCPState) ->
|
||||
dgiot_bridge:send_log(ChannelId, "revice from ~p", [Buff]),
|
||||
?LOG(info, "revice from ~p~n", [Buff]),
|
||||
?LOG(info, "Devaddr ~p~n", [DevAddr]),
|
||||
?LOG(info, "DtuProductId ~p~n", [ProductId]),
|
||||
case dgiot_shouyincheng:parse_frame(Buff, State) of
|
||||
{params, Data} ->
|
||||
?LOG(info, "Data ~p~n", [Data]),
|
||||
dgiot_tdengine_adapter:save(ProductId, DevAddr, Data);
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
{noreply, TCPState};
|
||||
|
||||
handle_info({deliver, _, _Msg}, #tcp{state = #state{id = _ChannelId} = _State} = TCPState) ->
|
||||
|
||||
{noreply, TCPState};
|
||||
%% {stop, TCPState} | {stop, Reason} | {ok, TCPState} | ok | stop
|
||||
handle_info(_Info, TCPState) ->
|
||||
?LOG(info, "TCPState ~p", [TCPState]),
|
||||
{noreply, TCPState}.
|
||||
|
||||
handle_call(_Msg, _From, TCPState) ->
|
||||
{reply, ok, TCPState}.
|
||||
|
||||
handle_cast(_Msg, TCPState) ->
|
||||
{noreply, TCPState}.
|
||||
|
||||
terminate(_Reason, _TCPState) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, TCPState, _Extra) ->
|
||||
{ok, TCPState}.
|
||||
|
||||
get_deviceid(ProdcutId, DevAddr) ->
|
||||
#{<<"objectId">> := DeviceId} =
|
||||
dgiot_parse:get_objectid(<<"Device">>, #{<<"product">> => ProdcutId, <<"devaddr">> => DevAddr}),
|
||||
DeviceId.
|
||||
|
||||
create_device(DeviceId, ProductId, DTUMAC, DTUIP, Dtutype) ->
|
||||
case dgiot_parse:get_object(<<"Product">>, ProductId) of
|
||||
{ok, #{<<"ACL">> := Acl, <<"devType">> := DevType}} ->
|
||||
case dgiot_parse:get_object(<<"Device">>, DeviceId) of
|
||||
{ok, #{<<"devaddr">> := _GWAddr}} ->
|
||||
dgiot_parse:update_object(<<"Device">>, DeviceId, #{<<"ip">> => DTUIP, <<"status">> => <<"ONLINE">>});
|
||||
_ ->
|
||||
dgiot_device:create_device(#{
|
||||
<<"devaddr">> => DTUMAC,
|
||||
<<"name">> => <<Dtutype/binary, DTUMAC/binary>>,
|
||||
<<"ip">> => DTUIP,
|
||||
<<"isEnable">> => true,
|
||||
<<"product">> => ProductId,
|
||||
<<"ACL">> => Acl,
|
||||
<<"status">> => <<"ONLINE">>,
|
||||
<<"location">> => #{<<"__type">> => <<"GeoPoint">>, <<"longitude">> => 120.161324, <<"latitude">> => 30.262441},
|
||||
<<"brand">> => Dtutype,
|
||||
<<"devModel">> => DevType
|
||||
})
|
||||
end,
|
||||
Productname =
|
||||
case dgiot_parse:get_object(<<"Product">>, ProductId) of
|
||||
{ok, #{<<"name">> := Productname1}} ->
|
||||
Productname1;
|
||||
_ ->
|
||||
<<"">>
|
||||
end,
|
||||
?MLOG(info, #{<<"clientid">> => DeviceId, <<"devaddr">> => DTUMAC, <<"productid">> => ProductId, <<"productname">> => Productname, <<"devicename">> => <<Dtutype/binary, DTUMAC/binary>>, <<"status">> => <<"上线"/utf8>>}, ['device_statuslog']),
|
||||
{DeviceId, DTUMAC};
|
||||
Error2 ->
|
||||
?LOG(info, "Error2 ~p ", [Error2]),
|
||||
{<<>>, <<>>}
|
||||
end.
|
||||
|
||||
%%create_instruct(ACL, DtuProductId, DtuDevId) ->
|
||||
%% case dgiot_product:lookup_prod(DtuProductId) of
|
||||
%% {ok, #{<<"thing">> := #{<<"properties">> := Properties}}} ->
|
||||
%% lists:map(fun(Y) ->
|
||||
%% case Y of
|
||||
%% #{<<"dataForm">> := #{<<"slaveid">> := 256}} -> %%不做指令
|
||||
%% pass;
|
||||
%% #{<<"dataForm">> := #{<<"slaveid">> := SlaveId}} ->
|
||||
%% Pn = dgiot_utils:to_binary(SlaveId),
|
||||
%%%% ?LOG(info,"DtuProductId ~p DtuDevId ~p Pn ~p ACL ~p", [DtuProductId, DtuDevId, Pn, ACL]),
|
||||
%%%% ?LOG(info,"Y ~p", [Y]),
|
||||
%% dgiot_instruct:create(DtuProductId, DtuDevId, Pn, ACL, <<"all">>, #{<<"properties">> => [Y]});
|
||||
%% _ -> pass
|
||||
%% end
|
||||
%% end, Properties);
|
||||
%% _ -> pass
|
||||
%% end.
|
@ -0,0 +1,85 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(dgiot_shouyincheng_handler).
|
||||
-author("stoneliu").
|
||||
-behavior(dgiot_rest).
|
||||
-dgiot_rest(all).
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
|
||||
%% API
|
||||
-export([swagger_shouyincheng_tcp/0]).
|
||||
-export([handle/4]).
|
||||
|
||||
%% API描述
|
||||
%% 支持二种方式导入
|
||||
%% 示例:
|
||||
%% 1. Metadata为map表示的JSON,
|
||||
%% dgiot_http_server:bind(<<"/pump">>, ?MODULE, [], Metadata)
|
||||
%% 2. 从模块的priv/swagger/下导入
|
||||
%% dgiot_http_server:bind(<<"/swagger_shouyincheng.json">>, ?MODULE, [], priv)
|
||||
swagger_shouyincheng_tcp() ->
|
||||
[
|
||||
dgiot_http_server:bind(<<"/swagger_shouyincheng.json">>, ?MODULE, [], priv)
|
||||
].
|
||||
|
||||
|
||||
%%%===================================================================
|
||||
%%% 请求处理
|
||||
%%% 如果登录, Context 内有 <<"user">>, version
|
||||
%%%===================================================================
|
||||
|
||||
-spec handle(OperationID :: atom(), Args :: map(), Context :: map(), Req :: dgiot_req:req()) ->
|
||||
{Status :: dgiot_req:http_status(), Body :: map()} |
|
||||
{Status :: dgiot_req:http_status(), Headers :: map(), Body :: map()} |
|
||||
{Status :: dgiot_req:http_status(), Headers :: map(), Body :: map(), Req :: dgiot_req:req()}.
|
||||
|
||||
handle(OperationID, Args, Context, Req) ->
|
||||
Headers = #{},
|
||||
case catch do_request(OperationID, Args, Context, Req) of
|
||||
{ErrType, Reason} when ErrType == 'EXIT'; ErrType == error ->
|
||||
?LOG(info, "do request: ~p, ~p, ~p~n", [OperationID, Args, Reason]),
|
||||
Err = case is_binary(Reason) of
|
||||
true -> Reason;
|
||||
false ->
|
||||
dgiot_ctl:format("~p", [Reason])
|
||||
end,
|
||||
{500, Headers, #{<<"error">> => Err}};
|
||||
ok ->
|
||||
%% ?LOG(debug,"do request: ~p, ~p ->ok ~n", [OperationID, Args]),
|
||||
{200, Headers, #{}, Req};
|
||||
{ok, Res} ->
|
||||
%% ?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
|
||||
{200, Headers, Res, Req};
|
||||
{Status, Res} ->
|
||||
%% ?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
|
||||
{Status, Headers, Res, Req};
|
||||
{Status, NewHeaders, Res} ->
|
||||
%% ?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
|
||||
{Status, maps:merge(Headers, NewHeaders), Res, Req}
|
||||
end.
|
||||
|
||||
|
||||
%%%===================================================================
|
||||
%%% 内部函数 Version:API版本
|
||||
%%%===================================================================
|
||||
|
||||
|
||||
%% PumpTemplet 概要: 新增报告模板 描述:新增报告模板
|
||||
%% OperationId:post_pump_templet
|
||||
%% 请求:get /iotapi/pump/templet
|
||||
%% 服务器不支持的API接口
|
||||
do_request(_OperationId, _Args, _Context, _Req) ->
|
||||
{error, <<"Not Allowed.">>}.
|
@ -280,7 +280,7 @@ alter_table(DB1, TableName, Context, Channel) ->
|
||||
<<"url">> ->
|
||||
<<"ALTER TABLE ", DB1/binary, TableName/binary, " ADD COLUMN ", LowerIdentifier/binary, " NCHAR(10);">>;
|
||||
<<"geopoint">> ->
|
||||
<<"ALTER TABLE ", DB1/binary, TableName/binary, " ADD COLUMN ", LowerIdentifier/binary, " NCHAR(20);">>;
|
||||
<<"ALTER TABLE ", DB1/binary, TableName/binary, " ADD COLUMN ", LowerIdentifier/binary, " NCHAR(30);">>;
|
||||
_ ->
|
||||
<<"ALTER TABLE ", DB1/binary, TableName/binary, " ADD COLUMN ", LowerIdentifier/binary, " ", Type/binary, ";">>
|
||||
end,
|
||||
|
@ -505,7 +505,7 @@ get_field(#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">> := <<"text
|
||||
Size = integer_to_binary(min(maps:get(<<"size">>, Spec, 10), 200)),
|
||||
{Field, #{<<"type">> => <<"NCHAR(", Size/binary, ")">>}};
|
||||
get_field(#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">> := <<"geopoint">>} = Spec}) ->
|
||||
Size = integer_to_binary(min(maps:get(<<"size">>, Spec, 20), 200)),
|
||||
Size = integer_to_binary(min(maps:get(<<"size">>, Spec, 30), 200)),
|
||||
{Field, #{<<"type">> => <<"NCHAR(", Size/binary, ")">>}};
|
||||
get_field(#{<<"identifier">> := Field, <<"dataType">> := #{<<"type">> := <<"enum">>, <<"specs">> := _Specs}}) ->
|
||||
%% Size = integer_to_binary(maps:size(Specs)),
|
||||
|
@ -330,7 +330,7 @@ get_chart(ProductId, Results, Names, Interval) ->
|
||||
|
||||
get_app(ProductId, Results, DeviceId) ->
|
||||
Maps = get_prop(ProductId),
|
||||
Props = get_props(<<"4f0931b623">>),
|
||||
Props = get_props(ProductId),
|
||||
lists:foldl(fun(R, _Acc) ->
|
||||
Time = maps:get(<<"createdat">>, R),
|
||||
NewTime = get_time(Time, <<"111">>),
|
||||
|
1
apps/dgiot_xinchuangwei
Submodule
1
apps/dgiot_xinchuangwei
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 126d77b1aa052fa0d2856cf7f2afcfcfbeb875e4
|
Loading…
Reference in New Issue
Block a user