亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Manufacturing Technology >> 制造工艺

家居智能家居

组件和用品

Raspberry Pi 2 B 型
橙色 PI 也可以
× 1
Xbee
× 1
Arduino UNO
× 1

应用和在线服务

Microsoft Azure

关于这个项目

简介

让我们看看使用联发科技 Linkit 设置智能家居系统需要什么。由于这里有很多专家会指导您进行硬件连接以读取传感器数据,因此我将专注于创建 api 并设置超低成本的 15 美元本地服务器来捕获您的所有传感器数据。或者,我将数据记录为 azure。

设置

传感器使用 xbee 或任何低成本收发器通过无线电信号将数据传输到 MediaTek LinkIt。联发科 link 它接收所有原始传感器数据,使用 adruinojson 库将其打包成 json 对象,并向本地服务器发出 POST 请求。本地服务器托管 nodejs Web 应用程序,并以 json 对象的形式接收所有传感器数据。

本地服务器被用作预处理器并添加 utc 时间和签名。任何数据验证、转换和过滤都可以在这里处理。在我们的案例 azure 存储服务中,本地服务器将所有数据记录到云服务。或者,联发科 linkIt 可以直接将 json 对象发布到 azure 存储服务。我设置了一个本地服务器只是为了证明一台 15 美元的电脑可以足够强大来处理我们的数据。即使在我们的本地服务器中,我们也可以将我们的数据记录到任何 no-sql 数据库中,完全消除了对外部云存储的需求。我把这一切留给你们。

演示

 

先决条件

我假设您知道如何使用传感器和微控制器(如 arduino 或 MediaTek)读取传感器数据。为了限制这个项目的范围,我将假设传感器数据可用于联发科技 Link It。您可以使用低广播无线电收发器或 Xbee 来传输和接收来自连接到微控制器(如联发科)的传感器的无线电信号。初学者可以使用联发科linkIt槽入门套件读取温度、湿度、光线等外部环境数据。

Json Json Json

Json 已成为物联网事实上的标准并被广泛采用。说了先决条件之后,让我们开始建模我们的传感器数据。主要目的是捕获尽可能多的数据并将其传递给服务器。服务器可以完成所有繁重的工作,例如分析、数据转换、机器学习等。

'想要的' json 对象将是传感器数据的所需状态。例如,当我们记录温度时,想要的值 24 意味着我们需要将值与 24 的值同步到云端。我们的客户端(如 Web 应用程序或移动应用程序)将更新为该值。

当我们想打开一盏灯时,我们说,所需的状态为开。这意味着灯已打开或将打开。我们所有的客户端应用程序都将使用此状态来反映对用户的更改。我的意思是,我们网络应用中的图标将被打开或关闭。

这不是国际标准,我只是想出了这个。所以,请随意使用您自己方便的格式。

温度

{ "deviceid" :"iot/myhome/livingroom/thermostat""desired" :{ "温度":"24", "湿度":"80"}, "timeutc":"2015-11 -23T00:41:48.824Z", "singedBy" :"localserver"} 

麦克风

{ "deviceid" :"iot/myhome/livingroom/mic""desired" :{"intensity" :"66"}, "timeutc":"2015-11-23T00:41:48.824Z" , "singedBy" :"localserver"} 

距离

{ "deviceid" :"iot/myhome/livingroom/obstacle""desired" :{"proximity" :"150"}, "timeutc":"2015-01-01", "singedBy" :“本地服务器”} 

红外线

{ "deviceid" :"iot/myhome/livingroom/pir""desired" :{"motion start" :"2500", "motion end" :"5345"}, "timeutc":"2015 -11-23T00:41:48.824Z", "singedBy" :"localserver"} 

全球定位系统

{"deviceid" :"iot/mydevice/location""desired" :{"lat" :"25.5", "long" :"32.2"},"timeutc":"2015-11-23T00 :41:48.824Z","singedBy" :"localserver"} 

