序幕
在莫斯科一家成功的大型公司中担任程序员的时候,我从未停止提高自己的编程技能,并在Udemy平台上修了各种课程。
当然,只是看着课程并在作者感到无聊之后再重复一遍,由于当时的无能,有些时刻我不明白。您需要根据课程作者提供的内容进行项目设计-我认为,当然我是对的。只有真正的困难及其解决方案才能为您提供宝贵的经验,这是真正的学习。
web , . Full-stack
, , , . JavaScript
Express
, Appolo GraphQL
( , - REST
), Apollo GQL
Vue
.
, , , , . , , , " "
, "The Facebook"
, "Instagram"
.. , , .
, , , ? ...
, 15 3 . , " , , , ". . "" — , , , .
, . - , . - . .
, " "
— 20-50 , ""
. , (, , , ), , RGB . , . . . . . . , , .
Arduino
. , , .
—
NodeMCU
— "" WI-FI
(ESP 8266
), , Arduino nano wi-fi , .. NodeMCU
, .
Arduino IDE
( Windows 10
, ), WI-FI
. , , . , , Lua
( , Micro python
, )
, , , C++ Arduino JS Python(). :
init.lua
print ( "Waiting ...")
tmr.register (0, 5000, tmr.ALARM_SINGLE, function (t) tmr.unregister (0); print ( "Starting ..."); dofile ( "main.lua") end)
tmr.start (0)
main.lua
--WiFi Settup
wifi.setmode(wifi.STATION)
local cfg={}
cfg.ssid="wifi_point_name"
cfg.pwd="point_pass"
wifi.sta.config(cfg)
cfg = nil
collectgarbage()
=wifi.ap.getip()
WI-FI
, , begin
end
. esp-8266
, . , Micro python
, , lua
.
pip install -g esptool
esptool.py --port COM3 --baud 460800 write_flash --flash_size=detect 0 esp8266-20191220-v1.12.bin
IDE
EsPy "" .
, , :
boot.py
— , . , Wi-FiWebREPL
;main.py
— ,boot.py
, .
WebREPL
— ssh
raspberri
, , EsPy
esptool
, . — WI-FI
— .
boot.py
import network
import time
''' WiFi '''
wlan_id = "my_point"
wlan_pass = "strong_pass"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if wlan.isconnected() == False:
wlan.connect(wlan_id, wlan_pass)
while wlan.isconnected() == False:
time.sleep(3)
print("Connection Fail...")
print('Device IP:', wlan.ifconfig()[0])
main.py
, , asyncio
, ( ).
main.py
from app import app_start
app_start()
MicroPyServer
( ), - ( ). .
app.py
from micropyserver import MicroPyServer
import ujson
server = MicroPyServer()
def send(self, **kwargs):
'''
'''
server.send(
ujson.dumps(kwargs),
content_type="Content-Type: application/json",
# CORS
extra_headers=["Access-Control-Allow-Origin: *"]
)
gc.collect()
def healthcheck():
send(success=1, healthcheck='green')
server.add_route("/healthcheck", healthcheck)
def app_start():
server.start()
() , , . .
main.py
boot.py
app.py
micropyserver.py
, http://192.168.1.70/
. , http://192.168.1.70/healthcheck
, — ,
// Json from chrome browser
{
"success": 1,
"healthcheck": "green",
}
hardware
( , LED-, LCD- .. ), , , . , , .
app.py
from heater import Heater
# ...
class HttpHelper:
"""
GET
"""
def __init__(self):
pass
def parse(self, request):
'''
'''
lines = request.split("\r\n")
result = {
'lines': lines,
'method': ure.search("^([A-Z]+)", lines[0]).group(1),
'path': ure.search(
"^[A-Z]+\\s+(/[-a-zA-Z0-9_.]*)", lines[0]
).group(1),
}
param_split = ure.sub("\/([a-z]+_?)+?\?", '', lines[0].split(" ")[1])
result['params'] = self.get_params(param_split.split("&"))
return result
def get_params(self, params_as_array):
'''
query
'''
params = {}
for element in params_as_array:
splited = element.split("=")
params[splited[0]] = splited[1]
return params
def send(self, **kwargs):
'''
'''
server.send(
ujson.dumps(kwargs),
content_type="Content-Type: application/json",
extra_headers=["Access-Control-Allow-Origin: *"]
)
gc.collect()
# ...
def get_water_temperature_C(request):
'''
'''
try:
water_heater.get_water_tmp_C()
http_helper.send(
success=1,
water_temperature_c=water_heater.water_tmp
)
except Exception as e:
print(e)
http_helper.send(success=0, error=e)
# ...
server.add_route("/healthcheck", healthcheck)
server.add_route("/get_water_tmp", get_water_temperature_C)
# ...
heater.py
import machine
import onewire
import ds18x20
HEATER_PIN = 2
class Heater:
def __init__(self):
self.water_tmp = 0.00
self.heater_pin = machine.Pin(HEATER_PIN)
self.sensor = ds18x20.DS18X20(onewire.OneWire(self.heater_pin))
def get_water_tmp_C(self):
rows = self.sensor.scan()
self.sensor.convert_temp()
for rom in rows:
self.water_tmp = self.sensor.read_temp(rom)
return self.water_tmp
LED . , . 5 :
- 2
- 1
- 1
- 1
32 , (24V) . , , " "
, , , . , . -, , 100% . , .
, API.
LCD , IP
, ip
. frontend
, .
IOT
, . MicroPyServer
, . , , , try except
, .
micropyserver.py
# ...
def _get_request(self):
""" Return request body """
# 4096 , MemoryError
return str(self._connect.recv(1024), "utf8")
:
- 使照明工作自动化,以便他本人可以检查房间中的照明情况,并营造出日落和黎明以及夜晚月光的效果。
- 自动化水分析
- 自动加热水
- 自动化流量泵
- 自动进纸器
- 自动填充