arduino服务器

by Harshita Arora

通过Harshita Arora

如何使用Arduino检查Web服务器的响应状态 (How to use Arduino to check your web server’s response status)

Last year, I created Crypto Price Tracker (an app which was acquired by Redwood City Ventures this year). A back end member of my team had been using an Arduino setup to check web server response statuses continuously to get updates all the time. I found that setup to be pretty useful and interesting.

去年,我创建了Crypto Price Tracker (一个应用程序,今年被Redwood City Ventures收购)。 我团队的一个后端成员一直在使用Arduino设置来连续检查Web服务器响应状态以始终获取更新。 我发现该设置非常有用且有趣。

I researched about it and recreated the setup for myself. In this article, I’ll show you how you can build it yourself, too.

我对此进行了研究,并为自己重新创建了设置。 在本文中,我将向您展示如何自己构建它。

您需要的东西: (Things that you need:)

  1. Arduino Uno

    Arduino Uno

  2. Ethernet Shield for Arduino (to connect the Arduino to the Internet)

    Arduino的以太网屏蔽 (将Arduino连接到Internet)

  3. Ethernet Cable以太网电缆
  4. A/B Type USB 2.0 Cable (Power cable for Arduino)A / B型USB 2.0电缆(Arduino的电源线)
  5. Male-to-Male Jumper Cables (x2)公对公跳线(x2)
  6. Breadboard面包板
  7. LED (x1, any color)LED(x1,任何颜色)
  8. Resistor (x1, >100 ohms works)电阻(x1,> 100欧姆可工作)

设置 (Setting It Up)

  1. Mount/Insert the Ethernet shield on the Arduino.在Arduino上安装/插入以太网屏蔽。
  2. Insert the positive (longer) end of the LED into the breadboard slot 6a and the negative (shorter) end into slot 5a.将LED的正(长)端插入面包板插槽6a,将负(短)端插入插槽5a。
  3. Insert one end of the resistor into the breadboard slot 1b and the other into slot 5b.

    电阻的一端插入面包板插槽1b,另一端插入插槽5b。

  4. Insert one end of the first jumper cable into the breadboard slot 1e. Insert the other end into the GND slot of the Ethernet shield.

    第一根跳线的一端插入面包板插槽1e中。 将另一端插入以太网屏蔽的GND插槽。

  5. Insert one end of the second jumper cable into the breadboard slot 6e. Insert the other end into pin slot 2 of the Ethernet shield.

    第二根跨接电缆的一端插入面包板插槽6e中。 将另一端插入以太网屏蔽的插针插槽2中。

  6. Connect the Ethernet cable from your router to your Ethernet shield.

    以太网电缆从路由器连接到以太网屏蔽。

This is what my setup looks like:

这是我的设置:

7. Open a command line interface on your machine and check and note your default gateway. This can be done using ipconfig command on Windows or the netstat -nr | grep default command on Linux/Mac.

7.在计算机上打开命令行界面,然后检查并记下默认网关。 可以使用ipconfig完成 Windows或netstat -nr | grep default使用netstat -nr | grep default netstat -nr | grep default Linux / Mac上的命令。

8. Download and install the Arduino IDE if you haven’t already.

8.如果尚未下载并安装Arduino IDE,请下载并安装。

9. Open the IDE and go to Files -> Examples -> Ethernet -> WebClientRepeating. You should see the following code:

9.打开IDE,然后转到“文件” -& > 为例es - >的Eth er网- > WebClientRepeating。 您应该看到以下代码:

10. Edit the line 37 to be an IP address in the range (1–254) of your default gateway IP. So for example, if my default gateway is 10.0.0.1, then I can use an IP address from 10.0.0.2 to 10.0.0.254. It is, however, important to make sure that the IP that you’re using doesn’t conflict with any other IP addresses on your network.

