Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pi.hub
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
iot
pi.hub
Commits
453ce884
Commit
453ce884
authored
Jun 26, 2017
by
Martin Kotula
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug-fixes and example data
parent
33115e06
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
5 deletions
+39
-5
UI.Web.Dashboard/src/pages/home/home.js
+15
-1
UI.Web.Dashboard/src/pages/test/test.html
+14
-0
UI.Web.Dashboard/src/services/mqttListener.js
+10
-4
No files found.
UI.Web.Dashboard/src/pages/home/home.js
View file @
453ce884
...
@@ -4,7 +4,8 @@ define([
...
@@ -4,7 +4,8 @@ define([
"components/sensor/sensorViewModel"
,
"components/sensor/sensorViewModel"
,
"queryHandlers/sensorReadingsQueryHandler"
,
"queryHandlers/sensorReadingsQueryHandler"
,
"services/mqttListener"
,
"services/mqttListener"
,
"lodash"
"lodash"
,
"knockout-postbox"
],
function
(
],
function
(
ko
,
ko
,
homeTemplate
,
homeTemplate
,
...
@@ -23,6 +24,8 @@ define([
...
@@ -23,6 +24,8 @@ define([
var
mqttListener
=
new
MqttListener
();
var
mqttListener
=
new
MqttListener
();
mqttListener
.
init
();
mqttListener
.
init
();
ko
.
postbox
.
subscribe
(
"sensorUpdate"
,
_
.
bind
(
this
.
onSensorUpdated
,
this
));
}
}
HomeViewModel
.
prototype
.
addSensor
=
function
(
key
,
sensorData
)
{
HomeViewModel
.
prototype
.
addSensor
=
function
(
key
,
sensorData
)
{
...
@@ -41,6 +44,16 @@ define([
...
@@ -41,6 +44,16 @@ define([
}
}
}
}
HomeViewModel
.
prototype
.
onSensorUpdated
=
function
(
data
){
var
key
=
data
.
name
;
if
(
this
.
sensorsDict
[
key
]){
this
.
updateSensor
(
key
,
data
);
}
else
{
this
.
addSensor
(
key
,
data
);
}
}
HomeViewModel
.
prototype
.
refresh
=
function
()
{
HomeViewModel
.
prototype
.
refresh
=
function
()
{
this
.
isRefreshing
(
true
);
this
.
isRefreshing
(
true
);
this
.
queryHandler
.
handle
().
then
(
_
.
bind
(
function
(
data
)
{
this
.
queryHandler
.
handle
().
then
(
_
.
bind
(
function
(
data
)
{
...
@@ -53,6 +66,7 @@ define([
...
@@ -53,6 +66,7 @@ define([
}
else
{
}
else
{
this
.
addSensor
(
key
,
latestReading
);
this
.
addSensor
(
key
,
latestReading
);
}
}
},
this
));
},
this
));
this
.
isRefreshing
(
false
);
this
.
isRefreshing
(
false
);
},
this
));
},
this
));
...
...
UI.Web.Dashboard/src/pages/test/test.html
View file @
453ce884
...
@@ -4,3 +4,16 @@
...
@@ -4,3 +4,16 @@
<input
data-bind=
"textInput : inputText"
type=
"text"
/>
<input
data-bind=
"textInput : inputText"
type=
"text"
/>
<button
data-bind=
"click: publish"
type=
"button"
>
Publish
</button>
<button
data-bind=
"click: publish"
type=
"button"
>
Publish
</button>
<h3>
Example data
</h3>
<pre>
{ "name": "Sensor 1", "isOccupied": true, "timestamp": "2017-06-17T21:10:59.948Z"}
{ "name": "Sensor 2", "isOccupied": true, "timestamp": "2017-06-17T21:10:59.948Z"}
{ "name": "Sensor 1", "isOccupied": true, "timestamp": "2017-06-17T21:11:59.948Z"}
{ "name": "Sensor 2", "isOccupied": true, "timestamp": "2017-06-17T21:11:59.948Z"}
{ "name": "Sensor 1", "isOccupied": true, "timestamp": "2017-06-17T21:12:59.948Z"}
{ "name": "Sensor 1", "isOccupied": false, "timestamp": "2017-06-17T21:13:59.948Z"}
{ "name": "Sensor 3", "isOccupied": false, "timestamp": "2017-06-17T21:13:59.948Z"}
{ "name": "Sensor 3", "isOccupied": true, "timestamp": "2017-06-17T21:13:59.949Z"}
</pre>
\ No newline at end of file
UI.Web.Dashboard/src/services/mqttListener.js
View file @
453ce884
...
@@ -14,11 +14,17 @@ define(["app/config", "mqtt", "lodash", "knockout", "knockout-postbox"], functio
...
@@ -14,11 +14,17 @@ define(["app/config", "mqtt", "lodash", "knockout", "knockout-postbox"], functio
this
.
client
.
on
(
'message'
,
function
(
topic
,
message
)
{
this
.
client
.
on
(
'message'
,
function
(
topic
,
message
)
{
// message is Buffer
// message is Buffer
var
messegeBody
=
JSON
.
parse
(
message
.
toString
());
try
{
console
.
debug
(
"Mqtt message received: "
+
message
.
toString
());
var
messegeBody
=
JSON
.
parse
(
message
.
toString
());
ko
.
postbox
.
publish
(
"sensorUpdate"
,
messegeBody
);
console
.
debug
(
"Mqtt message received: "
+
message
.
toString
());
ko
.
postbox
.
publish
(
"sensorUpdate"
,
messegeBody
);
}
catch
(
e
){
console
.
error
(
"Failed to parse message into JSON: ["
+
message
.
toString
()
+
"]"
);
}
});
});
}
}
;
MqttListener
.
prototype
.
end
=
function
(){
MqttListener
.
prototype
.
end
=
function
(){
if
(
this
.
client
){
if
(
this
.
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