Commit eeb5d563 authored by Vladimir Kiryakov's avatar Vladimir Kiryakov
Browse files

handle json shape

parent 4c351de1
......@@ -45,12 +45,15 @@ const mqttMiddleware = (function () {
const message = msg.toString();
if (config.debug) console.info('MQTT: Message recieved.\nTopic: %s\nPayload: %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')));
}
});
......
......@@ -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>
)
......
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment