Skip to content

Commit

Permalink
umas explicações sobre o funcionamento do programa.
Browse files Browse the repository at this point in the history
  • Loading branch information
FNakano committed Sep 20, 2022
1 parent a23a66e commit 791df01
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,64 @@

## Descrição


## Arquitetura e organização

## Explica como montar o dispositivo físico

## Explica como o motor funciona

## Explica como enviar comandos para o motor

## Explica como usar o programa

## Explica como o programa foi feito

```python
p25 = Pin(25, Pin.OUT)
motor = PWM(p25, freq=50)
motor.duty(40)
```
Fonte: https://docs.micropython.org/en/latest/esp8266/tutorial/pwm.html#control-a-hobby-servo

```python
s.bind(('', 3000)) # bind to port 3000 https://docs.micropython.org/en/latest/library/socket.html#socket.socket.bind
s.listen(2) # allow for 2 connection before refusing https://docs.micropython.org/en/latest/library/socket.html#socket.socket.listen
```

Uma requisição GET é feita (pelo navegador) concatenando, à URL (que endereça a requisição para o servidor), os parâmetros, no formato `?<id>=<valor>` no texto da requisição.

```python
request = conn.recv(1024) # get bytes https://docs.micropython.org/en/latest/library/socket.html#socket.socket.recv
request = str(request) # convert to string
```

Sobre o texto (string) da requisição, busca-se o parâmetro do GET:

```python
locker_on = request.find('/?locker=on') # find get request text https://www.w3schools.com/python/ref_string_find.asp
```

Em função do valor, o eixo do motor é girado a mais ou a menos:

```python
if locker_on == 6:
print('LOCKER ON')
motor.duty(110)
locker_state = "ON"
if locker_off == 6:
print('LOCKER OFF')
motor.duty(40)
locker_state = "OFF"
```

Ao final, a página é reenviada (não precisaria), para permitir um novo comando abre/fecha, junto com um código de resposta `HTTP-200` que significa OK (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).

## Referências

https://randomnerdtutorials.com/esp32-esp8266-micropython-web-server/
https://docs.micropython.org/en/latest/esp8266/tutorial/network_tcp.html#http-get-request


## Colaborar usando github (meta)

Expand Down
11 changes: 11 additions & 0 deletions README.md~
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

## Explica como o programa foi feito

```python
p25 = Pin(25, Pin.OUT)
motor = PWM(p25, freq=50)
motor.duty(40)
```
Fonte: https://docs.micropython.org/en/latest/esp8266/tutorial/pwm.html#control-a-hobby-servo


## Referências


## Colaborar usando github (meta)

A maneira indicada pelo mantenedor do github para colaborar com projetos hospedados nele é através de bifurcação e pull request: https://stackoverflow.com/questions/32750228/how-to-contribute-to-someone-elses-repository.
Expand Down

0 comments on commit 791df01

Please sign in to comment.