2019-12-30 17:52:46 [显示全部楼层]
1826浏览
查看: 1826|回复: 1

[项目] IOT-传感值的数据分析

[复制链接]
传感数值的分析预测通常是python来做的。

这次探索用不那么复杂的matlab来做,matlab因其强大的数学运算功能而为各种研究机构使用,学起来也不容易,好在thingspeak和matlab进行了合作,使得问题相对简化
还是用上篇的震动传感IOT。
先看硬件部分
IOT-传感值的数据分析图1
NodeMCU


IOT-传感值的数据分析图2
振动传感
IOT-传感值的数据分析图3
连线图
[mw_shl_code=applescript,true]#include <ESP8266WiFi.h>
String apiKey = "";
const char *ssid = "";
const char *pass = "";
const char* server = "api.thingspeak.com";
WiFiClient client;

//--------------------SETUP---------------
void setup(){
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

}
//--------------LOOP-----------------
void loop(){

float h = analogRead(A0);
if (client.connect(server, 80))
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(h/1023*100);
postStr += "r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Noise Level: ");
Serial.println(h/1023*100);
Serial.println("Data Send to Thingspeak");
}
client.stop();
Serial.println("Waiting...");

// thingspeak needs minimum 15 sec delay between updates.
delay(1500);

  }
[/mw_shl_code]
IOT 代码
IOT-传感值的数据分析图4
串口数据
------------------
然后是thingspeak部分
先登录thingspeak.com
IOT-传感值的数据分析图5
看到图表

IOT-传感值的数据分析图6

这里的两项,matlab analysis是数据分析,MATLAB visual是matlab高级图表展示
IOT-传感值的数据分析图7
上面有一些样例,方面参照。
同时也提供空白代码编辑区,只有你对matlab代码有了解,就可以自己撸码。在我看来m文件和c文件差不多。
[mw_shl_code=applescript,true]% Read raw data for the past day from a ThingSpeak channel and
% visualize hourly number of vibs using the AREA function.

   
% Channel ID to read data from
readChannelID = 947697;
   
% Channel Read API Key   
% If your channel is private, then enter the read API
% Key between the '' below:   
readAPIKey = '2M1072OYWK9189UU';
   
% Read vib data for the last 33 hours in a timetable, including
% timestamps for each measurement
[data, timeStamps ] = thingSpeakRead(readChannelID, 'Fields', [1], 'NumMinutes', 60,...
                         'ReadKey', readAPIKey, 'Outputformat', 'Timetable');


% Plot the averaged data as an area plot.

xlabel('Time');
ylabel('Average Number');
[/mw_shl_code]
简单写一段,应该可以看到坐标了。如果需要对比分析,需要两项测量指标。会用到数学公式。当然,这里只能温习了一些数学。

IOT-传感值的数据分析图8
下方有一行,是提供了matlab表也的url。这样方便第三方工具进行调用
例如用MIT app inventor可以很快写个app,用手机去打开matlab表页
IOT-传感值的数据分析图9
IOT-传感值的数据分析图10


kylinpoet  初级技神

发表于 2020-2-18 16:05:04

这个好,必须支持。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail