daveFNbuck/toilet-bot

语言: Python

git: https://github.com/daveFNbuck/toilet-bot

当厕所空闲时,机器人会提醒人们。
Bot for alerting people when the toilet is free.
README.md (中文)

厕所BOT

厕所机器人是一个Arduino传感器系统,可以向Raspberry Pi报告浴室档位的可用性。然后将此信息发布到Slack。

传感器设置

硬件

Arduino传感器非常简单,由三部分组成:    - Arduino(建在面包板上,提高电池效率)    - 磁性开关    - NRF24L01 +无线收发器

一旦你连接了一切,它看起来像这样:

伸出底部的蓝色物体代表磁性开关。其中一根导线连接到标有COM的螺钉上,另一根导线连接到标有NO的螺钉(常开,门应该是)。将第4个引脚连接到地的下拉电阻应具有相对较大的电阻,因为这将是门关闭时的主要电流源。我使用了一个10k电阻,但更大的电阻也应该没问题。

要连接NRF24L01,上图中atmega328的左上方引脚为引脚15,引脚左侧的引脚增加。将引脚连接到收发器,如下所示:

atmega328 pin NRF24L01+ pin
15 CSN
16 CE
17 MOSI
18 MISO
19 SCK
20 VCC
22 GND

注意,不使用atmega328引脚21,也不使用NRF24L01上的IRQ引脚。您的接线可能与图中看起来不完全相同,因为不同的制造商可以为NRF24L01生成不同的引脚布局。例如,我的引脚是图中的引脚的镜像。

软件

一旦设备全部接线,您需要通过将以下库复制到Arduino安装的库目录中来安装它们:   - 低电量    - NR24

接下来,只需将sensor.ino加载到Arduino程序中进行编译并将其上传到芯片上。加载代码后,请检查串行监视器,看它是否为收件人显示了合理的设置信息。

设置硬件和软件后,将磁铁传感器连接到浴室门,使其仅在门关闭时关闭电路。请注意,此传感器仅在门未被占用时常开时才起作用。如果不是这样,您可能需要修改浴室门。如果可能的话,尽量将它们安装在门顶附近,以便将天线放置得尽可能高。如果你有一个金属档,你需要放置天线,这样失速门和墙壁就不会阻挡它到Raspberry Pi上接收器的路径。

一旦确定找到适合他们的贴纸,就可以通过去除覆盖贴纸的纸张来连接传感器。您可以在电路中添加LED(带有适当的电阻)以验证放置。它应该只在您关上门时点亮。您可能会想要使用背面贴纸来连接面包板。我提醒不要这样做,因为它使重新编程,重新布线和更换部件变得困难。相反,使用可移动的墙贴。无论如何,你会想要这些用于电池盒。您可能还需要将天线粘贴到位以确保良好的定位。任何磁带都可以做到这一点。

此设置应适用于任意多个传感器,但在某些时候通道将变得过载。到目前为止,我只尝试过2个传感器。

接收器设置

接收器包括    - 一个Raspberry Pi(因为我把它放在公共场所,我收到了一个带有案例的工具包)    - USB WiFi适配器(套件中附带)    - NRF24L01 +无线收发器    - (可选)红色和绿色LED,电阻器,二极管,电线,指示灯面包板

即将推出将NRF24L01 +连接到右侧引脚的示意图。

接收器的软件有几个要求:    - 在Raspberry Pi上启用SPI    - 运行sudo apt-get install python-dev python-rpi.gpio    - 运行pip install receiver / requirements.txt    - 将lib_nrf24.py复制到接收器目录或将其放在python路径上

以上将允许您的代码运行。现在你需要使用类似的格式将你的松弛凭证添加到receiver / slack conf.yaml

api_token: XXXXXXXXXX
channel: YYYYYYYYYY

请注意,通道必须是通道的api键,而不是其原始文本名称。机器人将改变频道的主题以反映浴室的可用性。如果您不想要这种行为,则必须修改代码才能摆脱它。您还必须设置sql表bathroom.availability或禁用代码的sql部分。 sql代码假设您有一个密码为bathroom_bot的用户浴室。通过写入数据库,您可以大大增加显示选项。您可以轻松地在Raspberry Pi上托管一个简单的PHP状态页面,作为Slack帖子的替代方案。

最后,您可能需要修改代码以处理您拥有的档位传感器数量。现在,它是2个传感器的硬编码。这反映在消息数组长度和chat_msg函数中。其他一切都应足够通用,以便在必要时处理更多机器人。

