Because the inherent defects of this socket shell are difficult to solve, this project has been abandoned.
The new (complete) metering socket project can be found here: https://oshwhub.com/oldfox126/xin-guo-biao-wu-kong-ji-liang-cha-zuo-10a
-------------------------------------------------------------------------------------------------------------------------------------------
Magnetic holding WIFI metering socket (220V10A)
Statement:
This project is improved from my previous project: [Verified] Magnetic holding WIFI smart socket (220V10A) https://oshwhub.com/oldfox126/ci-bao-chi-wifi-zhi-neng-cha-zuo The biggest problem in production is neither hardware PCB nor software writing, but metering calibration (the value output by the metering chip is quite different from the actual value). Without professional power calibration instruments, it took a lot of effort to calibrate to the current level, which is far from perfect. The metering data of this socket can only be used as a reference and cannot be guaranteed to be 100% accurate.
I am a software major, not a student of electronic hardware, but an amateur. Therefore, I may not know a lot of basic hardware knowledge. If there is anything wrong with the circuit diagram, I hope you will give me some advice. Thank you very much.
Hardware Description:
1. This socket requires 2 PCBs, and the thickness of the 2 PCBs is 1mm. The PCB of ESP12S is located at: https://oshwhub.com/oldfox126/esp12s-shuang-mian-zhi-cha-mo-kuai-2x6p
2. The metering chip uses HLW8032, which is a high-precision metering IC. 3. Use an isolated power supply to output 5V to power the metering chip.
4. The relay is a magnetic latching relay, which only needs to be powered at the moment of action, and does not need to be powered to maintain the state later. Therefore, this socket has excellent power saving performance, and the overall power consumption is only about 0.65W, and long-term use will not cause the relay coil to heat up.
5. If during the PCB boarding process, the manufacturer prompts: the middle milling slot connection is too small, the board will be broken, etc., please reply: I have known and accepted the risks brought by this reason, please produce directly according to the Gerber file, thank you!
Software Description:
1. The compilation environment is VScode+PlatformIO2. Using the open source MQTT solution, you can get a cloud server with unlimited device quantity and service life without spending a penny.
Main functions of the software:
1. Support web page network configuration2. Support WeChat code scanning network configuration3. Support network synchronization NTP4. Support MQTT, which helps to understand the working mechanism of the Internet of Things more thoroughly. Use the switch, countdown timer, timer, etc. on the MQTT mobile APP to turn on or off the socket.
5. The timer program is implemented locally on the socket, not in the cloud. As long as the parameters are submitted and saved, even if the network is disconnected later, the socket can still be turned on or off regularly. Therefore, it is possible to physically restart the optical modem or router with this socket. 6. Support OTA online firmware upgrade, which can be upgraded through the network. No more painfully dismantling the board and re-flashing the firmware. 7. Support LittleFS file system, various parameters can be saved when power is off. Even if the socket is powered off and restarted, the original parameters are still there.
8. Support power metering, which can display real-time voltage V/current mA/power W, and total power consumption KWh.
Sources of related components:
1. Socket housing (including the 220V10A male and female integrated socket inside) -> Buy more than 2 at a time on Alibaba for cheaper prices
2. AC220V TO DC5V switching power supply module I have bought all the links on the right (Note: buy 5V with feet) -> Link 1 Link 2 Link 3

