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

学校的智能温度监测

组件和用品

Pycom SiPy
× 1
Raspberry Pi 3 B 型
× 1
Arduino Nano R3
× 1
SparkFun 逻辑电平转换器 - 双向
× 1
NFC RFID-RC522
× 1
Sharp GP2Y0A41SK0F (4cm - 30cm) - 模拟距离传感器
× 1
MLX90614-DCI I2C - 温度传感器
× 1
DFRobot I2C 16x2 Arduino LCD 显示模块
× 1
LED(通用)
× 1
电阻 330 ohm
× 2
蜂鸣器
× 1

应用和在线服务

Arduino IDE
Visual Studio Code (Pymakr)
ThingSpeak API
IFTTT
Putty
空闲 IDE

关于这个项目

问题说明

在亚洲,由于2003年天气炎热,加上严重急性呼吸系统综合症(SARS)的爆发,中小学生每个季度都需要进行体温测量,以确保学生的身心健康。每当有学校安排的体温测量练习时,学生都必须携带自己的电子体温计进行此项练习。但是,部分学生可能会因为温度计放错位置或损坏等原因而无法参加练习,忘记携带设备。由于个人卫生,不允许学生共用他们的温度计,他们可能没有足够的钱购买新的温度计。因此,它会影响温度测量运动的成功率。体温测量练习结束后,工作人员必须手动键入所有学生的体温数据和特定于数据库的学生。这项任务非常繁琐和耗时,因为每个班主任需要为大约40名学生进行输入。

解决方案是什么?

我们项目的主题是 SqwidNet 的社会影响,以及可持续发展目标 (SDG) 中的良好健康和福祉领域。这样做的原因是因为我们的系统能够部署自动测量有效用户的体温,以便监控他们的体温,并在超过某个阈值时发送警报。

工作原理:RaspberryPi 和 Arduino

RaspberryPi 包含一个 Python 程序和 MySQL 数据库。

在启动 Python 程序时,它会自动检查数据库是否已经创建,如果没有,它将自动创建。如果需要,也会自动检查和创建里面的表格。这减少了学校教师/行政人员的体力劳动。

然后建立查询连接,查询数据库,等待Arduino通过串口发送相关信息。

在 Arduino 上点击 RFID 卡后,卡信息存储在 Arduino 中,通过串行通信发送到 RaspberryPi。之后,树莓派用数据库确认该卡为有效用户,如果是,则发送给Arduino进行确认,Arduino在LCD屏幕上输出“欢迎,姓名”。如果它不是有效用户,它只会说“错误!无效用户!”。

假设,现在,我们有一个刚刚点击的有效用户。接下来,Arduino 将提示用户测量体温。然后距离传感器将感应用户是否准备好测量他们的体温。如果是,它会测量他们的温度并在 LCD 屏幕上输出他们的温度。如果是有效温度 (28*C - 42*C),则此信息将同时发送到 RaspberryPi (MySQL) 和 Sigfox (ThingSpeak) 以进行数据存储。 MySQL 数据库将存储用户 ID、日期、时间戳和每次拍摄的温度。

当从 Arduino 接收温度数据时,RaspberryPi 会不断检查温度是否正确传递,然后再进行其他任何操作。这是因为,如果 Python 程序只检查一次温度数据,它可能还没有被 Arduino 发送,因为这两个代码在不同的时间执行。所以为了同步,我们在继续程序的其余部分之前不断检查 Python 代码上的温度数据。

注意: RaspberryPi 的 Python 代码和 Arduino 代码都使用一种称为握手的同步方法。如果 RaspberryPi 没有准备好接收另一个温度/用户信息,Arduino 将不允许用户点击该卡,反之亦然 .

我这样做的一个简单方法是不断发送“READY”信号,直到对方发回“RECEIVE”信号,以便他们知道他们都准备好了。

阿杜诺-

boolean readySignal =Serial.readString() =="READY";


if(readySignal)
{

tapped =true;

Serial.println("RECEIVED");

}

Python -

while(readySignal ==True):

ser.write(b'' + "READY")



receivedSignal =ser.readline().strip() =="RECEIVED"


if(receivedSignal ==True):

readySignal =False

每次完成查询时,请记住关闭查询连接!这是为了消除任何可能的内存泄漏,总体来说这是一个很好的做法。

工作原理:Sigfox (SiPy)

SiPy 收到来自 Arduino 的温度数据后,会将用户 ID 和温度分成整数和小数位。这样做之后,所有的数据都通过字节发送到 Sigfox 后端(以便它可以发送到 Ubidots 和 ThingSpeak),并且应该看起来像下图。

