文档结构  
翻译进度:54%     翻译赏金:0 元 (?)    ¥ 我要打赏

介绍

物联网(IoT)是最近一段时间的网络流行语,除了对于普通大众来说热闹的意义,物联网还促进了机器到网络的数据庞大扩充的重新洗牌。说实话,物联网将会是未来的下一个前沿技术。

本文介绍了物联网的一般概念以及在我们现实世界中的应用,我们还将在这片文章的后半部分,讨论建立一个物联网相关功能的应用。如果你是一个科技爱好者,那么准备开始这篇文章之旅吧。

第 1 段(可获 1.19 积分)

什么是物联网?

这个术语顾名思义:物物相连的互联网。这一行字可以有很多种解读的方式。一个简单的解释可能是:将设备的网络添加进互联网,使得它们能够与其他用户和设备进行通信。总的来说,物联网促进了现实世界的高水平意识和一个平台来监控对我们公开反应意识。设备的网络可能包含它们自己的IP地址,并可以根据自动定义的任务连接到彼此。在2014年全球物联网市场的营收已达6558亿美元。到2020年,它预计将增长到8.9万亿美元的市场!

物联网 & 现实世界 (资源:  链接)

第 2 段(可获 1.55 积分)

起源

1982年卡内基梅隆大学做了一台被称之为第一台互联网连接设备的改造可乐贩售机。1999年美国麻省理工学院(MIT)的Kevin Ash-ton教授首次提出物联网的概念 。此后十年,物联网慢慢的获得了全球认可,成为了一项被主要推进的技术。.

应用程序

物联网可以应用在我们的现实世界的方方面面。想象一下,有这样的一个世界,当你来到自家门前的时候大门会是打开着的,而陌生人到门口台阶的时候会是大门紧闭。而灯光将会检测你是否在房间里而自动开关。当你发出语音命令的时候,将有一杯咖啡为你泡好。手表会为你爷爷做一张健康表并当你外出的时候如果发现有任何严重的问题将会发送警报给你的手机,等等。所以很明显可能性和应用领域是永无止境的。你已经开始想象了,不是吗?

物联网应用程序 (资源:  幻灯片分享)

第 3 段(可获 2.26 积分)

本文的结果

在这篇文章中我们将建立一个针对人身安全的物联网项目. 无论你是初学者或专业的, 本文都能教你如何把你的想法做成一个很棒的物联网工程.我们将讨论事物的协调,并通过本文一步步实现它们. 让我们开始吧!

那只兔子在哪?

先说本文中我们要实现的想法. 众所周知地震是最具根绝性的自然力量,人类从未能减小其毁灭性的影响 . 由于无法预知它的到来, 其造成的生命和财产损失往往跨越灾难性的水平.

在这篇文章中我们将通过物联网系统采用一种近似的方法来侦测地震波信号,并且你可以通过你的移动设备来预知即将到来的地震冲击波.我们将使用安卓作为移动设备测试平台. 我们在那里找到了那只兔子,不是吗?  让我们抓住它!

第 4 段(可获 2.24 积分)

背景

我住在孟加拉国——一个据记载自1548年以来,具有悠久的地震历史的国家。它被一些高地震活动区所围绕,包括北部的喜马拉雅弧和印度西隆高原,东面的缅甸弧、缅甸若开山复背斜,以及东北的印度那加逆断层。

统计调查发现,之前提到的印度洋板块曾在5千万年前和亚洲板块相撞。自此以后,印度洋板块持续向北挤压亚洲板块,并向下延伸至喜马拉雅山脉将其抬高。

近年来,大量严重地震在相应地区附近发生。或许我们中的很多人曾听说过尼泊尔和印度发生的产生了巨大损害的地震,其导致了数以千计的人失去生命以及数十亿美元的财产损失。在上述两个案例中,我的国家都遭遇了造成大量人员伤亡和财产损失的巨大地震事件。

第 5 段(可获 1.99 积分)

《国家地理》的一份报告(很多来自可信赖的资源,如:美国有线电视新闻网)显示:根据对不久的将来的预测,该国家可能面临经历量级会达到9.0级的“大逆冲型地震”的悲惨命运。甚至在对它的影响做出预测之前,要测算出这次地震将对世界人口最稠密的地区之一造成的损失的灾难性程度也不是一件很困难的事情。

尝试性的假设引导我去寻找一个能意识到地震活动的方法,如果我们能够在某种程度上测量有害的部分,并且使人们意识到在死区时间内他们安全的避难所,那么可能会在很大程度上挽救他们宝贵的生命。但是在那之前我们需要了解一些有关地震波的基本常识。

孟加拉国——印度——缅甸地区的隐藏故障(来源:美国有线电视新闻网)

