-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
39 lines (31 loc) · 1002 Bytes
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# init.py
import machine
from network import WLAN
import socket
__ssid='ssid'
__nwpass='nwpass'
# Use a static ip for easier access when developing
__myip = '192.168.1.81'
__gateway = '192.168.1.1'
__netmask = '255.255.255.0'
__dns = '8.8.8.8'
__syslogserver = '192.168.1.166'
# Syslog to the specified syslog server
# Facility USER = 1, Level ERR = 3
# <xx> = Level + Facility * 8 = 3 + 1 * 8 = 11
# Format follows BSD syslog RFC
def syslog(msg):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ret = s.sendto('<11>' + __myip + ' WiPy ' + msg, (__syslogserver, 514))
s.close()
return ret
def wlan_connect():
wifi = WLAN(mode=WLAN.STA)
wifi.ifconfig(config=(__myip, __netmask, __gateway, __dns))
wifi.scan() # scan for available networks
wifi.connect(ssid=__ssid, auth=(WLAN.WPA2, __nwpass))
while not wifi.isconnected():
pass
syslog('WiPy is up and running')
wifi.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
machine.sleep()