水分

{"deviceid" :"/iot/myhome/garden/moisture""desired" :{"moisture":"20"},"timeutc":"2015-11-23T00:41:48.824Z ","singedBy" :"localserver"} 

气体

{"deviceid" :" /iot/myhome/kitchen/gas""desired" :{"leak":"No"},"timeutc":"2015-11-23T00:41:48.824Z ","singedBy" :"localserver"} 

{"deviceid" :" /iot/myhome/livingroom/light""desired" :{"intensity":"60"},"timeutc":"2015-11-23T00:41:48.824Z ","singedBy" :"localserver"} 

或者用这个,

客厅

 <代码> { “设备ID”: “/ IOT / MYHOME /客厅”, “期望的”:{ “温度”: “25”, “湿度”: “80”, “窗口”: “开”,“门“: ”闭合“, ”光“: ”80“, ”噪声“:” 低“}}  

卧室

 <代码> { “设备ID”: “/ IOT / MYHOME /卧室”, “期望的”:{ “温度”: “24”, “湿度”: “70”, “窗口”: “闭合”,“门“: ”闭合“, ”光“: ”80“, ”AC:上”, “噪声”: “低”}} “” 

联发科 - 接收器

请参考软件部分附带的 ino 文件将数据记录到本地服务器。传感器数据是模拟的,您可以将实际读数传递给相应的json对象

本地服务器

本地服务器会增加开销,但会在很多方面进行验证。我们可以利用本地服务器作为输出物联网数据的预处理器。数据可以过滤、时间戳和签名

微型 PC 和 nodejs 是本地服务器的绝佳选择。我们可以选择任何小型电脑,如 raspberry pi、odriod、banana pi、beagle bone 等。我为这个项目选择了 Orange pi(15 美元)。

设置

Raspberry pi 2 或 Orange Pi 带有任何支持 nodejs 5 的 linux 操作系统。我为 arm7 选择了带有 arch linux 的橙色 pi。安装了 nodejs 和 npm。从 github 下载我的 iotapp 并导航到 /your/local/path/iotapp 并运行 npm install。基本的 expressjs 应用程序开始侦听您的 3000 端口。

浏览到 your-local-ip:3000 以检查是否呈现了默认的 expressjs 视图。我已经创建了这些 apis 来发布传感器数据

/iot/myhome/livingroom/thermostat - 温度 api

/iot/myhome/livingroom/mic - 声音 api

/iot/myhome/livingroom/pir - 状态传感器 api

/iot/myhome/livingroom/distance - 距离传感器 api

/iot/myhome/mydevice/location - gps 追踪器 api

/iot/myhome/garden/moisture - 土壤湿度传感器 api

/iot/myhome/kitchen/gas - 气体泄漏传感器 api

/iot/myhome/livingroom/light - 光传感器 api

/iot/myhome/livingroom - 客厅的其他 api

/iot/myhome/bedroom - 卧室的其他 api


设置本地服务器。从我的 github 克隆源代码 iotapp。修改index.js,将你的云ip地址或域名放在azure中托管aspnet5应用

远程服务器

如今,将数据发布到云端已变得很流行。我们可以从物联网数据提供购买订阅,例如 amazon、azure、spark fun、pubnub、initial state 等。我为这个演示选择了天蓝色。可以开发数据分析、数据挖掘和机器学习算法来处理我们的数据。

从我的 github 下载 iotwebapp。我使用针对 asp.net5 的 Visual Studio 2015 创建了它。这些 api 被设置为发布物联网数据。 api 将 iot 记录在 azure 存储表中

可以设置deviceid参数来识别传感器位置。

这些 api 已设置,

api/iot/myhome/thermostat - 用于记录所有恒温器数据的 asp.net5 web api

api/iot/myhome/microphone-asp.net5 web api 记录所有麦克风数据

api/iot/myhome/pir - 用于记录所有 pir 数据的 asp.net5 web api