第 6 段(可获 1.71 积分)

地震波

地震波传播的振动,是由地震震源向四处传播的振动。这些波通过地球内部传播并且可以被像地震仪这样的敏感探测器测量到。科学家们在全世界范围内建立了跟踪地壳运动的地震仪。 (分析:  地震波)

因此,它是某种形式的弹性波,可以产生一个诸如地震、爆炸或大型滑坡的脉冲。地震可以产生三种类型的地震波: 纵波(P波)、横波(S波)和面波(L波) 。

第 7 段(可获 1.25 积分)

P波(纵波)

也被称为“压缩波”“纵波”以及“主波”。P波是地震波中传播最快的一种,它比其他的波传播地更快,以至于最先从地壳到达地震台,因此被叫做“主要的波”。这种波能够穿过坚固的岩石以及液体,比如水或者是地球的液态层。P波在地壳中以每秒1.5至8千米的速度传播,并在此方向上震动地面。

P波(点击观看动画,来源:地震网)

S波(横波)

被称为“剪切波”或者“次级波”,在P波之后到达地震台。传播速度比P波慢了大概1.7倍。S波在它传播的垂直方向上震动地面。但是S波不能在液体或者气体中传播,因为液体和气体不能传递横向压力,而S波却是一种横向通过介质的地震波。

第 8 段(可获 1.9 积分)

通常说来,地震产生的横波比纵波要大,而且地震所造成的大部分灾害都是横波引起的强烈震动的结果。

横波(点击观看动画,来源:地震网)

面波

  和上面提到的两种地震波不同,这种波并不是在地球内部较深的地方传播。面波通常产生比体波更低的频率,因此很容易在震动图中区分出来。面波有两种:拉夫波和瑞利波。虽然面波在体波(纵波和横波)之后 到达,它对地震所造成的损害和破坏仍然负有责任。

第 9 段(可获 1.33 积分)

面波(点击观看动画,来源:地震网)

为了理解这些不同种类的地震波的全部影响,让我们来观看这个图像的动画。

一次地震的地震波(点击观看动画,来源:地震网)

修改计划

通过以上研究,我们对地震有了更加清晰的理解。当然我们所有人都会支持这种说法:纵波在地壳中传播地更快,而且就其他具有破坏性的地震波而言,纵波造成的损害更小。因为它的传播在转瞬之间,如果我们能够收集足够多的数据来研究它,那么在可怕的地震到来之前发出警告显然是有可能的。

第 10 段(可获 1.39 积分)

就算是通过计算纵波和横波到达时间的不同,对到地震中心距离的估计也会是一次艰难的任务。根据概测法:将两种波到达时间之差乘以5,将会得到以英里为单位的到地震中心的距离(来源:加州伯克利地震实验室)。

让我们做一个假设:一次地震袭击了一个地震台,相应的震动图记录了纵波和横波的到达时间分别为04:00:20 和 04:00:26.62。所以在这里这两种波的到达时间之差为6.62秒。应用上述原理,从地震台到地震中心的距离应该大约为(6.62*5)= 33英里。

 

第 11 段(可获 1.54 积分)

所以根据经验法则。

距离震源的距离 = ((P波的到达时间) – (S波的到达时间)) * 5

做下数学运算 

让我们做下数学运算。

情况 1: 计算一个距离你112英里的震源。由于P波的速度是6.0公里/秒,所以地震袭击你所在地方的时间为 ((1.6 * 112) / 6) = 29.87 s.

P波比S波快1.7倍,所以S波的速度为3.5公里/秒, 地震袭击你所在地方的时间为-((1.6 * 112) / 3.5) = 51.2 s.

这两种波之间的时间差 = (51.2 – 29.87) = 21.33, 这其中可能会由于若干因素的影响导致实际速度不符,但是实际的结果不会有太大的偏差。(基于上述公认的参考文献).

第 12 段(可获 1.91 积分)

情况 2: 现在计算你一个更加接近离你只有12英里的震源. P波到达你所在地的时间为 ((1.6 * 12) / 6) = 3.2 s.

S波将需要 ((1.6 * 12) / 3.5) = 5.48 s.

所以,在这种情况下时间差 = (5.48 – 3.2) = 2.28 s.

在上述两个例子中,有一点事明确的, P波和S波的时间差将会随着震源的远近而增加减少。

到目前为止,根据我们的想法, 我们应该计划如何通过记录P波使得人们可以在冲击波到来之前得到警示。

第 13 段(可获 1.45 积分)

收集组件

是时候收集我们工作所需要的重要组件了。为了检测地震活动造成的振动,我们将使用压力振动传感器。

压力振动传感器

