Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use single Chip Microcomputer to quickly realize Family Intelligent Control platform

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to quickly realize the family intelligent control platform by using the single-chip microcomputer". The editor shows you the operation process through the actual case, the operation method is simple and fast, and the practicability is strong. I hope this article "how to use single-chip microcomputer to quickly realize family intelligent control platform" can help you solve the problem.

Realization of web Server based on 0x01 single Chip Microcomputer

Several articles about using single-chip microcomputer to realize web server can also be found through baidu, but a more detailed implementation method has not been found. Here, there are two ideas that can be completed, one is wired lan module, such as w5500, this module itself has some functions of web service, which is relatively simple to use, but can only be accessed based on lan. The other is through stm32 and other single-chip computers, with the network module to complete. At present, the easiest way I can think of is to implement it in stm32+esp8266.

Based on the first method, I think it is greatly affected by the performance of the module, limited by the module, and has no sense of development. So consider the second method. In this method, someone uses arduino to do it, which is programmed based on c. In addition, consider using micropython, which can be implemented directly with python. Tpyboard V202 is still used here.

Realization of Home Intelligent Home Control platform by 0x02 Simulation

Because I didn't think about how complicated the experiment would be, I just wanted to simulate the effect, so in the whole process of the module, I chose the tpyboard v202 development board as the main control board and used a light-emitting diode to simulate a desk lamp (in reality, a relay can actually be used to control the power on and off of other devices), and a small DC motor plus a mini fan blade is used to represent the simulated fan. The whole implementation also uses a transistor (S9014 # NPN) to control the DC motor.

Construction and connection of 0x03 hardware

1. The use of light emitting diodes

Light-emitting diode is relatively easy to use, directly looking at its two "legs", the long one is the positive pole, and vice versa.

0x04 uses micropython to implement web Server

First, edit a main.py file. V202 Boot main.py File

Try: import usocket as socketexcept: import socketimport networkfrom machine import UARTfrom machine import Pinled_flag=Pin (2, Pin.OUT) # small lamp high level: off low level: bright led = Pin (4, Pin.OUT) # control pin of light emitting diode motor = Pin (5, Pin.OUT) # control pin of DC motor # initialize led.low () motor.low () led_flag.high () def do_connect (ssid Pwd): sta_if = network.WLAN (network.STA_IF) # STA mode sta_if.active (False) if not sta_if.isconnected (): # determine whether to connect sta_if.active (True) sta_if.connect (ssid) Pwd) # ssid:WIFI name pwd:WIFI password while not sta_if.isconnected (): pass if sta_if.isconnected (): return sta_if.ifconfig () [0] def main (ip_,dev_data,login_data,name,pwd): s = socket.socket () ai = socket.getaddrinfo (ip_, 80) addr = ai [0] [- 1] s.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR 1) s.bind (addr) s.listen (5) led_flag.low () # s_data=login_data while True: res = s.accept () client_s = res [0] client_addr = res [1] led_flag.high () req = client_s.readline () while True: h = client_s.readline () If h = = b "" or h = = b "\ r\ n": break # print (h) req+= (h.decode ('utf-8'). Lower () print ("Request:") req=req.decode (' utf-8'). Lower (). Split ('\ r\ n') # http header parsing req_data=req [0] .lstrip () .rstrip () .replace ('' '') print (req_data) if req_data.find ('favicon.ico') >-1: client_s.close () continue else: if len (req_data)-1 and _ pwd >-1: # determine whether the user logs in if req_data.find (name) > -1 and req_data.find (pwd) >-1: s_data=dev_data print ('Login success') Else: f=open ('fail.html','r') s_data=f.read () f.close () print (' Login failure') Else: # determine whether to control LED _ index=req_data.find ('led=') if _ index >-1: s_data=dev_data led_val=req_ data [_ index+4:_index+6] .lstrip () .rstrip () print (' led:' Led_val) if led_val=='on': led.value (1) else: led.value (0) # determine whether to control the motor _ index=req_data.find ('motor=') If _ index >-1: s_data=dev_data motor_val=req_ data [_ index+6:_index+8] .lstrip () .rstrip () print ('motor_val:' Motor_val) if motor_val=='on': motor.value (1) else: motor.value (0) print ('-') client_s.send (s_data) Client_s.close () led_flag.low () f=open ('device.html' 'r') dev_html=f.read () f.close () f=open ('login.html','r') login_html=f.read () f.close () f=open (' info.txt','r') info=f.read () f.close () name=info.split (',') .lstrip () .rstrip () pwd=info.split (',') [1] .lstrip (). Rstrip () print ('name:',name) print (' pwd:',pwd) myip_=do_connect ('essid') 'pwd') # WIFI name and password of the home network print (myip_) main (myip_,dev_html,login_html,name,pwd)

Login.html login page

Smart home network h3 {margin-top:4%; margin-bottom:40px;} Welcome to the smart home network platform

User name:

Secret code:

Device.html control page

Smart Home Network platform h3 {margin-top:4%; margin-bottom:40px;} Welcome to the Intelligent Home Network-Control platform

Lights:

Fan:

Fail.html login error page (that is, a slight change to login.html)

Smart home network h3 {margin-top:4%; margin-bottom:40px;} Welcome to log in to the smart home network platform user name or password is wrong!

User name:

Secret code:

Info.txt here is the user name and password stored in the file (separated by commas), preceded by the user name and followed by the password.

The user name and password here are used to log on to our smart home control platform.

Admin,123456

0x05 program download test

Using the MicroPython File Uploader tool, download the source code to v202.

Tool download address: http://tpyboard.com/download/tool/170.html

1. Connect v202 to the computer using the usb cable, open the device manager and view the loaded port. Mine is COM44.

"if the driver installation fails, you can download the driver for CH340 and install it manually.

Download address of CH340 driver: http://tpyboard.com/download/drive/163.html

2. Open MicroPython File Uploader to select a port, and click * * Open * *.

This is the end of the content about "how to use single-chip microcomputer to quickly realize the family intelligent control platform". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 261

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report