Browse Source

Move things around and refactor

Remove un-needed files and move functions from the wifi to the main file
master
Elis Hirwing 2 years ago
parent
commit
46f490e0c5
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 2
      Makefile
  2. 59
      src/main.py
  3. 14
      src/pinouts.py
  4. 55
      src/wifi.py

2
Makefile

@ -3,8 +3,6 @@ DEVICE := /dev/ttyUSB3
copy:
ampy --port $(DEVICE) put src/csms12.py
ampy --port $(DEVICE) put src/main.py
ampy --port $(DEVICE) put src/pinouts.py
ampy --port $(DEVICE) put src/wifi.py
connect:
picocom $(DEVICE) -b115200

59
src/main.py

@ -1,8 +1,65 @@
import time
from csms12 import CSMS12
import network
import socket
import time
def printloop():
csms12 = CSMS12()
while True:
print(csms12.getInterval())
time.sleep_ms(500)
def connect():
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('<ssid>', '<psk>')
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
def server():
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
sensor = CSMS12()
html = """
<!DOCTYPE html>
<html>
<head>
<title>ESP8266 Moisture Sensor v1.2</title>
<meta http-equiv="refresh" content="1">
</head>
<body>
<h1>Current moisture classification</h1>
<h2>%s</h2>
</body>
</html>
"""
s = socket.socket()
s.bind(addr)
s.listen(1)
print('listening on', addr)
while True:
cl, addr = s.accept()
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)
while True:
line = cl_file.readline()
if not line or line == b'\r\n':
break
response = html % sensor.getInterval()
cl.send(response)
cl.close()

14
src/pinouts.py

@ -1,14 +0,0 @@
class NodeMCU:
"""
Pinout mapping of the NODEMCU Board I've got.
"""
D0 = 16
D1 = 5
D2 = 4
D3 = 0
D4 = 2
D5 = 14
D6 = 12
D7 = 13
D8 = 15

55
src/wifi.py

@ -1,55 +0,0 @@
from csms12 import CSMS12
import socket
import network
def connect():
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('<ssid>', '<psk>')
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
def server():
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
sensor = CSMS12()
html = """
<!DOCTYPE html>
<html>
<head>
<title>ESP8266 Moisture Sensor v1.2</title>
<meta http-equiv="refresh" content="1">
</head>
<body>
<h1>Current moisture classification</h1>
<h2>%s</h2>
</body>
</html>
"""
s = socket.socket()
s.bind(addr)
s.listen(1)
print('listening on', addr)
while True:
cl, addr = s.accept()
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)
while True:
line = cl_file.readline()
if not line or line == b'\r\n':
break
response = html % sensor.getInterval()
cl.send(response)
cl.close()
Loading…
Cancel
Save