10.将第37行编辑为默认网关IP范围(1-254)中的IP地址。 因此,例如,如果我的默认网关是10.0.0.1,则可以使用从10.0.0.2到10.0.0.254的IP地址。 但是,重要的是要确保您使用的IP地址与网络上的任何其他IP地址都没有冲突。

For this example, I changed the line of code to be:

对于此示例,我将代码行更改为:

IPAddress ip(10, 0, 0, 2);

IPAddress ip(10, 0, 0, 2);

11. Change the DNS in line 40 to be 8.8.8.8 (this is the Google Public DNS and is just something I prefer, you may use a DNS that you prefer).

11.将第40行的DNS更改为8.8.8.8 (这是Google Public DNS,这只是我喜欢的东西,您可以使用自己喜欢的DNS)。

For this example, I changed the line of code to be:

对于此示例,我将代码行更改为:

IPAddress myDns(8, 8, 8, 8);

IPAddress myDns(8, 8, 8, 8);

12. Change the URL in line 45 to a URL matching your web server. If you would like to use an IP address instead, then comment line 45 and uncomment line 46. Since I am using a web server that I’m hosting locally, for this example, I will use an IP address.

12.将第45行中的URL更改为与您的Web服务器匹配的URL。 如果您想改用IP地址,请在注释行45和注释行46中取消注释。 由于我使用的是本地托管的Web服务器,因此在此示例中,我将使用IP地址。

For this example, I changed the line of code to be:

对于此示例,我将代码行更改为:

//char server[] = “www.arduino.cc";IPAddress server(127,0,0,1);

//char server[] = “ www.arduino.cc "; IPAddress server(127,0,0,1);

Note that the port or the path here is not important yet. Just the IP Addressis needed. If you would like to change the port that is used for the GETrequest, you may change it on line 94.

请注意,此处的端口或路径并不重要。 仅需要IP地址。 如果您想更改用于GETrequest的端口,则可以在第94行进行更改。

For this example, I have hosted my local webserver on port 3000. Thus, I will change the code in line 94 to something like this:

对于此示例,我将本地Web服务器托管在端口3000上。因此,我将在第94行中的代码更改为如下所示:

if (client.connect(server, 3000)) {

if (client.connect(server, 3000)) {

13. Edit the GET request that is pre-written in lines 97 - 100 to follow this pattern:

13.编辑在第97-100 行中预先编写的GET请求,以遵循以下模式:

client.println(“GET /path_to_url HTTP/1.1”);client.println(“Host: 127.0.0.1”);client.println(“Connection: close”);client.println();

client.println(“GET /path_to_url HTTP/1.1”); client.println(“Host: 127.0.0.1”); client.println(“Connection: close”); client.println();

14. We can now start programming the behaviour of the LED depending on the web server status and response. To do this, we must first declare the pin we’re using for the LED on our Ethernet shield.

14.现在,我们可以开始根据Web服务器的状态和响应对LED的行为进行编程。 为此,我们必须首先在以太网屏蔽上声明用于LED的引脚。

Add the following line of code after the first two include statements of the program:

在前两个包括之后添加以下代码行 该计划的陈述:

int LED = 2;

int LED = 2;

15. Add the following lines of code at the beginning of the setup() function.

15.在setup()函数的开头添加以下代码行。

pinMode(LED, OUTPUT);

pinMode(LED, OUTPUT);

digitalWrite(LED, LOW); //program starts with the LED turned off

digitalWrite(LED, LOW); //program starts with the LED turned off

16. Add the following line of code after the GET request line that we previously edited:

16.在我们先前编辑的GET请求行之后添加以下代码行:

digitalWrite(LED, LOW);

digitalWrite(LED, LOW);

17. Finally, add this line of code at the beginning of the else statement of the same conditional:

17.最后,在else的开头添加这一行代码 相同条件的语句:

digitalWrite(LED, HIGH);

digitalWrite(LED, HIGH);

And voilà, you’re done!

瞧,您完成了!

Upload the program to your Arduino. Open the serial monitor from the top right part of the IDE and watch the response. If your server doesn’t respond, the LED glows, if it does, the LED stays off :)

将程序上传到您的Arduino。 从IDE的右上方打开串行监视器,然后观察响应。 如果您的服务器没有响应,则LED发光,如果发光,则LED保持熄灭:)

