aerobotics

[Training Camp_Advanced Class] Innovative IoT Smart Socket

 
Overview

Innovative IoT smart power strip (with videos and tutorials)

A picture is worth a thousand words

1597818891048.jpgimage.png

Features

switch function

  • Supports independent control of four-way switches, providing greater control freedom
  • Support timing switch control, more intelligent
  • Supports voice assistant operations such as Google Assistant, which is convenient and fast
  • Buttons can control switches and air conditioning

Monitoring function

  • Supports detection of ambient temperature and humidity
  • Support key operation to display four-way switch status
  • (Abandoned for iteration) Support power detection

other functions

  • Supports being used as an infrared remote control to control other infrared devices (air conditioners, TVs, projectors, etc.), making remote control of non-intelligent devices possible
  • Supports one-click network configuration via mobile APP
  • Support IFTTT scene automation
  • Support OTA firmware upgrade
  • Connect to HomeAssistant private IoT platform , support multi-platform App and web client, public network HTTPS access

Technical features

The product is designed with practical applications in mind

  • Supports 100-240V ultra-wide voltage, more suitable for global use; plug and play, no need for other external power supply
  • The PCB design is compact, streamlined and small (7.43cm * 6.56cm), which is easy to embed into the socket, and connect to the socket of the socket with the shell and a single copper wire (or copper sheet)
  • The infrared remote control function supports the use of standard 38kHz equipment (air conditioners, TVs, etc.), and remote control learning functions can be added in subsequent iterations.
  • Focus more on commercial product design: no GPIOs are drawn out on the PCB, no circuits unrelated to practical applications such as USB-TTL serial ports are designed, and only test points for debugging are retained.
  • The temperature and humidity sensor uses a female base or flying wire, which can better expose the sensor to the environment to ensure collection accuracy. The humidity error is +-3%RH, and the temperature error is +-0.3°C.
  • The software supports OTA (Over The Air) firmware upgrade. Users can easily upgrade the device by operating the client, and the cloud can also promptly repair major software vulnerabilities.
  • One-click network distribution technology based on espressif's SmartConfig Demo

Hardware selection

