diff --git a/README.md b/README.md index 8af25c9..17d38d6 100644 --- a/README.md +++ b/README.md @@ -108,11 +108,30 @@ sudo nano /etc/default/motion ``` -N. Пишем на пыхе +6. Разбираемся с Питоном. + +```bash +sudo apt install python3-pip +pip3 install twisted autobahn pyserial + +``` + + + +```bash +git clone https://gitlab.com/zenls/rpi_remote_cam +sudo cp -r rpi_remote_cam/www/* /var/www/html/ +sudo mv /var/www/html/index.php /var/www/html/index1.php + +#работа с скрвером +scp -r * pi@10.253.35.143:~/rpi_remote_cam +sudo cp -r www/* /var/www/html/ +python3 server.py +``` ------------------------------------------ -https://github.com/silvanmelchior/RPi_Cam_Web_Interface +https://github.com/silvanmelchior/RPi_Cam_Web_Interface \ No newline at end of file diff --git a/server.py b/server.py index 27bfcd3..3a6232a 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,7 @@ import sys +import serial +import sys +import time from twisted.internet import reactor from twisted.python import log @@ -11,49 +14,89 @@ from autobahn.twisted.websocket import WebSocketServerFactory, \ from autobahn.twisted.resource import WebSocketResource i = 0 +turn_sleeptime = 0.8 +straight_sleeptime = 0.5 + +def setMotor(command): + + if command == 'D': + vacuum_serial.write(str.encode( + "SetMotor LWheelDist 155 RWheelDist 155 Speed 150 \n")) + time.sleep(straight_sleeptime) + if command == 'L': + vacuum_serial.write(str.encode( + "SetMotor LWheelDist -190 RWheelDist 190 Speed 200 \n")) + time.sleep(turn_sleeptime) + if command == 'R': + vacuum_serial.write(str.encode( + "SetMotor LWheelDist 190 RWheelDist -190 Speed 200 \n")) + time.sleep(turn_sleeptime) + if command == 'F': + vacuum_serial.write(str.encode( + "SetMotor LWheelDist -155 RWheelDist -155 Speed 150 \n")) + time.sleep(straight_sleeptime) def setServo(servoChannel, position): servoStr = str(servoChannel) + "=" + str(position) + "\n" with open("/dev/servoblaster", "wb") as f: f.write(bytes(servoStr, 'utf-8')) + class EchoServerProtocol(WebSocketServerProtocol): def onConnect(self, request): print("WebSocket connection request: {}".format(request)) def onMessage(self, payload, isBinary): - global i - i = i + 1 - if isBinary: - print("Binary message received: {0} bytes".format(len(payload))) - else: - print("Text message received: {0}".format(payload.decode('utf8'))) + global i + i = i + 1 + # if isBinary: + # print("Binary message received: {0} bytes".format(len(payload))) + # else: + # print("Text message received: {0}".format(payload.decode('utf8'))) string = " " + str(i) self.sendMessage(payload + bytes(string, 'utf-8'), isBinary) string = payload.decode('ASCII') - setServo(0, int(string.split("/")[0])) - setServo(1, int(string.split("/")[1])) + print("Str ->{0}".format(string)) + if string[0] != 'R' and string[0] != 'L' and string[0] != 'F' and string[0] != 'D': + setServo(2, int(string.split("/")[0])) + setServo(1, int(string.split("/")[1])) + else: + setMotor(string[0]) if __name__ == '__main__': - log.startLogging(sys.stdout) - - factory = WebSocketServerFactory(u"ws://10.174.136.143:45684") - factory.protocol = EchoServerProtocol - - resource = WebSocketResource(factory) - - # we server static files under "/" .. - root = File(".") - - # and our WebSocket server under "/ws" (note that Twisted uses - # bytes for URIs) - root.putChild(b"ws", resource) - - # both under one Twisted Web Site - site = Site(root) - reactor.listenTCP(45684, site) - - reactor.run() + try: + + vacuum_serial = serial.Serial('/dev/ttyACM0', 115200) + vacuum_serial.write(str.encode("testmode on \n")) + time.sleep(1) + + log.startLogging(sys.stdout) + + factory = WebSocketServerFactory(u"ws://10.253.35.143:45684") + factory.protocol = EchoServerProtocol + + resource = WebSocketResource(factory) + + # we server static files under "/" .. + root = File(".") + + # and our WebSocket server under "/ws" (note that Twisted uses + # bytes for URIs) + root.putChild(b"ws", resource) + + # both under one Twisted Web Site + site = Site(root) + reactor.listenTCP(45684, site) + + reactor.run() + + vacuum_serial.write(str.encode("testmode off \n")) + vacuum_serial.close() + + except KeyboardInterrupt: + print("Fuuuuuuuuuuuu") + vacuum_serial.write(str.encode("testmode off \n")) + vacuum_serial.close() diff --git a/www/css/main.css b/www/css/main.css index 82c0f88..2ca4d22 100644 --- a/www/css/main.css +++ b/www/css/main.css @@ -20,4 +20,10 @@ img { max-width: 100%; height: auto; - } \ No newline at end of file +} + + p { + margin-right: 5%; + margin-left: 5%; + font-size: 18px; +} diff --git a/www/index.html b/www/index.html index 2ed7f1a..06aadb0 100644 --- a/www/index.html +++ b/www/index.html @@ -18,51 +18,77 @@ + @@ -70,7 +96,8 @@

- +

-
-

Вертикаль:

-

Горизонталь:

-
+ + + + + + + +
+ +

+

+

+ +

+

+

+ +
+ +
+

Вертикаль: +

+

Горизонталь:

+
+ +
+ +