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
aa9f8e03
Commit
aa9f8e03
authored
Nov 10, 2019
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0df933eb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletions
+15
-1
coordinator.js
+10
-0
mqttclient.js
+1
-1
mqttserver.js
+4
-0
No files found.
coordinator.js
View file @
aa9f8e03
...
@@ -20,6 +20,15 @@ const Coordinator = function(param={}) {
...
@@ -20,6 +20,15 @@ const Coordinator = function(param={}) {
that
.
remoteclient
.
subscribe
(
`->tap/device/
${
deviceid
}
:
${
client
.
token
}
`
);
that
.
remoteclient
.
subscribe
(
`->tap/device/
${
deviceid
}
:
${
client
.
token
}
`
);
});
});
this
.
localserver
.
on
(
'clientDisconnected'
,
function
(
client
){
console
.
log
(
'client disconnected'
,
client
.
id
);
let
deviceid
=
client
.
id
.
split
(
':'
)[
0
];
that
.
remoteclient
.
unsubscribe
(
`->tap/shadow/
${
deviceid
}
:
${
client
.
token
}
`
);
that
.
remoteclient
.
unsubscribe
(
`->tap/device/
${
deviceid
}
:
${
client
.
token
}
`
);
});
this
.
remoteclient
.
on
(
'message'
,
function
(
topic
,
payload
){
this
.
remoteclient
.
on
(
'message'
,
function
(
topic
,
payload
){
let
jsonpayload
=
{};
let
jsonpayload
=
{};
try
{
try
{
...
@@ -27,6 +36,7 @@ const Coordinator = function(param={}) {
...
@@ -27,6 +36,7 @@ const Coordinator = function(param={}) {
}
}
catch
(
e
)
{}
catch
(
e
)
{}
//console.log('incoming message ', topic, jsonpayload)
if
(
topic
==
'@shadow/data/updated'
)
{
if
(
topic
==
'@shadow/data/updated'
)
{
that
.
localserver
.
publish
(
`
${
jsonpayload
.
deviceid
}
/shadow`
,
payload
.
toString
());
that
.
localserver
.
publish
(
`
${
jsonpayload
.
deviceid
}
/shadow`
,
payload
.
toString
());
}
}
...
...
mqttclient.js
View file @
aa9f8e03
...
@@ -37,7 +37,6 @@ MQTTClient.prototype.publish = function(topic, payload) {
...
@@ -37,7 +37,6 @@ MQTTClient.prototype.publish = function(topic, payload) {
this
.
client
.
publish
(
topic
,
payload
);
this
.
client
.
publish
(
topic
,
payload
);
}
}
else
{
else
{
}
}
}
}
...
@@ -51,6 +50,7 @@ MQTTClient.prototype.subscribe = function(topic) {
...
@@ -51,6 +50,7 @@ MQTTClient.prototype.subscribe = function(topic) {
}
}
function
create
(
param
)
{
function
create
(
param
)
{
return
new
MQTTClient
(
param
);
return
new
MQTTClient
(
param
);
}
}
...
...
mqttserver.js
View file @
aa9f8e03
...
@@ -30,6 +30,10 @@ MQTTServer.prototype.start = function() {
...
@@ -30,6 +30,10 @@ MQTTServer.prototype.start = function() {
that
.
emit
(
'clientConnected'
,
client
);
that
.
emit
(
'clientConnected'
,
client
);
});
});
this
.
mqttserver
.
on
(
'clientDisconnected'
,
function
(
client
,
reason
)
{
that
.
emit
(
'clientDisconnected'
,
client
,
reason
);
});
this
.
mqttserver
.
on
(
'subscribed'
,
function
(
topic
,
client
)
{
this
.
mqttserver
.
on
(
'subscribed'
,
function
(
topic
,
client
)
{
that
.
emit
(
'clientSubscribed'
,{
that
.
emit
(
'clientSubscribed'
,{
deviceid
:
client
.
id
,
deviceid
:
client
.
id
,
...
...
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