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
86365c21
Commit
86365c21
authored
Jan 30, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ae98af36
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
11 deletions
+15
-11
coordinator.js
+14
-10
flowagent.js
+1
-1
No files found.
coordinator.js
View file @
86365c21
...
@@ -99,17 +99,14 @@ const Coordinator = function(param={}) {
...
@@ -99,17 +99,14 @@ const Coordinator = function(param={}) {
outmsg = packet.payload.toString();
outmsg = packet.payload.toString();
that.remoteclient.publish(outtopic, outmsg);
that.remoteclient.publish(outtopic, outmsg);
}
}
}
}
});
});
*/
*/
this
.
flowemitter
.
on
(
'flowpub'
,
function
(
topic
,
payload
,
client
){
this
.
flowemitter
.
on
(
'flowpub'
,
function
(
topic
,
payload
,
client
){
console
.
log
(
'client published'
,
client
.
id
);
//console.log('client published', client.id);
let
outtopic
,
outmsg
;
let
outtopic
,
outmsg
;
let
deviceid
=
client
.
id
;
let
deviceid
=
client
.
id
;
switch
(
topic
)
{
switch
(
topic
)
{
case
'@shadow/data/update'
:
case
'@shadow/data/update'
:
outtopic
=
`@tap/shadow/update/
${
deviceid
}
:
${
client
.
token
}
`
;
outtopic
=
`@tap/shadow/update/
${
deviceid
}
:
${
client
.
token
}
`
;
...
@@ -139,7 +136,7 @@ const Coordinator = function(param={}) {
...
@@ -139,7 +136,7 @@ const Coordinator = function(param={}) {
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
this
.
flowemitter
.
on
(
'flowsub'
,
function
(
topic
,
client
)
{
let
deviceid
=
client
.
id
.
split
(
':'
)[
0
]
;
let
deviceid
=
client
.
id
;
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
if
(
topic
.
startsWith
(
'@local/msgin/'
))
{
let
msgpart
=
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
let
msgpart
=
topic
.
split
(
'/'
).
splice
(
4
).
join
(
'/'
);
...
@@ -169,12 +166,19 @@ const Coordinator = function(param={}) {
...
@@ -169,12 +166,19 @@ const Coordinator = function(param={}) {
this
.
remoteclient
.
on
(
'message'
,
function
(
topic
,
payload
){
this
.
remoteclient
.
on
(
'message'
,
function
(
topic
,
payload
){
console
.
log
(
"Incoming MQTT message-------------------------------------------------"
);
console
.
log
({
topic
,
payload
:
payload
.
toString
()
})
let
jsonpayload
=
{};
let
jsonpayload
=
{};
try
{
try
{
jsonpayload
=
JSON
.
parse
(
payload
.
toString
());
jsonpayload
=
JSON
.
parse
(
payload
.
toString
());
}
}
catch
(
e
)
{}
catch
(
e
)
{}
if
(
topic
.
startsWith
(
'@shadow/data/updated'
))
{
if
(
topic
.
startsWith
(
'@shadow/data/updated'
))
{
let
newpayload
=
cache
.
mergeShadow
(
jsonpayload
.
deviceid
,
jsonpayload
);
let
newpayload
=
cache
.
mergeShadow
(
jsonpayload
.
deviceid
,
jsonpayload
);
// that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/merged`, JSON.stringify(newpayload) );
// that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/merged`, JSON.stringify(newpayload) );
...
@@ -213,11 +217,11 @@ const Coordinator = function(param={}) {
...
@@ -213,11 +217,11 @@ const Coordinator = function(param={}) {
});
});
}
}
else
if
(
topic
.
startsWith
(
'@msg/'
))
{
else
if
(
topic
.
startsWith
(
'@msg/'
))
{
let
part
=
topic
.
split
(
'/'
).
splice
(
1
).
join
(
'/'
);
//
let part = topic.split('/').splice(1).join('/');
let
localtopic
=
`@local/msgin
/
${
part
}
`
;
// let localtopic = `@msg
/${part}`;
that
.
flowemitter
.
pub
(
`flow:m
essage
`
,
{
that
.
flowemitter
.
pub
(
`flow:m
sg
`
,
{
topic
:
local
topic
,
topic
:
topic
,
payload
:
payload
payload
:
payload
});
});
...
...
flowagent.js
View file @
86365c21
...
@@ -20,7 +20,7 @@ let FlowAgent = function(option = {}) {
...
@@ -20,7 +20,7 @@ let FlowAgent = function(option = {}) {
red
:
option
.
red
||
null
red
:
option
.
red
||
null
}
}
//
if (!this.option.red.flowevents) {
//
if (!this.option.red.flowevents) {
// this.option.red.flowevents = new events.EventEmitter;
// this.option.red.flowevents = new events.EventEmitter;
// }
// }
...
...
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