它适合测量机动性、振动、冲击力和触摸。较大的的动态范围(0.001Hz~1000MHz)保证了完美的测量的实现。并且,我们可以通过用螺丝钉调节机载电位计来调整它的灵敏度。

     压力振动传感插板(模型:SEN04031P)

USB串行编程

它提供了一些USB串行变频器电缆,这些电缆确保了USB和串行通用异步收发报机接口的连通性。一些电缆能够在5V的情况下保证连通性,3.3V或者用户指定的有各种连接器接口的信号电平。

第 14 段(可获 1.53 积分)

You may need to install the driver for use casing the thing. Our development device contains Windows 7 64 bit OS, hence we have installed corresponding driver for this module.

USB to Serial Programmer

Wifi Module

For transmitting sensor data to a portable mobile device we will need a wifi module. We have used Wifi Module – ESP8266 in our case. It is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to a WiFi network. It is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.

第 15 段(可获 1.25 积分)

We need a bit of work to customize the module and make it programmable. We need to manage couple of things for the context-

  • Veroboard (where the module will reside)
  • Some male connectors
  • Three 10K resistors for VC control
  • Two external buttons for reboot and reset the module

 

Re-modeled WIFI Module (Model- ESP8266)

Making the Wifi Module Programmable

A bit of hectic works are ahead of us in order to make this wifi module programmable. We want to connect this module with the familiar Arduino IDE for uploading the code to the board. Hence we need to look up the GITHUB project dedicated for the mentioned chip model ESP8266.

第 16 段(可获 1.36 积分)

Download the Arduino IDE from the official site. After installation, go to File à Preference à Additional Boards Manager URLs and paste this link.

Fig 1.1: Configuring Arduino IDE for programming re-modeled WIFI Module

Now go back to the home of the IDE à Tools à Board à Boards Manager, scroll down and find the option of “esp8266 by ESP8266 community”, click on it and press install button. Have patience until it completes the installation.

Fig 1.2: Configuring Arduino IDE for programming re-modeled WIFI Module

You can check available port of your corresponding developing device by right clicking on My Computer à Manage à Device Manager à Ports and double check with the IDE’s Tools à Port if they are same.

第 17 段(可获 1.44 积分)

Go to Arduino IDE, Select Tools à Board à scroll down and select “Node MCU 1.0 (ESP-12E Module)”. Now the wifi module is ready to eat the code! Before that we need to make up our circuit.

Finalizing the Circuit

Circuit Diagram

You need to have some basic knowledge about circuit diagram and stuffs like breadboard, male-female connectors etc to wire up the things, This is the circuit diagram that we will follow later.

 Circuit diagram

Circuit Design

According to the diagram we will now connect the things up, we will need a breadboard and some wires here.

Wiring things up to a Breadboard

第 18 段(可获 1.29 积分)

A real “a ha” moment as things are ready to operate except the code (along with mobile device end) to upload the data from the sensor to my local IP using the wifi module!

It’s time to write the code for the wifi module, we create a local wifi network via a tool named connectify, you can use your wifi router too.

Move to the arduino IDE and write up the code below.

#include <ESP8266WiFi.h>

const char* ssid = "SweetHeart";    // username of your network
const char* password = "123456780";  // password of your network

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 500;           // interval at which to blink (milliseconds)

int sensorValue = 0;

WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  //Start the server
  server.begin();
  Serial.println("Server started");

  //Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait unlil the client sends some data
  Serial.println("new client");
  while (!client.available()) {
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    sensorValue = analogRead(A0);
  }

  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("");  // do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  
  String webpage = "<head><meta http-equiv=""refresh"" content=""1""></head>";
  webpage += "<body>";
  //webpage += "Value: ";
  webpage += String(sensorValue);
  webpage += "</body></html>";
  client.println(webpage);

  Serial.println("Client disconnected");
  Serial.println("");

}
第 19 段(可获 0.93 积分)

If all things are done as like above steps the code will successfully load into the module (connect the circuit board to a power source, you can be sure about the program load by the blinking led of the wifi module), also make sure boot mode is activated in the module. Now open the serial monitor according to the port number and if the code runs successfully you will see your local IP address where the value has been uploaded (and continuing to update the value).

Getting local IP from programmed WIFI Module

Hit that IP address to your browser and will see the output if the things are behaving in the right way as described.

第 20 段(可获 1.45 积分)

          

Value from Piezo sensor at local IP

Touch the piezo sensor and you will see a sudden change in the uploaded value, according to the code the value is updating (refreshing) at every 1s interval, it could be changed as per choice.

Connecting with Android

As we are getting our desired sensor value to our local ip address, so its time to broadcast the value to our mobile device. Hence we are using android as the mobile OS platform (the module can broadcast the value to any platform).