api/iot/myhome/distance - asp.net5 web api 记录所有距离传感器数据

api/iot/myhome/device/location - 用于记录 GPS 数据的 asp.net5 web api

api/iot/myhome/moisture - asp.net5 web api 记录湿度传感器数据

api/iot/myhome/gas - 用于记录气体传感器数据的 asp.net5 web api

api/iot/myhome/light - 用于记录所有光传感器数据的 asp.net5 web api

api/iot/myhome/livingroom - 用于记录所有客厅属性/传感器数据的 asp.net5 Web api。我们可以使用这个 api 来推送所有的传感器值。

api/iot/myhome/bedroom - 与上面相同,我创建了一个来记录我卧室的详细信息

设置远程服务器。从我的 github 克隆源代码 iotwebapp。创建一个 Azure 存储表。修改 IoTController.cs 并放入您的 azure 存储表帐户名和密钥。在本地服务器使用这个域名或ip

结论

代码中有很多地方需要重构。请随时修改,如果您受到打击,请告诉我。

代码

  • 联发科Rx
  • nodejs - 本地服务器
  • ThermoStatController.cs
  • PIRController.cs
  • MoistureController.cs
  • LivingRoomController.cs
  • LightController.cs
  • GPSController.cs
  • GasController.cs
  • 距离控制器.cs
  • BedRoomController.cs