收到此信息后,Sigfox 后端将重新编码此数据以发送到 ThingSpeak 进行存储。下面将向您展示如何编写后端代码以将数据发送到 Thingspeak。

在设备类型> 设备名称> CALLBACKS 下的 Sigfox 后端中,您需要完全按照原样输入自定义负载 除非您更改了 SiPy 中的编码,因为自定义有效负载会将首先接收到的内容设置为用户 ID,例如,如果您先发送温度,在后端,它会将温度转换为用户 ID 而不是温度。在正文中,write api key 需要放在最上面,而字段可以与您在自定义负载中创建的任何自定义数据一起放置。

工作原理:云

数据成功发送到 ThingSpeak 后,它首先在私人查看通道中接收它,在该通道中,MATLAB 分析脚本分析数据并将温度数据组合成一个值,而不是将整数值和十进制值分开。

表格代码取自一个开源项目,并根据我们的需要进行了修改。它非常有用,因为每次发送新数据时表格都会自动更新,非常适合我们的使用。

同时,它会检查温度是否处于危险水平(发烧),如果是,将发送电子邮件通知员工/教师。

综上所述,第一个将温度值以整数和十进制分开的通道是后端通道,并非真正用于查看。第二个通道的温度值进行了合并,方便员工/管理层/管理员查看,并有一个类似Excel的表格,便于数据分析。

1. Arduino Nano 连接设置

对于 Arduino Nano,以下是我们与模块建立的连接。

Nano 和 Uno 具有相同的引脚排列。

RFID - RC522

SDA D10
SCK D13
MOSI D11
MISO D12
IRQ UNCONNECTED
GND GND
RST D9
3.3V 3.3V

如何测试RFID

LCD

SDA A4
SCL A5
GND GND
5V 5V

如何测试I2C LCD

距离传感器

5V 5V
GND GND
输入A0

如何测试夏普红外距离传感器

蜂鸣器

GND GND
输出D6

如何测试蜂鸣器

红外温度传感器

SDA A4
SCL A5
GND GND
5V 5V

如何测试红外温度传感器,

LED

平面(阴极)GND
非平面(阳极)D7

好! 对于 Arduino 连接,您现在应该可以开始了。

2. 树莓派设置

主要有两件事需要安装到您的 Raspberry Pi 3 机器上,

1.树莓派操作 系统 -

Raspbian 操作系统的安装被认为相当简单。

关于如何做到这一点的简短回答是将图像文件闪烁(写入)到 SD 卡上,然后将该 SD 卡插入 Raspberry Pi 3。

但是,如果您正在寻找分步长答案教程,请按以下步骤操作 -

首先,您必须下载一个软件,该软件允许您将.img 文件闪存到存储驱动器中。您可以使用名为 balenaEtcher 的软件。

之后,前往 Raspberry Pi - Raspbian 页面并选择一个适合您的需求。我选择了“Raspbian Buster with Desktop 和推荐软件”,因为正如其名,自带推荐软件,省去下载软件的麻烦。

完成后 通过上述步骤,只需启动 balenaEtcher 软件。这一步很容易解释:选择图像(your.img Raspbian 文件),然后选择您的 SD 卡,然后按 flash。现在,你只需要等待。完成后,它应该会提示您,您现在可以将新刷入的 SD 卡插入您的 Raspberry Pi。

在此之后,通过 HDMI 将您的 Raspberry Pi 机器连接到显示器并进行初始设置。最后,前往首选项 -> Raspberry Pi 配置 你应该在这个菜单上 -

按照选项,此步骤启用SSH,VNC等接口,允许您通过eth0或wlan0连接到IP地址(因此您不再需要HDMI电缆,您可以通过SSH完成所有操作)。

(可选步骤) - 我打开终端并编辑 dhcpcd.conf 文件(sudo nano /etc/dhcpcd.conf)并添加这些命令行,

接口eth0
静态ip_address=192.168.0.11/24

以上允许我通过以太网电缆连接到 Raspberry Pi,静态地址为 192.168.0.11,所以我每次都知道那是我的 Raspberry Pi 的地址。

这是一个可选步骤,因为一旦您连接到 WiFi,您将获得一个 wlan0 ip 地址,该地址允许您在没有以太网电缆的情况下连接到 Raspberry Pi,只要您连接到该位置的任何位置无线上网。要查看您的 wlan0 IP 地址,只需将鼠标悬停在位于右上角的 WiFI 符号上,它就会指示。

不错! 您已完成对 Raspberry Pi 的初始设置!

3. MySQL 数据库设置

我觉得这一步有点难,尤其是需要设置MySQL root用户的部分,请仔细按照,因为任何错误都很难纠正。

首先,您必须确保您的系统已升级并更新到最新固件。您可以通过输入这些命令来确定,

