Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
flowagent
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node-red
flowagent
Commits
9c029cc7
Commit
9c029cc7
authored
Dec 03, 2019
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add working flowagent with debug log
parent
90979b08
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletions
+27
-1
coordinator.js
+26
-0
mqttserver.js
+1
-1
No files found.
coordinator.js
View file @
9c029cc7
...
...
@@ -56,6 +56,19 @@ const Coordinator = function(param={}) {
}
});
this
.
localserver
.
on
(
'clientSubscribed'
,
function
(
packet
,
client
)
{
let
deviceid
=
client
.
id
.
split
(
':'
)[
0
];
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
if
(
packet
.
topic
.
startsWith
(
'@msg/'
))
{
let
msgpart
=
packet
.
topic
.
split
(
'/'
).
splice
(
3
).
join
(
'/'
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
msgpart
}
`
;
that
.
remoteclient
.
subscribe
(
outtopic
);
}
else
{
}
});
this
.
localserver
.
on
(
'clientPublished'
,
function
(
packet
,
client
){
console
.
log
(
'client published'
,
client
.
id
);
...
...
@@ -78,6 +91,13 @@ const Coordinator = function(param={}) {
outmsg
=
packet
.
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
break
;
default
:
if
(
packet
.
topic
.
startsWith
(
'@msg/'
))
{
let
part
=
packet
.
topic
.
substr
(
5
);
outtopic
=
`@tap/msg/topic/
${
deviceid
}
:
${
client
.
token
}
/
${
part
}
`
;
outmsg
=
packet
.
payload
.
toString
();
that
.
remoteclient
.
publish
(
outtopic
,
outmsg
);
}
}
});
...
...
@@ -123,6 +143,12 @@ const Coordinator = function(param={}) {
cache
.
setStatus
(
jsonpayload
.
deviceid
,
jsonpayload
);
that
.
localserver
.
publish
(
`
${
jsonpayload
.
deviceid
}
/device/get`
,
JSON
.
stringify
(
jsonpayload
));
}
else
if
(
topic
.
startsWith
(
'@msg/'
))
{
console
.
log
(
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
)
console
.
log
({
topic
,
payload
})
that
.
localserver
.
publish
(
topic
,
payload
);
}
});
}
...
...
mqttserver.js
View file @
9c029cc7
...
...
@@ -39,7 +39,7 @@ MQTTServer.prototype.start = function() {
that
.
emit
(
'clientSubscribed'
,{
deviceid
:
client
.
id
,
topic
:
topic
});
}
,
client
);
});
this
.
mqttserver
.
on
(
'unsubscribed'
,
function
(
topic
,
client
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment