Commit 14eab3de by Martin Kotula

Adjusted to hub contract

parent 83dda3db
......@@ -17,11 +17,19 @@ define(["app/config", "app/events", "mqtt", "lodash", "knockout", "knockout-post
try{
console.debug("Mqtt message received: " + message.toString());
var messageBody = JSON.parse(message.toString());
if(messageBody.id === undefined || messageBody.isOccupied === undefined){
if(messageBody.object === undefined ||
messageBody.object.sensorid === undefined ||
messageBody.object.isbusy === undefined ){
throw "InvalidMessageFormat";
}
ko.postbox.publish(events.sensorUpdate, _.merge(messageBody, { timestamp: new Date()}));
var model = {
id: messageBody.object.sensorid,
isOccupied: messaegeBody.object.isbusy,
timestamp: new Date()
};
ko.postbox.publish(events.sensorUpdate, model);
}
catch(e){
console.error("Failed to parse message into JSON: [" + message.toString() + "]: " + e);
......
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