sudo apt update
sudo apt upgrade

完成后,您将安装apache2。

sudo apt install apache2 

Apache2 将允许您创建一个网络服务器,以便您可以访问您以后创建的网站。

apache2安装好后,需要安装PHP。

sudo apt install php php-mbstring 

PHP 将允许您创建和查看您自己的 PHP 网站。

让我们停下来看看您刚刚安装的所有东西是否都正常工作,只需在您的网络浏览器中输入您的 Raspberry Pi 的 IP 或“localhost”(如果您仍然通过 HDMI 连接),您应该会看到一个 Apache 索引页面。

现在,您将需要安装数据库。为此,您将使用 MySQL 和 mariadb。

sudo apt install mariadb-server php-mysql 

重要 - 请务必仔细阅读以下内容。

现在,您将创建您的 MySQL 根用户,以便您可以使用它来访问数据库。

sudo mysql --user=root 

您现在将进入一个 MySQL 会话,您可以在其中键入 MySQL 代码,逐行键入这些代码,(您可以将密码替换为您自己的密码)

DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root' @'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

您现在可以通过登录来测试您的 MySQL 根用户;

mysql --user=root --password=yourmysqlpassword 

如果一切正常,现在您可以安装 PHPMyAdmin,管理员控制面板供您访问(查看)和修改 MySQL 数据库。

sudo apt install phpmyadmin

(安装后)
sudo phpenmod mysqli
sudo /etc/init.d/apache2 restart

恭喜! 您现在可以使用 http://your_raspberrypi_ip_address/phpmyadmin 访问新创建的数据库。

4. SiPy 扩展板 2.0 设置和软件指南

首先,您需要将 SiPy 模块插入扩展板上,重置按钮面向 USB 连接器,并且应该牢固地卡入到位,针脚不再可见。

来源:Pycom 文档

之后,您需要更新 SiPy 上的固件,以便您可以上传和运行程序以及获取 Sigfox 设备 ID 和 PAC 编号,这些 ID 和 PAC 编号将用于注册 Sigfox 后端。根据您使用的操作系统(操作系统)下载固件更新程序。

  • 窗户
  • macOS(10.11 或更高版本)
  • Linux(需要 dialog python-serial 包)

下载pycom固件升级后,第一次启动更新程序时,下图只会出现一次 所以请确保您选择了正确的 Sigfox 区域、Board。

请仔细按照固件更新的说明进行操作,因为它可能导致您的 Sigfox 无法正常运行,例如 Sigfox 设备 ID 和 PAC 编号全部为“F”(如下所示),而是数字和字母的混合。

b 'FFFFFFFF'
b 'FFFFFFFFFFFFFFFF'

固件更新后,您需要下载 Visual Studio Code 并安装扩展 Pymkr 和 nodejs,然后才能开始在 SiPy 上上传和运行程序。

首先,您需要创建一个新文件夹来保存您稍后要上传到 SiPy 的所有文件,或者只是存储您要运行的所有程序。按左上角的文件并按打开文件夹或Ctrl+K+O, 然后选择要放置此文件夹的位置并右键单击以创建一个新文件夹。之后,创建一个新文件或Ctrl+N 打开一个新文件。创建新文件后,您需要将新文件另存为python并将保存类型更改为python文件,以便稍后可以在SiPy上运行代码并将其保存到您创建的新文件夹中。

注意: 文件名可以是Test、Trial等。但是如果上传到SiPy文件名需要叫main .

要仅运行您的代码而不将其上传到 Sipy 模块,您所要做的就是按下位于程序底部的运行按钮。它旁边的上传将当前文件夹上传到 SiPy 模块。 使用 while 1 循环时要小心,因为一旦这些循环被上传到 SiPy 模块,再次访问 SiPy 模块的唯一方法是通过 FTP 进入闪存并从 SiPy 中删除 main.py 文件 模块。

如果您不小心添加了无限 while 循环,则无需担心,因为您仍然可以通过 FTP 上传程序或删除前一个程序。首先,去下载filezilla免费版本并安装它。

安装后,您将需要设置连接。首先打开filezilla并进入文件下的站点管理器或按Ctrl + S并按新站点。

您可以将站点重命名为 SiPy 或任何您想调用此连接的名称,并将加密设置更改为仅使用普通 FTP(不安全) 并将设置转移到 passive 并将活动连接数限制为 1

您可以通过按所有命令并选择全局设置,通过 Visual Studio Code 找到主机(地址)、用户和密码。 这将显示主机(地址)、用户(用户名)和密码的默认设置。这可以通过按项目设置来更改 在所有命令中。

