您的 Node.js 服务器提供的网页是使用 BoostrapJS 和 AngularJS 开发的简单SPA。网页将尝试使用WebSocket连接连接到服务器,之后它将发送自己的注册消息,因此服务器可以将其套接字添加到其数据库中。
来自ESP8266但由后端服务器转发的加速度值的入口点是:
socket.on('acc_data' , function(data)
{
for(var i=O; i < $scope.myacc_col1ection.length; i++)
{
if (data.acc_data.device_name == $scope.myacc_collection[i].acc_id)
{
$scope.myacc_collection[i].x = Number(data.acc_data.x);
$scope.myacc_collection[i].y = Number(data.acc_data.y);
$scope.myacc_collection[i].z = Number(data.acc_data.z);
var currentDate = new Date().getTime( );
$scope.myacc_collection[ i].axeX.append(currentDate, Number(data.acc_data.x));
$scope.myacc_collection[i].axeY.append(currentDate, Number(data.acc_data.y));
$scope.myacc_collection[i].axeZ.append(currentDate, Number(data.acc_data.z));
return;
}
}
});
此函数从服务器接收实际数据,并使用 append 函数将X,Y和Z加速度的值添加到 smoothie.js