3
3
from _superpyhtml_ import SuperPYHTML ,MCUSERVER
4
4
5
5
if MCUSERVER :
6
- from machine import Pin ,I2C ,RTC
7
6
import utime as time
8
7
else :
9
8
import time
@@ -23,16 +22,16 @@ def set_initialdata(self):
23
22
except :
24
23
s = 0
25
24
pass
26
- self .selectedmenu = s
25
+ self .selm = s
27
26
query = ''
28
27
if 'URLQuery' in self .RD .keys ():
29
28
query = self .RD ['URLQuery' ]
30
29
cookies = ''
31
30
if 'Cookie' in self .RD .keys ():
32
31
cookies = self .RD ['Cookie' ]
33
32
34
- if self .selectedmenu >= 0 and self .selectedmenu < len (self .Menus ):
35
- title = self .Menus [self .selectedmenu ]['title' ]
33
+ if self .selm >= 0 and self .selm < len (self .Menus ):
34
+ title = self .Menus [self .selm ]['title' ]
36
35
if title == 'Welcome' :
37
36
c = "<h1>Welcome"
38
37
if self .POST != {}:
@@ -68,11 +67,12 @@ def set_initialdata(self):
68
67
69
68
def doMCUThings (self ):
70
69
self .XD ["MCUThings" ]= ""
71
- title = self .Menus [self .selectedmenu ]['title' ]
70
+ title = self .Menus [self .selm ]['title' ]
72
71
73
- if self .selectedmenu >= 0 and self .selectedmenu < len (self .Menus ):
72
+ if self .selm >= 0 and self .selm < len (self .Menus ):
74
73
if MCUSERVER :
75
74
if title == 'Welcome' :
75
+ from machine import Pin
76
76
LED = Pin (2 , Pin .IN )
77
77
if 'LED' in self .POST .keys ():
78
78
val = LED .value ()
@@ -91,6 +91,7 @@ def doMCUThings(self):
91
91
c += " <input name='LED' type='submit' value='Toggle'>"
92
92
self .XD ["MCUThings" ]+= c + "</form><BR>"
93
93
elif title == 'Status' :
94
+ from machine import RTC
94
95
if 'STATUS' in self .POST .keys ():
95
96
if self .POST ['STATUS' ] == "Set+Time" :
96
97
try :
@@ -101,7 +102,7 @@ def doMCUThings(self):
101
102
pass
102
103
t = time .localtime ()[:6 ]
103
104
c = "<p>Current time: %04d-%02d-%02d %02d:%02d:%02d</p>" % t
104
- c += '<form action="%s.py.html?menu=%d" method="post">' % (self .PYFile ,self .selectedmenu )
105
+ c += '<form action="%s.py.html?menu=%d" method="post">' % (self .PYFile ,self .selm )
105
106
c += ' <p><label for="date">date: </label><input type="text" id="date" name="date" value="%04d-%02d-%02d"></p>' % (t [:3 ])
106
107
c += ' <p><label for="time">time: </label><input type="text" id="time" name="time" value="%02d:%02d:%02d"></p>' % (t [3 :])
107
108
c += ' <input name="STATUS" type="submit" value="Set Time">'
@@ -125,7 +126,7 @@ def doMCUThings(self):
125
126
self .cfg .passphrase = self .POST ['psk' ]
126
127
self .cfg .saveconfig ()
127
128
self .XD ["MCUThings" ]+= 'Configuration saved... Please, restart server manualy'
128
- c = '<form action="%s.py.html?menu=%d" method="post">' % (self .PYFile ,self .selectedmenu )
129
+ c = '<form action="%s.py.html?menu=%d" method="post">' % (self .PYFile ,self .selm )
129
130
c += ' <p><label for="wifimode">Wifi mode: </label><select id="wifimode" name="wifimode">'
130
131
c += ' <option value="AP"%s>AP</option>' % (' selected=1' if self .cfg .wifimode == 'AP' else '' )
131
132
c += ' <option value="station"%s>Station</option>' % (' selected=1' if self .cfg .wifimode == 'station' else '' )
@@ -137,6 +138,7 @@ def doMCUThings(self):
137
138
c += '</form><BR>'
138
139
self .XD ["MCUThings" ]= c + self .XD ["MCUThings" ]
139
140
elif title == 'I2C' :
141
+ from machine import Pin ,I2C
140
142
i2c = I2C ( scl = Pin (5 ),sda = Pin (4 ),freq = 100000 )
141
143
self .XD ["MCUThings" ] = "<hr><p>I2C scan: {}</p>" .format (i2c .scan ())
142
144
return True
0 commit comments