接下来,您需要知道 SiPy 模块 SSID,可以使用所有命令并按获取 WiFI AP SSID 找到它。 每个 SiPy 模块 SSID 都是唯一的,但密码始终相同且无法更改。 SiPy 模块 SSID 的密码是 www.pycom.io

注意: 桌面用户需要获得一个 WiFi 适配器

现在您可以开始使用 filezilla 来访问 SiPy Flash!首先连接到 SiPy SSID,然后转到 filezilla 站点管理器并连接到您创建的新站点并输入密码。现在打开 flash 文件夹并删除 main.py ONLY! 删除 main.py 后,重启 SiPy,您就可以开始运行/上传您的程序了。

注意: 您可能希望将 flash 文件夹复制到您的操作系统(操作系统)上,以防您删除所有内容。

5. 注册 Sigfox 后端

安装Visual Studio Code后,将pycom扩展板连接到电脑,打开Visual Studio Code会自动检测连接。复制下面的代码并将其粘贴到终端或文件中并运行它。 任何一种方法都可以。

from network import Sigfox
import binascii

# 初始化 Sigfox for RCZ*(您可能需要不同的 RCZ 区域)
sigfox =Sigfox(mode=Sigfox) .SIGFOX, rcz=Sigfox.RCZ*)

# 打印 Sigfox 设备 ID
print(binascii.hexlify(sigfox.id()))

# 打印Sigfox PAC 编号
print(binascii.hexlify(sigfox.pac()))

注意 :将 * 替换为您的 RCZ 地区编号。

获取 Sigfox 设备 ID 和 PAC 编号的终端方法

在 Visual Studio Code 中调出终端按 Ctrl+~。然后将代码粘贴进去,就会如下图所示。

获取 Sigfox 设备 ID 和 PAC 编号的文件方法

通过按 Ctrl+S 保存新文件或转到文件然后保存后,将代码粘贴到文件中并保存文件,然后您可以通过按运行按钮来运行该文件 在屏幕底部,应该与下图相同。

获得您的 Sigfox 设备 ID 和 PAC 编号后,您需要将您的 Sigfox 注册到 Sigfox 后端,然后才能开始向其传输。您看到的第一页将是您的 sigfox 公司所在的位置。您必须选择使用此 Sigfox 设备的国家/地区,因为每个 Sigfox 区域的配置都不同。

选择正确的国家后,下一页将需要您在本章开头获得的 Sigfox 设备 ID 和 PAC 编号。将它们粘贴到正确的字段中,页面应该看起来像图片吹。至于剩下的就相应地补上。

填写设备页面后,创建 Sigfox 帐户或登录现有的 Sigfox 帐户,您必须将 Sigfox 注册到您的帐户。如果您要创建新的 Sigfox 帐户,Sigfox 会向您注册的邮箱发送一封电子邮件以设置密码。

设置 sigfox 后端帐户后,您可以运行此代码发送一些数据,看看后端是否可以接收它们。

注意**: 在运行任何 sigfox 程序之前先连接您的 sigfox 天线。

from network import Sigfox
import socket

# 初始化 Sigfox for RCZ*(您可能需要不同的 RCZ 区域)
sigfox =Sigfox(mode=Sigfox) .SIGFOX, rcz=Sigfox.RCZ*)

#创建一个Sigfox socket
s =socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)

#使套接字阻塞
s.setblocking(True)

#只配置为上行
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)

# 发送一些字节
s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))

注意 :将 * 替换为您的 RCZ 地区编号。

6. 设置云

首先,您必须设置 IFTTT 以发送电子邮件,访问 IFTTT 网站并创建一个帐户。设置帐户并登录后,转到位于“探索”左侧屏幕右上角附近的个人资料,然后按创建 .

点击“这个 " 然后搜索 Webhooks 并按下它。如果您不确定,以下图片将帮助您解决问题。

After selecting Webhooks, press the Receive a web request box and enter an event name to fit your requirements (in this example fever is used), afterwards press Create trigger .

Press the word "That ", type email in the search box and press Email then press Send me an email box

Enter message information. You can pass data about the event that triggered your message by using ingredients. For example, including {{Event Name}} adds the event name to your text message. The Body section must include at least {{Value1}} and {{Value2}}. Click Create action to finish the new applet. Note:Value 1, value 2 and value 3 in body message are derived from MATLAB Analysis and can be modified according to your requirement

ThingSpeak is an IOT (Internet of Things) platform which can be easily setup, learned and is open source.

First, we create two channels; (SIGFOX) TEMPERATURE PRIVATE VIEWING &(SIGFOX) TEMPERATURE PUBLIC VIEWING.