You can check out my final code here.

您可以在此处查看我的最终代码。

检查响应 (Checking Response)

If you would also like to validate the response that you receive from yourweb server, then you may add them inside the following conditional of theprogram.

如果您还想验证从Web服务器收到的响应,则可以将它们添加到程序的以下条件中。

if (client.available()) {char c = client.read();Serial.write(c);}

if (client.available()) { char c = client.read(); Serial.write(c); }

The variable c is where the response is stored.You could check it like this:

变量c是响应的存储位置,您可以像这样检查它:

if (client.available()) {

if (client.available()) {

char c = client.read();if(c == “arduino is great”){ digitalWrite(LED, LOW); //correct response}else{digitalWrite(LED, HIGH); //wrong response}Serial.write(c);}

char c = client.read(); if(c == “arduino is great”){ digitalWrite(LED, LOW); //correct response digitalWrite(LED, LOW); //correct response } else{ digitalWrite(LED, HIGH); //wrong response digitalWrite(LED, HIGH); //wrong response } Serial.write(c); }

Do note that, if you’re trying to do this, then it’s best to get rid of thedigitalWrite statement after the GET request. Depending on your response,you may also have to parse JSON values. There are several ways to do thisand plenty of tutorials/articles around for it too! Make sure to check themout!

请注意,如果您尝试执行此操作,则最好在GET请求之后删除digitalWrite语句。 根据您的响应,您可能还必须解析JSON值。 有几种方法可以做到这一点,并且还有很多教程/文章! 请务必检查一下!

Have fun! Feel free to email me at harshita (at) harshitaapps.com for any questions, feedback, or ideas!

玩得开心! 如有任何问题,反馈或想法,请随时通过harshita (at) harshitaapps.com给我发送电子邮件!

Make sure to check out Crypto Price Tracker app if you’re interested/invested in cryptocurrencies! :)

如果您对加密货币感兴趣/投资了,请确保签出Crypto Price Tracker应用程序! :)

翻译自: https://www.freecodecamp.org/news/how-to-use-arduino-to-check-your-web-servers-response-status-9e47e02a61cc/

arduino服务器

arduino服务器_如何使用Arduino检查Web服务器的响应状态相关推荐

  1. 无法在Web服务器上启动调试。与Web服务器通信时出现身份验证错误

    使用Visual Studio 2005(Visual Studio 2008亦存在此问题)调试设置了主机头的网站时出现如下错误信息: --------- Microsoft Visual Studi ...

  2. html 应用程序主机 自动关闭,服务器会话连接自动关闭怎么办?Web服务器 -电脑资料...

    在网络维护工作量相对较大的单位,网络管理员往往很少有时间呆在服务器现场,为了让服务器系统时刻高效地运行,他们不得不利用远程桌面功能来对服务器系统进行远程管理与维护, 事例回放 某一局域网络拓扑结构非常 ...

  3. 向web服务器传文件,c++实现向web服务器上传文件

    [实例简介] vs2013 c++实现上传的客户端,服务端为java写的web工程,模拟post方法,可以上传大文件 [实例截图] [核心代码] c向web服务器上传文件 └── c++ 向web服务 ...

  4. 景安服务器怎么上传网站程序,Web服务器是如何被应用服务器“收编”的?

    在传统 Web 应用的多层架构中 系统一般会包括有负载均衡器 Web 服务器.应用服务器等多个后端服务 其中,Web 服务器和应用服务器 常常被人视为一个整体 但其实从工作原理上来说 两者还是有一定区 ...

  5. 服务器信息泄漏漏洞,Windows2008 r2“Web服务器HTTP头信息泄露”漏洞修复(示例代码)...

    一.漏洞名称漏洞名称漏洞摘要修复建议 Web服务器HTTP头信息泄露远程Web服务器通过HTTP头公开信息.修改Web服务器的HTTP头以不公开有关底层Web服务器的详细信息. 二.安装IIS 6 管 ...

  6. web服务器可以上传信息吗,Web服务器的架设上传.doc

    Web服务器的架设上传.doc 简单Web服务器的架设 什么是web服务器 Web服务器其实就是一台提供网页解析服务的计算机上的一个软件程序.WEB服务器也称为WWW(WORLD WIDE WEB)服 ...

  7. cdt规约报文用程序解析_用 Python 撸一个 Web 服务器第3章:使用 MVC 构建程序

    Todo List 程序介绍 我们将要编写的 Todo List 程序包含四个页面,分别是注册页面.登录页面.首页.编辑页面.以下分别为四个页面的截图. 注册页面: 登录页面: 首页: 编辑页面: 程 ...

  8. web 服务器 内存 影响_工业环境软件套件 CODESYS web 服务器被曝严重的RCE漏洞

    聚焦源代码安全,网罗国内外最新资讯!编译:奇安信代码卫士团队用于工程控制系统的 CODESYS 自动化软件 web 服务器中被指存在一个严重漏洞(CVE-2020-10245),可导致远程未认证攻击者 ...

  9. 服务器关闭重启后客户端socket能自动连接吗_用Python 撸一个 Web 服务器

    从一个 Hello World 程序说起 要编写 Web 服务器,需要用到一个 Python 内置库 socket.Socket 是一个比较抽象的概念,中文叫套接字,它代表一个网络连接.两台计算机之间 ...

最新文章

  1. jquery实现上传图片及图片大小验证、图片预览效果代码
  2. SVN Unable to connect to a repository at URL问题解决
  3. python生成dat文件_Ra-使用Python脚本生成shape.dat文件
  4. 树莓派学习笔记——GPIO功能学习
  5. synchronized与java.util.concurrent.locks.Lock的相同之处和不同之处
  6. 零基础学Python(第二十章 异常处理try)
  7. PooledByteBuf源码分析
  8. 的it生活_在日本生活了10年的IT女,聊聊回国工作的亲身经历
  9. C++ AFX_MANAGE_STATE(AfxGetStaticModuleState())的作用
  10. 扫地机器人开年之战:新品初现,战局微调
  11. Django REST framework 的快速入门教程
  12. php红包平均分配,红包平均分配算法
  13. 揭晓AI算力池化的五大场景
  14. 【转】(Jquery)避免数据相加小数点后产生多位数和计算精度损失
  15. iphone怎么查看wifi密码_怎么查看电脑连接的wifi密码?2种方法分享给大家!
  16. C语言 进制转换 将十进制转换为任意进制
  17. GPS定位开发步骤以及流程图
  18. python-web自动化测试-对话框的处理
  19. 计算机图形学【GAMES-101】4、纹理映射(重心坐标插值、透视投影矫正、双线性插值MipMap、环境光遮蔽AO)
  20. 自监督学习详细介绍(学习笔记)

热门文章

  1. 不看绝对血亏!java字符串转json
  2. java支付模块架构,涨薪7K!
  3. HTML列表标签,大牛最佳总结
  4. 使用Docker快速搭建Tensorflow开发环境
  5. 让内核突破512字节的限制
  6. day06 hashlib模块
  7. JavaScript变量和作用域
  8. C 文件读写 容易疏忽的一个问题
  9. EBS并发管理器请求汇总(按照并发消耗时间,等待时间,平均等待事件等汇总)...
  10. symbian 中自动寻找cmwap连接点,通杀uiq 2nd 3nd和s60 2nd 3nd 5nd