Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cascade-examples
rigado-node-hello-world-frontend
Commits
eeb5d563
Commit
eeb5d563
authored
Apr 12, 2018
by
Vladimir Kiryakov
Browse files
handle json shape
parent
4c351de1
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/middlewares/mqtt.js
View file @
eeb5d563
...
...
@@ -45,12 +45,15 @@ const mqttMiddleware = (function () {
const
message
=
msg
.
toString
();
if
(
config
.
debug
)
console
.
info
(
'
MQTT: Message recieved.
\n
Topic: %s
\n
Payload: %s
'
,
topic
,
message
);
if
(
_
.
isEqual
(
topic
,
msgTopic
))
{
const
json
=
_
.
attempt
(()
=>
JSON
.
parse
(
message
.
message
),
{});
messages
.
push
({
topic
,
message
:
_
.
get
(
json
,
'
payload
'
),
timestamp
:
_
.
get
(
json
,
'
timestamp
'
)
});
const
json
=
_
.
attempt
(()
=>
JSON
.
parse
(
message
),
{});
const
payload
=
_
.
get
(
json
,
'
payload
'
);
if
(
payload
)
{
messages
.
push
({
topic
,
payload
:
_
.
attempt
(()
=>
JSON
.
stringify
(
json
),
message
),
timestamp
:
_
.
get
(
json
,
'
timestamp
'
)
});
}
store
.
dispatch
(
changeConnectionStatus
(
_
.
get
(
json
,
'
status
'
)));
}
});
...
...
src/modules/MQTT/components/SubscriptionView/index.js
View file @
eeb5d563
...
...
@@ -29,7 +29,7 @@ const SubscriptionView = ({className, messages, displayType}) => {
<
MessageContent
>
{
_
.
isEqual
(
'
json
'
,
displayType
)
?
<
ReactJson
src
=
{
_
.
attempt
(()
=>
JSON
.
parse
(
message
.
message
),
{})}
/> : message.
message
}
src
=
{
_
.
attempt
(()
=>
JSON
.
parse
(
message
.
payload
),
{})}
/> : message.
payload
}
<
/MessageContent
>
<
/Message
>
)
...
...
src/reducers/mqtt.js
View file @
eeb5d563
...
...
@@ -34,12 +34,12 @@ export default (state = {
case
MQTT_PUSH_MESSAGES
:
const
newAccelXYZBData
=
action
.
payload
.
messages
.
map
((
i
)
=>
{
const
obj
=
_
.
attempt
(()
=>
JSON
.
parse
(
i
.
message
),
{});
const
x
=
_
.
get
(
obj
,
'
accel.x
'
);
const
y
=
_
.
get
(
obj
,
'
accel.y
'
);
const
z
=
_
.
get
(
obj
,
'
accel.z
'
);
const
obj
=
_
.
attempt
(()
=>
JSON
.
parse
(
i
.
payload
),
{});
const
x
=
_
.
get
(
obj
,
'
payload.
accel.x
'
);
const
y
=
_
.
get
(
obj
,
'
payload.
accel.y
'
);
const
z
=
_
.
get
(
obj
,
'
payload.
accel.z
'
);
const
timestamp
=
_
.
get
(
obj
,
'
timestamp
'
);
const
button
=
_
.
get
(
obj
,
'
button
'
);
const
button
=
_
.
get
(
obj
,
'
payload.
button
'
);
if
(
x
&&
y
&&
z
)
{
return
[
x
,
y
,
z
,
timestamp
,
button
];
}
...
...
@@ -72,7 +72,8 @@ export default (state = {
return
{
...
state
,
isConnected
:
false
,
isConnectInProcess
:
false
isConnectInProcess
:
false
,
connectionStatus
:
GATEWAY_DISCONNECTED
};
case
MQTT_FORM_TOGGLE
:
return
{
...
...
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