For the (SIGFOX) TEMPERATURE PRIVATE VIEWING , its purpose is to obtain data from the Sigfox backend. Sigfox sends up using bytes, this is because, we have realised that Ubidots (a web service) do not really work well with decoding Strings, so to make it work and accessible with both ThingSpeak and Ubidots, we chose to use bytes as it contain numbers from 0-255.

Therefore, using bytes makes it so we have to send both the whole number and the decimal number of the temperature information separately. So, this channel is mainly for keeping these messy values, later transferring to another channel for viewing which is the (SIGFOX) TEMPERATURE PUBLIC VIEWING channel.

We use MATLAB Analysis to convert the two messy values (whole number &decimal number) into just one combined value and transfer it onto the other channel. At the same time, we also transfer the userID onto the (SIGFOX) TEMPERATURE PUBLIC VIEWING as it's used for viewing. The MATLAB script is triggered on data insertion using a ThingSpeak REACT which will be explained below.

To setup the react, first go to Apps and then select React which will open the reacts tab. Press New React to create a new react for the MATLAB Analysis to be triggered when new data arrives from the Sigfox backend. Set the condition type to string, test frequency to on data insertion, condition to field 3 (which should be your userid) of the (SIGFOX) TEMPERATURE PRIVATE VIEWING when its not equal to 0, action to MATLAB Analysis with the code for calculating the temperature and Options to Run Action only the first time condition is met.

The table code was taken from an open sourced project and modified to suit our needs. It's very useful as the table auto updates every time a new data is sent in, perfect for our usage.

Unfortunately, the MATLAB plugin for the table is only view-able in private view and not in the public view. As it's intended for administrative purposes only, we do not subject this as an issue, it's intended to be only viewed in private view.

To retrieve Webhooks information, Click on your profile logo near the top right corner of the screen on the left of the “Explore” tab. Select My Services, select Webhooks then click documentation near the top right of the web page, from there you can see your key and format for sending a request. Enter that event name. The event name for this project is fever

https://maker.ifttt.com/trigger/{event}/with/key/(example)

https://maker.ifttt.com/trigger/fever/with/key/(example)

The service can be tested to see if it works or not by pasting the URL(example of the URL are shown above) into your browser or pressing the test button upon creation of the webhooks and email applet

After all that is done, you should be able to receive an email like the following picture, after you have finished setting up the ThingSpeak React.

Contributions

Aden - RaspberryPi + Arduino + its modules + ThingSpeak (MATLAB+ Setup)

Reginald - Sigfox + ThingSpeak Data Collection + Schematics

Bo Sheng - IFTTT Setup

代码

  • [C] ARDUINO NANO
  • [PYTHON] RaspberryPi
  • [MicroPython] Sigfox (Pycom)
  • [ThingSpeak] MATLAB SCRIPT
[C] ARDUINO NANOArduino
This code is used for checking if there's a RFID card tap, if there is, there will be temperature taking and also handshaking between the Raspberry Pi to send data over like the card's ID, temperature and ready/standby signal and more.

It also uses LCD to show informative information.

