1.09KiB; Python | 2019-09-04 20:14:38+02 | SLOC 41
1
#----- SERVER CONNECTION -----#
2
3 1
from machine import Pin
4
import network
5 2
import time
6
7
ssid = 'AndroidAP'            #SSID of the network
8
password = 'hola1234'   #Password of the network
9
10
station = network.WLAN(network.STA_IF)
11
station.active(True)
12
station.connect(ssid, password)
13
while station.isconnected() == False:
14
    pass
15
print('Connection successful')
16
print(station.ifconfig())
17
18
#----- WEB SERVICE -----#
19
20
21
22
#----- COMMUNICATION -----#
23
24
#Sends warning to firefighters server
25
def send(ip, portn):
26 1
    import socket␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣
27
    sock = socket.socket()
28 1
␣␣␣␣
29
    sock.connect((ip, portn))
30 1
␣␣␣␣
31
    sock.send("on")
32 1
␣␣␣␣
33
    print("succesful")
34
    sock.close()
35
36
37
#Port declaration
38
39
40
41 2
import socket
42
43
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
44
s.bind(('', 8080))
45
s.listen(5)
46
47
#IP de bomberos
48
host = "192.168.43.193"
49
port = 1883
50
51
while True:
52
    conn, addr = s.accept()
53
    print('Got a connection from %s' % str(addr))
54
    request = conn.recv(1024)
55
    request = str(request.decode())
56
57
    if request == "on":
58
        send(host, port)
59
    #response = 'Holi'
60
    #conn.send(response)
61
    conn.close()