type model Advantage cost
Main control+Wifi ESP8266-12F It has a high main frequency, strong processing performance, and low cost, making it very suitable for use in node-type smart devices. ¥8.86
AC-DC HLK-PM01 It has a powerful output capability of 5V@3W. The output voltage and ripple are very stable and can be used to drive four relays. ¥19.29
LDO SPX3819M5-L-3-3/TR Compared with AMS1117, it saves considerable space, and its 500mA output capability is sufficient to handle high-power RF circuits. ¥0.86
drive NUD3105DMT1G The ultra-small package inductive driver saves the huge space occupied by dual MOS with the same principle. ¥1.66 * 2
drive 74LVC2G14GW Inverter to prevent the relay from being accidentally triggered when the main control is reset. ¥0.37 * 2
sensor ACS715ELCTR-05B-T A sensor based on the Hall effect with ultra-high response frequency (unfortunately, the bias voltage of Vout's VCC/2 was misunderstood) ¥12.21
sensor SHT30 Temperature and humidity sensor with lower temperature drift and higher accuracy, and extremely fast response speed ¥11.30
relay SRD-DC5V-SL-C Songle is a professional relay factory with a history of more than 20 years. Its quality has been certified by authorities from Germany, the United States, China and other countries. ¥2.11 * 4

human-computer interaction

voice control

Currently, the following functions of Google Assistant voice control are supported:

  • Turn air conditioner on or off
  • Set air conditioner temperature
  • turn on off light
  • Turn on or off individual or all switches

1597822070403.jpg

client

Regarding user operation experience, a user-friendly client and interface cannot be underestimated. The open source HomeAssistant project is used here, which supports IoT devices and even vehicles connected to unknown protocols of some third-party companies.

  • Second response, second start client operation interface; supports HTTPS access, more secure
  • Highly supports UI customization
  • Custom device supporting MQTT protocol
  • Supports common smart home functions such as IFTTT and scenes

client.jpg

server

In order to cope with various complex network environments and the difficulty of MCUs in dealing with network protocols, we chose the MQTT protocol to ensure efficient, fast and stable transmission of signals. As we all know, the MQTT server in the MQTT protocol is very critical. It is responsible for forwarding subscription and publishing information from devices and users, so it is a key transfer center. Here we choose the EMQ MQTT server developed by Chinese people. The operating environment is Debian10, and the service operation failure rate is extremely low.

  • Support public network devices accessing MQTT server
  • It has a graphical management interface to facilitate debugging and management of subscriptions, topics, clients, etc.

3.jpg

other

More in-depth testing

In order to enable smart devices to cope with more complex actual application environments and more demanding network conditions, I simulated some actual possible faults and made some solutions.

  • No Wifi/Don’t want to configure the network: Prevent some applications from being unable to connect to the Internet and throwing exceptions when the device does not have Wifi.
  • No Internet: Prevents MQTT from being unable to connect to the server and causing an infinite loop, causing WDT to be reset due to the inability to feed the dog.
  • Human-machine experience optimization: Prevent the platform from delaying receiving status information after button operation
  • Bug fix: hair loss

Existing flaws

Since it is only the first version of the PCB and has not been iterated yet, there are some initially considered features that have not been implemented.

  • The ACS712 current sensor currently exceeds the ADC range of the ESP8266 due to the bias voltage, making it impossible to measure.
  • Indicator LEDs and infrared LEDs multiplex the same GPIO. Future expansion functions may limit the richness of LED indication functions.
  • The GPIO2 where the button is located will affect the selection of the ESP8266 startup mode. Therefore, when the user presses the button when powering on, it may affect the use of the product and affect the user experience.
  • At present, the GPIOs of ESP8266 are almost all used up, but after debugging in the future, the serial port can be disabled to add two GPIOs.

development environment

PCB drawing

Use the efficient, permanently free domestic PCB design tool: Lichuang EDA. In the current stage where multi-person collaboration is so important, Lichuang EDA has greatly improved the development speed and progress of small teams. In addition, compared with other large-scale PCB drawing software, it has the advantage of extremely low environmental configuration requirements. It is extremely friendly to novices and can be quickly started. It omits some uncommon parameters and presets some commonly used parameters. 1.jpg

software development

The main control adopts Essence's ESP8266-12F/S module, which has the advantages of high main frequency, stable operation, and extremely low cost. It combines WiFi and MCU into one, which greatly improves the development efficiency of developers. For the host computer environment, you can choose espressif's eclipse-based IDE, or you can use Arduino's ESP8266 compatibility library. Limited by the cost of learning time, the latter is chosen here. At the same time, like OSHWhub, it also has a large open source community, which reduces the difficulty of development. 2.jpg

Demo video

See end of page

Note: The EBeam smart home APP used in the distribution network in the video is developed based on ESP Touch and has been shared in the attachment.

Experience

Through this training camp organized by Lichuang EDA, I got to know Lichuang EDA more comprehensively. Compared with other large-scale PCB design software, it is lightweight, free, and saves time and effort in developing applications. It helps us beginners get started quickly. It may save some unnecessary time. In addition, this is also my first time designing a strong current application, and almost the first time I actually design a practical (commercial) application. At the same time, I would like to thank the training camp for this opportunity, which allowed me to come into contact with more IOT platforms, understand more ICs, and more practical websites.

Technology sharing (hard core tutorials)

  • Physical resource requirements: idle PC or Raspberry Pi. This tutorial is more specific to PCs. Of course, you can also choose Alibaba Cloud lightweight application servers, which are sufficient to handle this instance application.
  • System environment requirements: deb system, Debian9 / Debian10 recommended

Basic environment setup

Docker environment installation

  • Docker engine installation tutorial: For details, please refer to the tutorial . You can choose between "automatic installation using the official installation script" and "manual installation".
$ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
$ docker volume create portainer_data
$ docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Note: Portainer is a graphical management interface that facilitates managing Docker through the web ( http://your-server-ip:9000/), not required

EMQ MQTT server installation

  • There are two options for installing the MQTT server, installing it in Docker and not relying on the Docker engine. In most cases, I recommend the former, but in my environment, installing it in Docker will cause trouble and cannot be started.
  • Docker environment installation: see official documentation for details
  • Does not rely on Docker installation: For details, please refer to the official documentation . Scroll down to find "Install EMQ X using the repository" of "Debian". The actual test supports Debian10
$ sudo apt update && sudo apt install -y 
    apt-transport-https 
    ca-certificates 
    curl 
    gnupg-agent 
    software-properties-common
$ curl -fsSL https://repos.emqx.io/gpg.pub | sudo apt-key add -
$ sudo add-apt-repository 
    "deb [arch=amd64] https://repos.emqx.io/emqx-ee-ce/deb/debian/ 
    $(lsb_release -cs) 
    stable"
$ sudo apt update
$ sudo apt install emqx-ee
$ emqx start
$ sudo systemctl start emqx
$ sudo service emqx start

EMQ MQTT server configuration

  • After the installation is complete, you can access the EMQ MQTT backend through http://your-server-ip:18083/
  • It is recommended to select General->User at the bottom of the left menu to create a new user for use.

HomeAssistant installation

$ docker run -d --name="home-assistant" -v /PATH_TO_YOUR_CONFIG:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant:stable

Note: Change "/PATH_TO_YOUR_CONFIG" in the command to the directory in your physical machine where you want to save data , such as "/root/hassdata"

HomeAssistant configuration

  • After the installation is complete, you can access the HomeAssistant backend through http://your-server-ip:8123/
  • The configuration of HomeAssistant is mainly achieved by modifying the "configuration.yaml" configuration file in the directory where the data is saved . Therefore, you need to have a shallow understanding of yaml to modify it. When you are not sure, please back up the original file first.
  • Share some of my configuration files. After copying and restarting from the background, you should be able to use them.
default_config:

sensor:
  - platform: mqtt
    name: "次卧温度"
    state_topic: "home/secbedroom/temp"
    unit_of_measurement: '°C'
  - platform: mqtt
    name: "次卧湿度"
    state_topic: "home/secbedroom/humi"
    unit_of_measurement: '%RH'

climate:
  - platform: mqtt
    name: 次卧空调
    fan_modes:
      - "auto"
      - "quiet"
      - "1"
      - "2"
      - "3"
      - "4"
      - "5"
      - "turbo"
    swing_modes:
      - "off"
      - "on"
    mode_command_topic: "home/secbedroom/ac/modectrl"
    mode_state_topic: "home/secbedroom/ac/modestat"
    temperature_command_topic: "home/secbedroom/ac/tmpctrl"
    temperature_state_topic: "home/secbedroom/ac/tmpstat"
    fan_mode_command_topic: "home/secbedroom/ac/fanctrl"
    fan_mode_state_topic: "home/secbedroom/ac/fanstat"
    swing_mode_command_topic: "home/secbedroom/ac/vswingctrl"
    swing_mode_state_topic: "home/secbedroom/ac/vswingstat"
    current_temperature_topic: "home/secbedroom/appatemp"
    min_temp: 16
    max_temp: 30
    temp_step: 1
    retain: false

switch:
  - platform: mqtt
    name: "插排开关1"
    command_topic: "home/secbedroom/socket/relay1ctrl"
    state_topic: "home/secbedroom/socket/relay1stat"
  - platform: mqtt
    name: "插排开关2"
    command_topic: "home/secbedroom/socket/relay2ctrl"
    state_topic: "home/secbedroom/socket/relay2stat"
  - platform: mqtt
    name: "插排开关3"
    command_topic: "home/secbedroom/socket/relay3ctrl"
    state_topic: "home/secbedroom/socket/relay3stat"
  - platform: mqtt
    name: "插排开关4"
    command_topic: "home/secbedroom/socket/relay4ctrl"
    state_topic: "home/secbedroom/socket/relay4stat"

automation: !include automations.yaml
group: !include groups.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

Arduino project source code

  • The source code is still being improved! I heard that likes + collections + comments can increase the speed!
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-17 16:23:11

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号