If you're interested in knowing more, please read the section on "HOW IT WORKS:RaspberryPi &Arduino"
/*90% is coded from scratch by Aden,http://www.astero.methe other 10% consists of open sourced libraries(Credits found below) used, like the RFID &temperature module.*//* * Initial Author:ryand1011 (https://github.com/ryand1011) * * Reads data written by a program such as "rfid_write_personal_data.ino" * * See:https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data * * Uses MIFARE RFID card using RFID-RC522 reader * Uses MFRC522 - Library * ----------------------------------------------------------------------------------------- * MFRC522 Arduino Arduino Arduino Arduino Arduino * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro * Signal Pin Pin Pin Pin Pin Pin * ----------------------------------------------------------------------------------------- * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST * SPI SS SDA(SS) 10 53 D10 10 10 * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15*//***************** This is a library example for the MLX90614 Temp Sensor Designed specifically to work with the MLX90614 sensors in the adafruit shop ----> https://www.adafruit.com/products/1748 ----> https://www.adafruit.com/products/1749 These sensors use I2C to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ******************/ // INCLUDE NECESSARY HEADER FILES #include #include #include #include #include #include // DEFINITION OF PINS#define RST_PIN 9 // Configurable, see typical pin layout above#define SS_PIN 10 // Configurable, see typical pin layout above#define BUZZER_PIN 7 //Pin define for Buzzer#define LED_PIN 6 //Pin define for LED #define dist_sensePin A0MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.LiquidCrystal_I2C lcd(0x27,16,2); // Calls the LiquidCrystal class and creats an instance for the LCD.// set the LCD address to 0x27 with 16 chars and 2 line displayAdafruit_MLX90614 mlx =Adafruit_MLX90614(); // Calls the Adafruit MLX90614 instance.SoftwareSerial unoSerial(2, 3); // RX, TX // Calls the SoftwareSerial instance (for Pycom communication)// GLOBAL VARIABLESboolean tapped =true; boolean confirmation =false;String GetUID(){ String card_UID=""; String card_UID_no_space =""; for (byte i =0; i  200)) // Check if there is actually a valid user infront of the machine. If no, it'll keep looping what's under. { dist_senseValue =analogRead(dist_sensePin); // Keep checking until there's a person that comes in the distance sensor's range. lcd.setCursor(0,0); lcd.print("Please take"); lcd.setCursor(0,1); lcd.print("your temperature."); // Prompt the user to take their temperature by standing infront of the machine. } digitalWrite(BUZZER_PIN, 1); digitalWrite(LED_PIN, 1);液晶显示器(); // Turns on the Buzzer and LED, at the same time, clear the LCD too. meas_temp =(float)mlx.readObjectTempC(); temp_Hbyte =floor(meas_temp); temp_Lbyte =(meas_temp - temp_Hbyte) * 100; sMeasTemp +=userID; sMeasTemp +=","; sMeasTemp +=temp_Hbyte; sMeasTemp +=","; sMeasTemp +=temp_Lbyte; // Collect the temperature data that is taken. Serial.println("TEMP"); Serial.println(meas_temp); // Transfer the temperature data through Serial Communication to the RaspberryPi. if((meas_temp>
=28) &&(meas_temp <=42)) // Check if it's a valid temperature. unoSerial.print(sMeasTemp); // If it is, send to the sigfox module for cloud storage. lcd.setCursor(0,0); lcd.print("温度:"); lcd.setCursor(0,1); lcd.print(" " + String(meas_temp)); // Shows the temperature of the user through the LCD screen. } else // If it's an invalid user, { lcd.setCursor(0,0); lcd.print("Error!"); lcd.setCursor(0,1); lcd.print("Invalid User."); // Tells the user that he's not a valid user and he is unable to proceed to the temperature taking phase. } rawData =Serial.readString(); commaPos =rawData.indexOf(','); userInitial =rawData.substring(0, commaPos); // Above reads the incoming rawData again and converts into a userInitial variable. if(userInitial =="0") // If the user initial sent back is 0, it means that it's an invalid temperature because the RaspberryPi is unable to process it. { lcd.clear(); lcd.setCursor(0,0); lcd.print("Error!"); lcd.setCursor(0,1); lcd.print("Invalid Temperature."); // Prompts the user it's an invalid temperature range. } Serial.println("STANDBY"); // Sends Serial that the Arduino is still processing data.延迟(1000); // Delay for 1 second. mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); } }
[PYTHON] RaspberryPiPython
This code is mainly used for updating the MySQL database and also to handshake with the Arduino via Serial Communication. It plays a vital role with the Arduino in this project

