devkit_如何使用NodeMCU Devkit和Firebase数据库开始物联网
devkitby Jibin Thomas 吉宾·托马斯(Jibin Thomas)如何使用NodeMCU Devkit和Firebase数据库开始物联网 (How to get started with IoT using NodeMCU Devkit and Firebase database)“The Internet will disappear. There will be so...
devkit
by Jibin Thomas
吉宾·托马斯(Jibin Thomas)
如何使用NodeMCU Devkit和Firebase数据库开始物联网 (How to get started with IoT using NodeMCU Devkit and Firebase database)
“The Internet will disappear. There will be so many IP addresses, so many devices, sensors, things that you are wearing, things that you are interacting with, that you won’t even sense it. It will be part of your presence all the time. Imagine you walk into a room, and the room is dynamic. And with your permission and all of that, you are interacting with the things going on in the room.”
“互联网将会消失。 将会有太多的IP地址,那么多的设备,传感器,您所穿的东西,与之交互的东西,甚至您都不会感觉到。 它将一直是您在场的一部分。 想象一下,走进一个房间,房间是动态的。 在您的允许下,您正在与房间中发生的事情进行互动。”
Nowadays many devices that we use day to day are connected to the internet like Television, smart speakers, refrigerators, etc. These devices extend their primary functions which allows them to interact with other devices on the internet and to be controlled remotely.
如今,我们日常使用的许多设备都已连接到Internet,例如电视,智能扬声器,冰箱等。这些设备扩展了其主要功能,从而使它们可以与Internet上的其他设备进行交互并受到远程控制。
You can build your own IoT devices using some sensors and microcontrollers. There are many development boards that will help you get started with IoT like Arduino, NodeMCU, Raspberry Pi, etc. You can automate your home by building from these devices.
您可以使用一些传感器和微控制器来构建自己的物联网设备。 有许多开发板可以帮助您开始使用IoT,例如Arduino,NodeMCU,Raspberry Pi等。您可以通过使用这些设备进行构建来使您的房屋自动化。
In this post, we will be using NodeMCU devkit and Firebase for turning on and off LED remotely. NodeMCU devkit and Firebase are the best combinations to get started with building some IoT projects. NodeMCU is cheap and has built-in wifi for internet connectivity, and the Firebase free plan is more than enough.
在本文中,我们将使用NodeMCU devkit和Firebase远程打开和关闭LED。 NodeMCU devkit和Firebase是开始构建某些IoT项目的最佳组合。 NodeMCU价格便宜,并且具有内置的wifi以实现Internet连接,而Firebase的免费计划绰绰有余。
搭建开发环境 (Setting up Development Environment)
1. We will be using Arduino IDE for writing code and we will flash the code to the device. Download the latest version of the IDE here.
1.我们将使用Arduino IDE编写代码,并将代码闪存到设备中。 在此处下载最新版本的IDE。
2. Since we are using NodeMCU which is not officially supported by Arduino IDE, we have to add the JSON file of the device. In Arduino IDE add this URL in
2.由于我们使用的是Arduino IDE官方不支持的NodeMCU,因此我们必须添加设备的JSON文件。 在Arduino IDE中将此网址添加到
Open File > Preferences > Additional Board Manager URLs
打开文件>首选项>其他Board Manager URL
http://arduino.esp8266.com/stable/package_esp8266com_index.json
http://arduino.esp8266.com/stable/package_esp8266com_index.json
3. Select your Board from
3.从中选择您的董事会
Tools > Board > NodeMCU 1.o
工具>板> NodeMCU 1.o
4. To use firebase database in NodeMCU you need to download the firebase-arduino library which abstracts the REST API of the firebase. Download firebase-arduino here.
4.要在NodeMCU中使用firebase数据库,您需要下载firebase-arduino库,该库抽象了firebase的REST API。 在此处下载firebase-arduino 。
5. Include the downloaded zip file on Arduino IDE.
5.将下载的zip文件包含在Arduino IDE中。
Sketch > Include library > Add .zip > Select zip file
草图>包含库>添加.zip>选择zip文件
6. You also need to install the ArduinoJson library which can be downloaded from Arduino IDE itself.
6.您还需要安装ArduinoJson库,该库可以从Arduino IDE本身下载。
Note: The library version should not be 6.x.x — use the latest 5.x.x
注意:库版本不应为6.xx-使用最新的5.xx
Sketch > Include library > Manage Libraries > Search for ArduinoJson by Benoit Blanchon
草图>包含库>管理库> Benoit Blanchon搜索ArduinoJson
设置Firebase数据库 (Setting up Firebase Database)
7. Create a new firebase project from the console and head towards the database section. Select the firebase real-time database.
7.从控制台创建一个新的firebase项目,然后转到“数据库”部分。 选择Firebase实时数据库。
8. Copy the database secret for authentication from Settings Panel > Service accounts.
8.从设置面板>服务帐户复制数据库密码以进行身份验证。
9. Add a led node to the firebase database. This value will decide whether to turn on or off the LED.
9.将一个led节点添加到firebase数据库。 该值将决定是打开还是关闭LED。
配置Arduino IDE和Firebase数据库以协同工作 (Configuring Arduino IDE and firebase database to work together)
Now that all the setup procedures are done let’s start coding.
现在,所有设置过程都已完成,让我们开始编码。
You need to create a macro for your database URL and firebase secret which you had copied in Step 8.
您需要为在步骤8中复制的数据库URL和Firebase机密创建一个宏。
#define FIREBASE_HOST “yourfirebasedatabase.firebaseio.com”
#define FIREBASE_HOST“ yourfirebasedatabase.firebaseio.com”
#define FIREBASE_AUTH “*****”
#define FIREBASE_AUTH“ *****”
For simplicity, we will write a simple code for turning on and off LED remotely
为简单起见,我们将编写一个简单的代码以远程打开和关闭LED
10. The positive of the LED should be connected to the D1 pin and negative pin to the ground pin of NodeMCU.
10. LED的正极应连接到D1引脚,负极应连接到NodeMCU的接地引脚。
11. Upload your code from Arduino IDE.
11.从Arduino IDE上传您的代码。
Sketch > Upload
草图>上传
12. Now try changing the database value to true and false. The led should now start turn on and off. Additionally, you can extend this project by creating a web app that will toggle the LED instead of manually changing the value in the database.
12.现在尝试将数据库值更改为true和false。 LED现在应该开始打开和关闭。 此外,您可以通过创建一个Web应用程序扩展该项目,该应用程序将切换LED,而不是手动更改数据库中的值。
So now that you understand the basics of how to go about connecting NodeMCU to the internet and controlling it remotely, start hacking some new projects with it.
因此,现在您了解了如何将NodeMCU连接到互联网并进行远程控制的基础知识,开始使用它来入侵一些新项目。
devkit
更多推荐
所有评论(0)