Overview
Due to the significant gender imbalance in Alibaba Cloud and the limited space of toilets, male colleagues have to wait in a special odor environment every day for limited stalls. We wondered if we could use IoT technology to create a low-cost solution that would allow male colleagues to know the availability of stalls without having to be on-site (like a parking lot). Based on our IoT division’s one-stop development platform – Link Develop, we aim to create an IoT smart toilet.
Technical Architecture

Preparation
Hardware
NodeMCU x9, PIR sensor x9, 1800mAh LiPo battery x9, waterproof box x9, usb mini connection cable x1
Software
Arduino IDE
Platform
Alibaba Cloud account, Link Develop platform access
Implementation
Establishing Device Model
The device model can be understood as a class or a template. It specifies the common attributes of a certain type of device and allows you to instantiate devices in bulk.


Enter the Link Develop platform, just like other cloud products, you need to complete the basic registration information first.

Next, we will enter a blank project page. At the top of the page, we need to click on “Create New Device Model”. Open the device model pop-up window, enter a name and define a category, here we can choose “Custom Type”. Then, after entering the details page of the device model, add standard functions – input infrared – select infrared detection status. We have completed a device model that can report infrared detection data. This model meets our needs.

Then we need to instantiate our toilet monitoring device. In the device model details page, click on the “Test Device” tab. Then create 9 different test devices with different device names (deviceName) in sequence. After each device is created, there will be a ProductKey, DeviceName, and DeviceSecret, which we collectively refer to as the “triple”, and we will use this later.

After completing these steps, the establishment and instantiation of the device model are OK. Next, we enter the Arduino code writing.
Hardware Development
The PIR has only three ports, which are VCC, GND, and output port. The wiring method is as follows (NodeMCU’s D7 is equivalent to Pin 13 in Arduino)

Then connect the USB cable. Open the Arduino IDE. Copy the following code:


Here are a few segments of code that need explanation:
Importing Libraries

If you haven’t used Arduino before, these libraries are not included with Arduino and need to be imported. Taking ArduinoJson as an example, see the specific operation method in the figure below:

Modify WiFi

Here you need to enter your home WiFi SSID (i.e., WiFi name) and password. The WiFi shown in the red box below, SSID is “TOM” (case-sensitive), and the password is “123456”

Modify Triple

This is the previously mentioned triple, fill in the corresponding triple for different devices.

Modify HashMAC Key

To ensure security, the Link Develop platform requires authentication for devices uploading data. Therefore, different Hmac values need to be configured for each device. The method is to first combine a segment of fields:
“clientIdtestdeviceName” + device name + “productKey” + device model identifier + “timestamp123456789” For example, the field for the triple shown in the screenshot is:
clientIdtestdeviceNamehuman01productKeya1rezUVs103timestamp123456789 After writing this field, go here to encrypt it. Select the HmacSHA1 method, using the above field as plaintext and deviceSecret as the key. See the figure below:

We can obtain the following ciphertext: e30657f36e7ded9a2781bba97b0dee79e8fa31b6, then replace the original field of MQTT_PASSWD.
After completing the code compilation, select the corresponding development board and upload it. After powering on, you can check the serial port and the test device list on Link Develop to see if it has successfully gone online.


Application Development
Click on Web Application Development in the left sidebar, select “Visual Application” and enter a name. Then you will enter the workspace for visual development of Web applications.

Next, we need a text component to represent titles and other information. We need an indicator light to show whether the current stall is occupied.

Next, we will take stall 1 as an example to illustrate how to bind the component to the device. Click on the “Data” on the right panel and select “Associate Device”. This will display all the test devices that have been created. Select the corresponding sensor for the stall, and then choose the data to be displayed (Boolean infrared monitoring status). This completes the data binding.

You can simulate going online to see if the association is successful. Additionally, some personalized styles can also be configured by yourself.

Next is the time to unleash creativity. You can upload various background images and add various small styles to create a dashboard like the picture. Finally, click the preview in the upper right corner.

This completes a dashboard! No need to endure, just check if there are available stalls! The tutorial for DingTalk push will follow up~
Deployment
This is the physical installation box. To provide a better user experience, we added a note on the box saying “Only detects occupancy, no camera” to avoid user privacy concerns.


During deployment, we used Raspberry Pi + display screen.

The smart toilet solution that benefits 90% of the employees on the fourth floor of Building One in Feitian Park is complete!
Welcome to use Link Develop
Link Develop (IoT Development Platform) is an end-to-end one-stop development service platform provided by Alibaba Cloud for the IoT field, covering various IoT industry application scenarios. It mainly solves the problems of long development chain, complex technology stack, high collaboration costs, and difficult solution migration in the IoT development field, providing a complete development process, framework/engine, and debugging tools from hardware development, service orchestration, web application development to mobile app development. It can also connect mature development outputs to the Alibaba Cloud market for sale, enabling developers to achieve commercial returns.
The two authors of this article are a colleague from an operations background and a colleague from a design background, neither of whom are professional engineers, yet they were able to complete the entire smart toilet solution setup based on Link Develop in just one day. We believe that after recognizing the development capabilities of the Link Develop platform, more innovative ideas will emerge, and IoT application development can be quickly realized using Link Develop!
Welcome to visit:
https://linkdevelop.aliyun.com
end
Thank you for your patience! “Code Efficiently: Java Development Manual” has been officially released.
At the Hangzhou Yunqi Conference, Alibaba Cloud made a big move, with 8K remote medical consultations attracting attention.
From complexity to simplicity, revealing the first look at Alibaba Cloud’s Feitian Luoshen system.
Introduction to Blink Testing Technology.
More Exciting Content