If you're interested in knowing more, please read the section on "HOW IT WORKS:RaspberryPi &Arduino".
'''Coded from scratch by Aden; for the Hackster.io Sigfox competition.http://www.astero.me'''# IMPORTSimport mysql.connectorimport serialimport osimport time# METHODSdef queryConnection():cursor =conn.cursor(buffered=True) cursor.execute("USE `" + databaseName + "`") # Use the userInfo database, return cursor # DATABASE INFORMATIONhost ="localhost"user ="root"password ="password"databaseName ="smartTemp"conn =mysql.connector.connect(host=host, user=user,passwd=password)# Serial CommunicationcomPort ='ttyUSB0'baudRate =9600ser =serial.Serial('/dev/' + comPort, baudRate, timeout=0) # Set the timeout as 0 so if it doesn't read a serial, it skips.print("Confirming USB Serial Port now, please wait") connected =False# Below, is to ensure that the RaPi receives the correct COM port of the Arduino board.for x in range(2):time.sleep(2) ser.write("RAPI") # Basically, here, we're writing to the Arduino to confirm communication. if connected ==False:serialConfirmation =ser.readline().strip() =="ARDUINO" # Check if the RaPi is reading the correct COM port, whether it can read the Arduino's serial communications. print(serialConfirmation) if(serialConfirmation ==False):comPort ='ttyUSB1' connected =True else:comPort ='ttyUSB0' connected =True print(comPort) ser =serial.Serial('/dev/' + comPort, baudRate) # Re-initiates this variable again, this time without a Serial Communication timeout. Meaning, it'll try to communicate with the Arduino w/o a timeout. print("COM PORT confirmed, using " + comPort) # Print to let you know which PORT the Arduino is on.# File CreationcountFile =open("count.txt", "a++") # Creates a count file if it doesn't exist.# GLOBAL VARIABLEStapRFID =Falsecursor =queryConnection()if(os.stat("count.txt").st_size ==0):# Checks if the count.txt is empty. print("Count has not been set, setting to 1 now.") count =1else:for countNumber in countFile:count =int(countNumber) # Set the count to the last counted count. print("Count has been restored from previous session:" + str(count)) try:# Tries to create the database if it doesn't already exists. print("Creating " + databaseName + " database now..") cursor.execute("CREATE DATABASE " + databaseName) # Create a database. print("Database has been sucessfully created.") except(mysql.connector.errors.DatabaseError):# If the database already exists, it excepts here. print(databaseName + " database is already created.") # If that database is found, run this block of code instead.cursor.execute("CREATE TABLE IF NOT EXISTS `userInfo` (id int, cardID VARCHAR(9), userID VARCHAR(4), userInitial VARCHAR(8))") # Create a userInfo table if it doesn't exist.cursor.execute("CREATE TABLE IF NOT EXISTS `tempData` (id int, userID VARCHAR(4), dateMeas date, timeMeas time, tempMeasure decimal(5,2))") # Create a tempData table if it doesn't exist.while True:# Endless loop. cursor =queryConnection() # Re-establishes the query connection using the queryConnection() method. cardID =str(ser.readline().strip()) # Reads the serial line and converts it to a String, stripping any empty spaces. cursor.execute("SELECT * FROM userInfo WHERE cardID ='" + cardID + "'") # Select the userInfo table with the inputted cardID from the Arduino. items =cursor.fetchone() # Fetch one line of the table. if(items !=None):# If it's able to fetch (valid user) print(cardID) # Print out the cardID that it's currently fetching. userID =str(items[2]) # Gets the userID from the fetched line. userDetails =str(items[3] + ", " + items[2]) # Get the userDetails from the fetched line. # Get the currentDate ¤tTime. currentDate =str(time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()))[0:10] currentTime =str(time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()))[11:] print(items) # Print the whole item array that was fetched. (for debugging) ser.write(b'' + userDetails) # Serial communication to the Arudino. countFile.close() # Closes the count file. countFile =open("count.txt", 'w') # Makes it so it overwrites the count file with the new saved count below. tempSignal =False while(tempSignal ==False):# Keeps looping until it gets the temperature reading from the Arduino. print("Getting Temperature") tempSignal =ser.readline().strip() =="TEMP" # Read the Arudino incoming serial. tempData =float(ser.readline().strip()) # Read the Arduino incoming serial of the temperature data. print(tempData) # Prints the retrieved temperature data from the Arduino. if(tempData>=28 and tempData <=42):# Check if the temperature is of a valid range. cursor.execute("INSERT INTO `tempData`(`id`, `userID`, `dateMeas`, `timeMeas`, `tempMeasure`) VALUES (" + str(count) + ",'" + userID + "','" + currentDate + "','" + currentTime + "','" + str(tempData) + "')") # Write into the database the necessary information. conn.commit() # Commit the INSERT changes into the database. count =count + 1 # Ups the count. countFile.write(str(count)) # Update the count file with the new count. else:# If it's not a valid temperature. ser.write(b'' + "0, 0") # Serial Communication to the Arduino informing that it's invalid temperature. else:# If it's not a valid user. ser.write(b'' + ", 0") # Serial Communication to the Arduino informing that no valid cardID is found. print("Nothing found") readySignal =ser.readline().strip() =="STANDBY" # Waits for the Arduino to tell that it's ready to do it again, to read/validate data. while(readySignal ==True):# If the Arduino is ready, loop until we're able to tell him back that we're also ready for another session. ser.write(b'' + "READY") # Serial communication basically to say we're ready too. print("sending") receivedSignal =ser.readline().strip() =="RECEIVED" if(receivedSignal ==True):readySignal =False print("received") cursor.close() # Close the query connection to prevent memory leaks. conn.close() # Closes the connection to the MySQL.
[MicroPython] Sigfox (Pycom)Python
This code is mainly used to read the serial communication from the Arduino and upload the received values to the Sigfox backend