MediaTekRxC/C++
Media Tek 作为接收器。 Sketch to local data to local server
/* Web client 此草图使用 MediaTek LinkIt 平台上的 Wi-Fi 功能连接到网站。相应地更改宏 WIFI_AP、WIFI_PASSWORD、WIFI_AUTH 和 SITE_URL。 2010 年 7 月 13 日由 dlf (Metodo2 srl) 修改 2012 年 5 月 31 日由 Tom Igoe 修改 2014 年 8 月 20 日由 MediaTek Inc. */#include #include #include #include #define WIFI_AP "your ap"#define WIFI_PASSWORD "your password"#define WIFI_AUTH LWIFI_WPA // 从 LWIFI_OPEN、LWIFI_WPA 或 LWIFI_WEP 中选择。#define SITE_URL "your ip" //你的 nodejs 或 azure ip 地址或域名LWiFiClient c;void setup(){ LWiFi.begin(); Serial.begin(115200); // 继续重试,直到连接到 AP Serial.println("Connecting to AP");而 (0 ==LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { delay(1000); } // 不断重试,直到连接到网站 Serial.println("Connecting to WebSite"); while (0 ==c.connect(SITE_URL, 3000)) { Serial.println("重新连接到网站");延迟(1000); }}boolean disconnectedMsg =false;void loop(){ // 确保我们已连接,并将响应内容转储到 Serial while (!c) { Serial.println(" Server disconnected.."); // 不断重试,直到连接到网站 Serial.println("Connecting to WebSite"); while (0 ==c.connect(SITE_URL, 3000)) { Serial.println("重新连接到网站");延迟(1000); Serial.println("读取温度..");更新温度();延迟(3000); Serial.println("检测声音..");更新声音();延迟(3000); Serial.println("检测人员移动..");更新PIR();延迟(3000); Serial.println("检测障碍物..");更新距离();延迟(3000); Serial.println("正在更新设备位置..");更新GPSTracker();延迟(3000); Serial.println("计算土壤湿度..");更新水分();延迟(3000); Serial.println("检测气体泄漏..");更新气体泄漏();延迟(3000); Serial.println("记录光强..");更新光照强度();延迟(3000);更新客厅属性();延迟(3000);更新卧室属性(); delay(3000);}void writeToConsole(){ // 确保我们已连接,并将响应内容转储到 Serial while (c) { int v =c.read(); if (v !=-1) { Serial.print((char)v); Serial.println(); Serial.println("服务器断开连接.."); // 不断重试,直到连接到网站 Serial.println("Connecting to WebSite"); while (0 ==c.connect(SITE_URL, 3000)) { Serial.println("重新连接到网站");延迟(1000); } }void updatePIR(){ long unsigned int s; DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired"); root["deviceid"] ="/iot/myhome/livingroom/pir"; //假设默认单位需要毫秒["motionstart"] =String(random(0,1000));期望[“motionend”]=字符串(随机(1000,10000)); String len =String(root.measureLength()); c.println("POST /iot/myhome/livingroom/pir HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); //检测缓慢的服务器响应并再次发布请求而无需等待死响应的逻辑 s =millis(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); }void updateDistance(){ long unsigned int s; DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired"); root["deviceid"] ="/iot/myhome/livingroom/distancesensor"; //假设默认单位cm期望["障碍"]=String(random(50,450)); String len =String(root.measureLength()); c.println("POST /iot/myhome/livingroom/distance HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); }void updateGPSTracker(){ long unsigned int s; DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired"); root["deviceid"] ="/iot/mydevice";期望[“纬度”] =字符串(随机(20,25));期望[“长”]=字符串(随机(22,27)); String len =String(root.measureLength()); c.println("POST /iot/mydevice/location HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole();}void updateMoisture(){ long unsigned int s; DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired"); root["deviceid"] ="/iot/myhome/garden/moisture"; //假设需要的默认单位["水分"] =String(random(40,60)); String len =String(root.measureLength()); c.println("POST /iot/myhome/garden/moisture HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); }void updateGasLeak(){ DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired");期望[“泄漏”] =“否”; root["deviceid"] ="/iot/myhome/kitchen/gas"; long unsigned int s; String len =String(root.measureLength()); c.println("POST /iot/myhome/kitchen/gas HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); }void updateLightIntensity(){ DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired");期望[“强度”] =“80”; root["deviceid"] ="/iot/myhome/livingroom/light"; long unsigned int s; String len =String(root.measureLength()); c.println("POST /iot/myhome/livingroom/light HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); }void updateLivingroomAttributes(){ DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); root["deviceid"] ="/iot/myhome/livingroom"; JsonObject&desired =root.createNestedObject("desired"); //同时登录客厅属性的替代api所需["window"] ="open";期望[“门”] =“关闭”;期望[“交流”] =“关闭”;期望[“温度”] =字符串(随机(24,28));所需的[“湿度”] =字符串(随机(60,65)); long unsigned int s; String len =String(root.measureLength()); c.println("POST /iot/myhome/livingroom HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); } void updateBedroomAttributes(){ DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); root["deviceid"] ="/iot/myhome/bedroom"; JsonObject&desired =root.createNestedObject("desired"); //同时登录客厅属性的替代api所需["window"] ="open";期望[“门”] =“关闭”;期望[“交流”] =“关闭”;期望[“温度”] =字符串(随机(22,23));所需的[“湿度”] =字符串(随机(75,80)); long unsigned int s; String len =String(root.measureLength()); c.println("POST /iot/myhome/bedroom HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); } void updateSound(){ long unsigned int s; long unsigned int e; DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired");期望[“强度”] =字符串(随机(40,80)); root["deviceid"] ="/iot/myhome/livingroom/mic"; root["timeutc"] =""; root["signedby"]=""; String len =String(root.measureLength()); c.println("POST /iot/myhome/livingroom/mic HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole();}void updateTemperature(){ long unsigned int s; long unsigned int e; DynamicJsonBuffer jsonBuffer; jsonObject&root =jsonBuffer.createObject(); JsonObject&desired =root.createNestedObject("desired");期望[“温度”] =字符串(随机(20,40));期望[“湿度”]=字符串(随机(60,80)); root["deviceid"] ="/iot/myhome/livingroom/thermostat"; root["timeutc"] =""; root["signedby"]=""; String len =String(root.measureLength()); c.println("POST /iot/myhome/livingroom/thermostat HTTP/1.1"); c.println("主机:" SITE_URL); c.println("内容类型:应用程序/json"); c.println("缓存控制:无缓存"); c.print("内容长度:"); c.println(len); c.println("连接:关闭"); c.println(); root.printTo(c); root.printTo(串行); s =毫秒(); // 等待服务器响应 Serial.println("waiting HTTP response:");而(!c.available()){延迟(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("服务器没有响应..");休息; } } Serial.println("调用写入控制台.."); writeToConsole(); }
nodejs - 本地服务器JavaScript
具有从联发科接收数据的路由的 index.js
var express =require('express');var router =express.Router();var buf =require('buffer');var request =require("request");//用你的实际IP地址或域名替换your-ip-or-domain-name//example iot.azurewebsites.com//example yourdomainname.com//example 47.12.67.16//接受homepagerouter.post('/iot/myhome/livingroom/thermostat', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; POST 请求console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/thermostat', headers:{ 'cache -control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('客厅温度记录');});//接受POST请求 microuter.post('/iot/myhome/livingroom/mic' , 乐趣动作 (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi";控制台日志(状态); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/microphone', headers:{ 'cache-control':'no- cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('客厅声音强度记录');});//接受POST请求 pirrouter.post('/iot/myhome/livingroom/pir', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name /api/iot/myhome/livingroom/pir', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request (options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('客厅pir运动记录');});/ / 接受 POST 请求 distancerouter.post('/iot/myhome/livingroom/distance', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/distance', headers:{ 'cache -control':'no-cache', 'content-type':'application/json' }, body:state, js上:真}; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('客厅障碍记录');});//接受POST请求 gpsrouter.post('/iot/mydevice/location', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/ iot/mydevice/location/gps', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('设备位置记录');});//接受POST请求.post('/iot/myhome/garden/moisture', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state ); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/garden/moisture', headers:{ 'cache-control':' no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Garden moisture level recorded');});// accept POST request gasrouter.post('/iot/myhome/kitchen/gas', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/kitchen/gas', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Gas leak information recorded');});// accept POST request lightrouter.post('/iot/myhome/livingroom/light', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/light', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(optio ns, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Light intensity recorded');});// accept POST request livingroomrouter.post('/iot/myhome/livingroom', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/room/livingroom', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Livingroom attributes recorded');});// accept POST request bedroomrouter.post('/iot/myhome/bedroom', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/room/bedroom', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, fu nction (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Bedroom attributes recorded');});// accept PUT request at /userrouter.put('/user', function (req, res) { res.send('Got a PUT request at /user');});// accept DELETE request at /user//router.delete('/user', function (req, res) {// res.send('Got a DELETE request at /user');//});/* GET home page. */router.get('/', function(req, res, next) { res.render('index', { title:'Express' });});module.exports =router;
ThermoStatController.csC#
api to log temperature data to the cloud
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Newtonsoft.Json;using Microsoft.WindowsAzure.Storage;using Microsoft.WindowsAzure.Storage.Auth;using Microsoft.WindowsAzure.Storage.Table;// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class ThermoStatController :IoTController { // GET:// public IActionResult Index() { return View(); } [HttpPost] public IActionResult Post([FromBody]IotTemperature iotTemperature) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotTemperature.PartitionKey ="thermostat"; iotTemperature.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotTemperature); // Execute the insert operation. table.Execute(insertOperation); return Ok("Temperature data logged to azure cloud.."); } } public class IotTemperature :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string temperature { get;放; } public string humidity { get;放; } } }}
PIRController.csC#
api to log presence sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class PIRController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotPIR iotPIR) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotPIR.PartitionKey ="pir"; iotPIR.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotPIR); // Execute the insert operation. table.Execute(insertOperation); return Ok("PIR data logged to azure cloud.."); } } public class IotPIR :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string motionstart { get;放; } public string motionend { get;放; } } }}
MoistureController.csC#
api to log soil moisture data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/garden/[Controller]")] public class MoistureController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotMoisture iotMoisture) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotMoisture.PartitionKey ="moisture"; iotMoisture.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotMoisture); // Execute the insert operation. table.Execute(insertOperation); return Ok("Moisture data logged to azure cloud.."); } } public class IotMoisture :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string moisture { get;放; } } }}
LivingRoomController.csC#
api to log all living room sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/room/[controller]")] public class LivingRoomController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotLivingRoom iotLivingRoom) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotLivingRoom.PartitionKey ="livingroom"; iotLivingRoom.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotLivingRoom); // Execute the insert operation. table.Execute(insertOperation); return Ok("Living room attributes logged to azure cloud.."); } } public class IotLivingRoom :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string window { get;放; } public string door { get;放; } public string ac { get;放; } public string temperature { get;放; } public string humidity { get;放; } } }}
LightController.csC#
api to log light sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class LightController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotLight iotLight) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotLight.PartitionKey ="light"; iotLight.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotLight); // Execute the insert operation. table.Execute(insertOperation); return Ok("Light intensity logged to azure cloud.."); } } public class IotLight :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string intensity { get;放; } } }}
GPSController.csC#
api to log gps data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/mydevice/location/[Controller]")] public class GPSController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotGPS iotGPS) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotGPS.PartitionKey ="gps"; iotGPS.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotGPS); // Execute the insert operation. table.Execute(insertOperation); return Ok("GPS data logged to azure cloud.."); } } public class IotGPS :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string lat { get;放; } [JsonProperty("long")] public string longitude { get;放; } } }}
GasController.csC#
api to log gas leakage data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/kitchen/[Controller]")] public class GasController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotGas iotGas) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotGas.PartitionKey ="gas"; iotGas.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotGas); // Execute the insert operation. table.Execute(insertOperation); return Ok("Gas leak information logged to azure cloud.."); } } public class IotGas :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string leak { get;放; } } }}
DistanceController.csC#
api to log ultrasonic distance sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class DistanceController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotDistance iotDistance) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotDistance.PartitionKey ="distance"; iotDistance.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotDistance); // Execute the insert operation. table.Execute(insertOperation); return Ok("Obstacle data logged to azure cloud.."); } } public class IotDistance :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string obstacle { get;放; } } }}
BedRoomController.csC#
api to log all bedroom sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/room/[controller]")] public class BedRoomController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotBedRoom iotBedRoom) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotBedRoom.PartitionKey ="bedroom"; iotBedRoom.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotBedRoom); // Execute the insert operation. table.Execute(insertOperation); return Ok("Bed room attributes logged to azure cloud.."); } } public class IotBedRoom :TableEntity { public string deviceid { get;放; } public string timeutc { get;放; } public string signedby { get;放; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get;放; } public class Desired { public string window { get;放; } public string door { get;放; } public string ac { get;放; } public string temperature { get;放; } public string humidity { get;放; } } }}
Media Tek Smart home - Source code for data logging
source code for nodejsapp, aspnet5 and mediatek receiver inohttps://github.com/syediddi/iot-mediatek-linkIt

示意图

Transmit radio signal from arduino Transmit radio signal via Xbee from arduino without shield Transmit radio signals from arduino

制造工艺

  1. 智能数据:物联网的下一个前沿
  2. 带有 Sensorflare 和 RaspberryPi 的 433MHz 智能家居控制器
  3. RASPBERRY PI 家庭自动化
  4. Smart Bartender
  5. 未来的智能医院需要更智能的软件
  6. 智能家居技能差距
  7. 工作场所互联的好处
  8. 变得聪明:你家的未来
  9. 智能工厂白日梦
  10. 智能家居连接:克服主要障碍的 3 个步骤
  11. 面向现代生活的智能家居升级
  12. 数据收集 - 智能制造之旅的关键