如果您包含可选指示灯,您可以将它们连接到引脚14和15.这将为您提供一个物理显示屏,指示浴室门的当前状态。

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

toilet-bot

Toilet bot is a system of Arduino sensors that report bathroom stall availability to a Raspberry Pi. This information is then posted to Slack.

Sensor setup

Hardware

The Arduino sensors are fairly simple and consist of three components:
- an Arduino (built on a breadboard for battery efficiency)
- a magnetic switch
- an NRF24L01+ wireless transceiver

Once you've wired everything up, it'll look something like this:
sensor circuit

The blue object sticking out the bottom represents the magnetic switch. One of the wires attaches to the screw labeled COM and the other to the screw labeled NO (for normally open, which the door should be). The pulldown resistor connecting the 4th pin to ground should have relatively large resistance, as this will be the main source of current when the door is closed. I used a 10k resistor, but larger resistances should be ok too.

To connect the NRF24L01, the top-left pin on the atmega328 in the above diagram is pin 15, and pins increase on the left side going down. Connect the pins to the transceiver as follows:

atmega328 pin NRF24L01+ pin
15 CSN
16 CE
17 MOSI
18 MISO
19 SCK
20 VCC
22 GND

Note that atmega328 pin 21 is not used, nor is the IRQ pin on the NRF24L01. Your wiring may not look exactly like in the diagram, as different manufacturers can produce different pin layouts for the NRF24L01. The pins on mine are a mirror image of the one in the diagram, for example.

Software

Once the device is all wired up, you'll need to install the following libraries by copying them into your Arduino installation's libraries directory:
- Low-Power
- NR24

Next, just load sensor.ino into the Arduino program to compile and upload it onto the chip. Once the code is loaded, check the serial monitor to see if it displays reasonable-looking setup information for the transciever.

Once the hardware and software are setup, attach the magnet sensor to the bathroom door such that it closes the circuit only when the door is closed. Note that this sensor only works if the door is normally open when not occupied. You may need to modify the bathroom door if this is not the case. Try to attach these near the top of the door if possible so that your antenna can be placed as high as possible. If you have a metal stall, you'll want to place the antenna so that the stall doors and wall don't block its path to the receiver on the Raspberry Pi.

You can attach the sensors by removing the paper covering their stickers once you are sure you're found a good placement for them. You can add an LED (with appropriate resistor) to the circuit to verify placement. It should only light up when you close the door. You may be tempted to attach the breadboard using the sticker already on its back. I caution against this as it makes reprogramming, rewiring and replacing parts difficult. Instead, use removable wall stickers. You'll want these for the battery case anyway. You may also need to tape the antenna in place to ensure good positioning. Any tape will do for that.

This setup should work with arbitrary many sensors, but at some point the channel will become overloaded. I've only tried it with 2 sensors so far.

Receiver setup

The receiver consists of
- A Raspberry Pi (I got a kit with a case since I put mine in a public place)
- USB WiFi adapter (comes in the kit)
- an NRF24L01+ wireless transceiver
- (optional) red and green LEDs, resistors, diodes, wires, breadboard for indicator lights

Diagram for attaching the NRF24L01+ to the right pins coming soon.

The software for the receiver has several requirements:
- enable SPI on your Raspberry Pi
- run sudo apt-get install python-dev python-rpi.gpio
- run pip install receiver/requirements.txt
- copy lib_nrf24.py to the receiver directory or put it on your python path

The above will allow your code to run. Now you need to add your slack credentials to receiver/slack_conf.yaml with a format like

api_token: XXXXXXXXXX
channel: YYYYYYYYYY

Note that channel must be the api key for a channel and not its raw text name. The bot will change the topic of the channel to reflect bathroom availability. If you don't want this behavior, you'll have to modify the code to get rid of it. You'll also have to either set up a sql table bathroom.availability or disable the sql part of the code. The sql code assumes you have a user bathroom with a password bathroom_bot. By writing to a database, you're greatly increasing the display options. You can easily host a simple PHP status page on your Raspberry Pi as an alternative to Slack posts.

Finally, you may have to modify the code to handle how many stall sensors you have. Right now, it's hard-coded for 2 sensors. This is reflected in both the message array length and the chat_msg function. Everything else should be sufficiently general to handle more bots as necessary.

If you included the optional indicator lights, you can hook them up to pins 14 and 15. This will give you a physical display indicating the current state of the bathroom doors.