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
e908ea8a
Commit
e908ea8a
authored
Jan 30, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up debug log
parent
86365c21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 additions
and
45 deletions
+1
-45
coordinator.js
+1
-29
flowagent.js
+0
-15
mqttclient.js
+0
-1
No files found.
coordinator.js
View file @
e908ea8a
module
.
exports
.
create
=
create
const
DEBUG_SUBLIST
=
tru
e
;
const
DEBUG_SUBLIST
=
fals
e
;
const
events
=
require
(
'events'
);
const
cache
=
require
(
'./cache'
);
...
...
@@ -165,72 +165,44 @@ const Coordinator = function(param={}) {
});
this
.
remoteclient
.
on
(
'message'
,
function
(
topic
,
payload
){
console
.
log
(
"Incoming MQTT message-------------------------------------------------"
);
console
.
log
({
topic
,
payload
:
payload
.
toString
()
})
let
jsonpayload
=
{};
try
{
jsonpayload
=
JSON
.
parse
(
payload
.
toString
());
}
catch
(
e
)
{}
if
(
topic
.
startsWith
(
'@shadow/data/updated'
))
{
let
newpayload
=
cache
.
mergeShadow
(
jsonpayload
.
deviceid
,
jsonpayload
);
// that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/merged`, JSON.stringify(newpayload) );
// that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/updated`, JSON.stringify(jsonpayload) );
that
.
flowemitter
.
pub
(
`flow:shadow:
${
jsonpayload
.
deviceid
}
`
,
{
// shadowupdated : JSON.stringify(jsonpayload),
// shadowmerged : JSON.stringify(newpayload)
shadowupdated
:
jsonpayload
,
shadowmerged
:
newpayload
});
}
else
if
(
topic
.
startsWith
(
'@device/status/changed'
)){
cache
.
setStatus
(
jsonpayload
.
deviceid
,
jsonpayload
);
//that.flowemitter.publish(`${jsonpayload.deviceid}/device/changed`, JSON.stringify(jsonpayload));
that
.
flowemitter
.
pub
(
`flow:device:
${
jsonpayload
.
deviceid
}
`
,
{
//devicechanged : JSON.stringify(jsonpayload)
devicechanged
:
jsonpayload
});
}
else
if
(
topic
.
startsWith
(
'@private/shadow/data/get/response'
)){
cache
.
setShadow
(
jsonpayload
.
deviceid
,
jsonpayload
);
//that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/get`, JSON.stringify(jsonpayload));
that
.
flowemitter
.
pub
(
`flow:shadow:
${
jsonpayload
.
deviceid
}
`
,
{
//shadowget : JSON.stringify(jsonpayload)
shadowget
:
jsonpayload
});
}
else
if
(
topic
.
startsWith
(
'@private/device/status/get/response'
)){
cache
.
setStatus
(
jsonpayload
.
deviceid
,
jsonpayload
);
//that.flowemitter.publish(`${jsonpayload.deviceid}/device/get`, JSON.stringify(jsonpayload));
that
.
flowemitter
.
pub
(
`flow:device:
${
jsonpayload
.
deviceid
}
`
,
{
//deviceget : JSON.stringify(jsonpayload)
deviceget
:
jsonpayload
});
}
else
if
(
topic
.
startsWith
(
'@msg/'
))
{
// let part = topic.split('/').splice(1).join('/');
// let localtopic = `@msg/${part}`;
that
.
flowemitter
.
pub
(
`flow:msg`
,
{
topic
:
topic
,
payload
:
payload
});
// that.flowemitter.publish(`msg:${localtopic}`, {
// msg : {
// localtopic,
// payload
// }
// });
}
});
...
...
flowagent.js
View file @
e908ea8a
...
...
@@ -20,10 +20,6 @@ let FlowAgent = function(option = {}) {
red
:
option
.
red
||
null
}
// if (!this.option.red.flowevents) {
// this.option.red.flowevents = new events.EventEmitter;
// }
this
.
remoteclient
=
MQTTClient
.
create
({
host
:
that
.
option
.
broker_uri
,
options
:
{
...
...
@@ -34,15 +30,6 @@ let FlowAgent = function(option = {}) {
}
});
// console.log({
// host: that.option.broker_uri,
// options: {
// clientId: Date.now()+'-'+that.option.flowagentid,
// username: that.option.flowagentid,
// password: that.option.flowagentsecret,
// keepalive: 30
// }});
this
.
flowemitter
=
FlowEmitter
.
create
({
red
:
this
.
option
.
red
});
this
.
coordinator
=
Coordinatior
.
create
({
remoteclient
:
that
.
remoteclient
,
...
...
@@ -50,8 +37,6 @@ let FlowAgent = function(option = {}) {
});
}
//FlowAgent.prototype = new events.EventEmitter;
FlowAgent
.
prototype
.
on
=
function
(
eventname
,
handler
)
{
this
.
on
(
eventname
,
handler
);
}
...
...
mqttclient.js
View file @
e908ea8a
...
...
@@ -64,4 +64,3 @@ MQTTClient.prototype.unsubscribe = function(topic) {
function
create
(
param
)
{
return
new
MQTTClient
(
param
);
}
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