As we have already seen that, we are printing the sensor values as an http response so from client side (read android) we need to parse the values and that will be enough for us.

For parsing an http response we will use a library here written for android, named OkHTTP. Lets write up the code.

public class GetResponse {

    OkHttpClient client = new OkHttpClient();

    String run(String url) throws IOException {
        Request request = new Request.Builder()
                .url(url)
                .build();

        Response response = client.newCall(request).execute();
        return response.body().string();
    }
}
GetResponse example = new GetResponse();

try {
    String response = example.run("http://192.168.25.103");
    Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();

} catch (IOException e) {
}
第 21 段(可获 1.8 积分)

The things are getting interesting here, isn’t it? We had successfully caught the sensor values due to some vibration and transmitted the value to an android device which runs in same WIFI network. But in case of an earthquake or seismic activities you may stay outside of your home, may be in your office or coffee-shop, and then? Things not gonna help you in that case, but now we will screw things up for the latter case.

Remote Connection

We need to transmit the value to a remote source from where our mobile client can parse the value. Hence we are using a brilliant tool called ngrok. You can their docs for implementation.

第 22 段(可获 1.43 积分)

After downloading and installing the tool just bring the cmd window and navigate to the folder where it has been installed. Put this command:

ngrok http your_local_ip_address:8080

Execute the command and hit localhost in your browser along with the link “https://localhost:4040”. You will get 2 universal links from ngrok there and now you can use any of them inside the java code of android client as both of the links are universal now and can be accessed anywhere of the world. Fun, isn’t it?

Making the Phone Aware

All things are done as expected. Last part is parsing the corresponding html value that we will get form the universal link and make our mobile device aware what to do with the value. Let do the parsing.

第 23 段(可获 1.7 积分)

We will get just the expected value from the html response now. We will now set a filter for the value, if the response value gets past the filter value at anytime our mobile device will generate an alarm tone.

For filter value we are using 512, generally piezo sensor gives value within the range of 0 -1024 based on its received vibration frequency. So we are setting a value that is exactly half of its range, anything over the value will create an alarm tone.

Our previous code will change a little bit here.

GetResponse example = new GetResponse();

try {
    String response = example.run("http://92832de0.ngrok.io");
    //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
    String htmlTextStr = Html.fromHtml(response).toString();

    if (Integer.valueOf(htmlTextStr) > 512) {
        Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

        if (alert == null) {
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        }

        Ringtone ring = RingtoneManager.getRingtone(getApplicationContext(), alert);
        ring.play();
    }

} catch (IOException e) {
}
第 24 段(可获 1.19 积分)

We will customize the thing with a timer. From android client  we will make request in every 5 seconds to correspoding universal adress. So we will need a timer approach to achieve that.

private int mInterval = 5000; // 5 seconds by default, can be changed later
private Handler mHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    .....

    mHandler = new Handler();
    startRepeatingTask();
}
void startRepeatingTask() {
    mStatusChecker.run();
}
​​​​​​​Runnable mStatusChecker = new Runnable() {
    @Override
    public void run() {
        try {
            //this function can change value of mInterval.
            GetResponse example = new GetResponse();

            try {
                String response = example.run("http://92832de0.ngrok.io");
                //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
                String htmlTextStr = Html.fromHtml(response).toString();

                if (Integer.valueOf(htmlTextStr) > 512) {
                    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

                    if (alert == null) {
                        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
                    }

                    Ringtone ring = RingtoneManager.getRingtone(getApplicationContext(), alert);
                    ring.play();
                }

            } catch (IOException e) {
            }

        } finally {
            mHandler.postDelayed(mStatusChecker, mInterval);
        }
    }
};
第 25 段(可获 0.41 积分)

Points of Interest

We have successfully made a prototype of detecting seismic activities from a mobile device and the future interest from here is countless. We have started this research work keeping in mind about a megathrust quake possibiliy in our region of near future. We want to extend this work on a large scale, will look for some funding so that we can continue this research work and the solution can really help people at duying time. The solution can play a vital role to save the lives of million in current context. 

With some advance research (that we are continuing to model up) it is possible to get over 90% accurate results about the seismic vibration and hence some calculation may help the user to know the distance between him and the earthquake focus on the spot(read his/her mobile device). We will keep updating this article as soon as we get some great results. Your suggestion are welcome too to scale up our solution because this is for us, to save mankind.

Credit

For assembling the components and wiring them up we want to give the credit to one of our(Project[R] Lab, WizardApps) great contributor Mr. Chayan Mistry, EEE (3rd yr), NWU University, Khulna, Bangladesh.

第 26 段(可获 2.64 积分)

文章评论