If you're interested in knowing more, please read the section on "HOW IT WORKS:Sigfox (Pycom)"
'''100% is coded by Reginald,'''from machine import UART # Tx and Rx (``P3`` and ``P4``)from network import Sigfox # Import the sigfox library from the pycom controllerimport binascii # Import the Binary to ASCII library for converting from Binary (1,0) to ASCII (readable characters)import socket # Import socket module to enable socket connection for Sigfoximport time # Import time that can be used for delaysimport pycom # Import pycom module that contains fucntions that controls the pycom deviceimport sys # Import sys module to enable exit from the pycom running programpycom.heartbeat(False)#init Sigfox for RCZ4 (Asia)sigfox =Sigfox(mode=Sigfox.SIGFOX,rcz=Sigfox.RCZ4)uart1 =UART(1, baudrate=9600) # To set the serial communcation parametersuart1.init(9600,bits=8,parity=None, stop=1, pins =('P3', 'P4'), timeout_chars=20) # To set the serial communcation parameterswhile True:try:recv=uart1.readline() # It always reads the serial communcation for any messages if recv !=None:'''If there is a message recieved from the serial communcation, it will procced to establish the sigfox connection and process the message for sending''' #print Sigfox DeviceID print(binascii.hexlify(sigfox.id())) # print Sigfox PAC number print(binascii.hexlify(sigfox.pac())) #create Sigfox socket sk1 =socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) #make thesocket blocking sk1.setblocking(False) #configure as uplink only sk1.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) dataList =recv.decode("utf-8") #decode the received message print("dataList :%s" %(dataList)) split_val =dataList.split(",") #split the listing based on commas # eg. if receive message is 8,35,60 -> userID =8, temperature =35.60 degree celsius userID =int(split_val[0]) # assign the 1st element in the listing to userID. temp_H =int(split_val[1]) # assign the 2nd element in the listing to the whole number of the temperature. temp_L =int(split_val[2]) # assign the 3rd element in the listing to the decimal numner of the temperature. print("userID :%d temp_H :%d temp_L :%d" % (userID, temp_H, temp_L)) bData =[userID,temp_H,temp_L] # create a list print(bData) meas_temp =temp_H + (temp_L*0.01) # merge temperature values print("measure temperature :%.2f" %(meas_temp)) sk1.send(bytes(bData)) #cast the data list to bytes and send to Sigfox backend. sk1.close() #close Sigfox socket connection. time.sleep(5) #delay for 5 seconds. except KeyboardInterrupt:sys.exit() 
[ThingSpeak] MATLAB SCRIPTMATLAB
This script focuses on combining the raw data that is sent up by the Sigfox to ThingSpeak and put them together into a presentable visual state, allowing users to properly visualize the information. It also works alongside with IFTTT by triggering a webhook URL when it reaches a fever temperature, alerting user(s) via Email.

If you're interested in learning more about this code, please read the section on "HOW IT WORKS:ThingSpeak".
%% Made from scratch by Aden; for the Hackster.io Sigfox Competition.%% http://www.astero.mereadChannelID =870479; %% Channel to read.webhookTrigger ='https://maker.ifttt.com/trigger/student_fever/with/key/h10MdSGwjSPtZQ43wH-AgoiKI0pwaljBNnGUEu4Yecn';readAPIKey ='QGHINBPNJQKULBH2'; %% Channel read API Key.writeChannelID =870482; %% Channel to write.writeAPIKey ='R6NJIM8NT5A42R9N'; %% Channel write API Key.wholeNumber =thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', 1); %% Read the value from field 1 and save it to a variable.decimalNumber =thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', 2)/100;%% Read the value from field 2 and save it to a variable.userID =thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', 3);%% Read the value from field 3 and save it to a variable.display(wholeNumber, 'BEFORE') %% Display value for debugging.analyzedData =wholeNumber + decimalNumber; %% Converting the two into one whole number instead of two separate values.display(analyzedData, 'AFTER')display(userID, 'USERID')%%thingSpeakWrite(writeChannelID, analyzedData, 'Fields', 1, 'WriteKey', writeAPIKey);thingSpeakWrite(writeChannelID,'Fields',[1,2],'Values',{analyzedData,userID},'WriteKey', writeAPIKey)if(analyzedData>=38) %% Check if fever temperature. webwrite(webhookTrigger,'value1',analyzedData,'value2',userID); %% If yes, trigger the webhook and send an email of the values.end

示意图

How everything is connected together Connections for Distance Sensor for Arduino Connections for Temperature Sensor Connections for LED for Arduino Connections for RFID for Arduino Connections for LCD for Arduino Connections for Buzzer for Arduino

制造工艺

  1. Raspberry Pi 上的温度监控
  2. 使用 Raspberry Pi 监测温度
  3. DIY:HomeBrew 的温度监控和调节
  4. 使用 K30 传感器监测二氧化碳
  5. 智能百叶窗
  6. 非接触式温度监控门
  7. Arduino - 通过串口向 Web 发送温度
  8. Arduino 的 8 位 IO 端口库
  9. 智能手套
  10. Arduino 的 64 键原型键盘矩阵
  11. 健康手环——老人智能助手
  12. 智能农业:农业监测的综合物联网解决方案