Now we have a working front end its time to get the backend working. Handleling mqtt is simple enough on node the hard bit is sorting out this Jason file.
Here is our node red sketch http://cup.eu-gb.mybluemix.net/red/
Duncan found a file storage on bluemix that would allow use to save and then view the Jason file. Once we had that we could look through the file and find the information we want. However the problem remains of how to pull the data out and use it as neither of us have worked with Jason files before. With the help of simon we found out that to pull the information we just pull it out like an array , which did mean counting down what sections we needed. After that using the information was straight forward.
Here is the code we used to pull the file
var openPercent = msg.insights.children[0].children[0].children[0].percentage;
var conPercent = msg.insights.children[0].children[0].children[1].percentage;
var extraPercent = msg.insights.children[0].children[0].children[2].percentage;
var agreePercent = msg.insights.children[0].children[0].children[3].percentage;
var emoPercent = msg.insights.children[0].children[0].children[4].percentage;
msg.payload = [];
msg.payload.push(openPercent);
msg.payload.push(conPercent);
msg.payload.push(extraPercent);
msg.payload.push(agreePercent);
msg.payload.push(emoPercent);
return msg;
I than made a small java script file to take that information and work out the highest strength and send that down to mqtt.
if (msg.payload[0]>msg.payload[1]&& msg.payload[0] >msg.payload[2]&& msg.payload[0]>msg.payload[3]&& msg.payload[0] >msg.payload[4]){
msg.payload = "open";
}
else if (msg.payload[1]>msg.payload[0]&& msg.payload[1] >msg.payload[2]&& msg.payload[1] >msg.payload[3]&& msg.payload[1] >msg.payload[4]){
msg.payload="con";
}
else if (msg.payload[2]>msg.payload[1]&& msg.payload[2]>msg.payload[0]&& msg.payload[2] >msg.payload[3]&& msg.payload[2] >msg.payload[4]){
msg.payload="extra";
}
else if (msg.payload[3]>msg.payload[1] && msg.payload[3] >msg.payload[0]&& msg.payload[3]>msg.payload[2]&& msg.payload[3]>msg.payload[4]){
msg.payload="agree";
}
else if (msg.payload[4]>msg.payload[1]&& msg.payload[4] >msg.payload[0]&& msg.payload[4] >msg.payload[2]&& msg.payload[4]>msg.payload[3]){
msg.payload="emo";
}
return msg;
This was the hardest node red sketch I have ever made, this was due to the use of a Jason file. The personality insight node could be improved but does work very well.