3. Side buttons (Note: buy H=5MM) -> Purchase link
4. ESP-12S module can be purchased ESP12E/F/S, and then make the board and solder it yourself: https://oshwhub.com/oldfox126/esp12s-shuang-mian-zhi-cha-mo-kuai-2x6p
5. Magnetic latching relay (Note: buy HF3F-L-05-1HL1T (10A 4 feet)) -> Purchase link
6. Magnetic latching relay driver chip MD7620A SOT23-6 -> Purchase link
7. In addition to these, I basically bought other components (including resistors, capacitors, AMS1117, ESP12S, light-emitting diodes LED, LTV-356T-B, HLW8032, etc.) at Youxin Electronics -> Youxin Electronics Taobao Store
8. ESP8266 development test stand/burner (only needed by beginners), I bought this one -> Purchase link
Software and hardware installation steps:
1. First flash the firmware for ESP12S, reference: https://oshwhub.com/article/ci-bao-chi-WIFIzhi-neng-cha-zuo-ruan-jian-gong-cheng-dao-ru-VSCODE-yi-ji-bian-yi-shuo-ming
2. Set the MQTT parameters for ESP12S network configuration, reference: https://oshwhub.com/article/ci-bao-chi-WIFIzhi-neng-cha-zuo-ruan-jian-diao-shi-shuo-ming
3. Install MQTT on the mobile phone APP, and set the MQTT server parameters, refer to: https://oshwhub.com/article/ci-bao-chi-WIFIji-liang-cha-zuo-pei-tao-de-shou-ji-APPshe-zhi-shuo-ming
4. Solder the ESP12S with the firmware to the PCB
5. First solder the resistors, capacitors, chips, etc. to the socket body PCB, and use solder paste + teppanyaki on the front for better soldering.
6. Install the male and female integrated sockets, magnetic latching relays, ESP12S modules, 220V-5V power modules, 5V isolation modules, LEDs, side buttons, etc. on the back of the PCB, and solder them all with an electric soldering iron (the place with more solder in the middle is to pass large currents, so additional soldering is required)
7. Various angles of the soldering (please ignore the white plastic that has been devastated in the picture, and too much washing water has been poured)



8. Shell installation test, ******Don't use glue******First assemble it roughly, in case of problems, you can rework. (It is best to test it on the plugboard, because the shell is not glued and can be easily pulled out)
9. After the test is complete, glue the shell together. It is recommended to use shoe repair glue -> link. The glue is very strong and you need to wait 24 hours for the glue to dry before you can use it.
Hardware update instructions:
2022/11/18
1. In order to make the raised plastic block on the plastic back cover top on the PCB, the position of the components was adjusted to bypass the four raised plastic blocks. But the largest protrusion in the middle still cannot be bypassed, so the protrusion can be cut off. Thanks @skcks 2. According to the design scheme of using the neutral line N as the reference ground designed by the big brother @EHE in the comment area, the schematic diagram and PCB diagram were redrawn. In theory, the live wire L is better as the reference ground, but when arranging the PCB, it was found that the component layout needs to be swapped left and right, which is too much work and easy to make mistakes. The live wire L is temporarily abandoned as the reference ground. Thanks @EHE
2022/11/11
According to the comments of the big brother in the comment area, the improvements are as follows:
1. The 5V isolated power supply is removed. However, because the 5V sampling signal needs to be converted to MCU 3.3V, the optocoupler cannot be saved. Thanks @LZGD
2. The PCB height is increased by 1mm. Thanks @小菜比
3. All traces are converted to arc traces. Thanks @小菜比
4. The position of the sampling resistor is readjusted. Thanks @小菜比
5. GND copper is added. Thanks to @小菜比
6. Because the 5V isolated power supply was removed, GND was directly connected to one end of the 220V. I felt that burning the pins became very dangerous, so I cancelled it.
2022/9/10
1. Hardware release (socket body PCB V0.4, ESP12S double-sided plug-in module 2x6P V2.2)
Software update instructions:
2022/11/23 In order to solve the problem of untimely display of power information: 1. Change the current time display to display once every 10 seconds; 2. The power data is changed to update every second, and a timestamp is added before the power, similar to 59:49|
2022/11/31. Fixed a logical error that the program would freeze and not continue to run when no metering data was read (such as flashing firmware and debugging on the programmer).
2022/10/26 1. In order to solve the problem of delayed display of the current time (because the power information needs to be displayed every second, causing too much data to be updated), the frequency of displaying power information is adjusted to display once every 10 seconds.
2022/10/41. Added a function: when the network is disconnected, if the network connection cannot be connected after 100 retries, the device will automatically restart. 2022/9/10
1. Software release
thanks:
Thanks to Jiali Chuang yyds, I have to make PCB boards every month.
Thanks: @yu_chengcheng @alei643 @全幼儿园最帅男人@御坂0x1BF52号@Mi_Story @ht19174023411 @daybeen @jpdd521 @WilliamLP @playzlov @Egbert @lycm @kkkkllll08 @san_shui @udzcn @maomaodemao @Along666 @iceworld @206435D @pxb8888 @Alex Yang @linxii @zhigao1986 @trainliang @ljtnine and other big guys who left comments in the comment area. Thanks to your opinions and suggestions, I have gained a lot of inspiration and learned more knowledge. Thank you very much!