Skip to content

Commit 725e377

Browse files
committed
Solar2: FIX: Reconnect
1 parent b1b7cbf commit 725e377

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

solar2.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from gc import mem_free
2222

2323
errorcount = 0
24+
reconnectcount = 0
25+
2426
powerMode = False
2527

2628
print("octopusLab solar regulator: ", _ver)
@@ -98,27 +100,17 @@ def solar_adc(d7show = True):
98100
sleep(1)
99101

100102

101-
def wait_connect():
102-
retry = 0
103-
print("Connecing")
104-
while not net.sta_if.isconnected():
105-
print(".")
106-
retry += 1
107-
time.sleep(1)
108-
109-
if retry > 30:
110-
break
111-
112-
113103
def reconect():
114104
global errorcount
105+
global reconnectcount
106+
115107
errorcount+=1
116108
if errorcount > 4:
117109
machine.reset()
118110
else:
119111
net.sta_if.disconnect()
120-
net.sta_if.connect()
121-
wait_connect()
112+
net.connect()
113+
reconnectcount+=1
122114

123115

124116
def bmp_init():
@@ -133,30 +125,33 @@ def bmp_init():
133125

134126

135127
def send_boot():
136-
try:
137-
print("influx.write: start_boot")
138-
influx.write("octopuslab", start_boot = 1)
139-
except Exception as e:
140-
print("influx send_bme Exception: {0}".format(e))
128+
print("influx.write: start_boot")
129+
if influx.write("octopuslab", start_boot = 1):
130+
pass
131+
else:
132+
print("influx send_boot Exception: {0}".format(e))
141133

142134

143135
def send_bmp():
136+
global errorcount
144137
temp = bmp.temperature
145138
press = bmp.pressure
146139

147-
try:
148-
print("influx.write: ", temp, press)
149-
influx.write("octopuslab", temperature = temp, pressure= press)
150-
except Exception as e:
140+
print("influx.write: ", temp, press)
141+
if influx.write("octopuslab", temperature = temp, pressure = press):
142+
errorcount = 0
143+
else:
151144
print("influx send_bme Exception: {0}".format(e))
152145
reconect()
153146

154147

155148
def send_solar(s20=0,s21=0):
156-
try:
157-
print("influx.write: ", s20, s21)
158-
influx.write("octopuslab", solar20 = s20, solar21 = s21)
159-
except Exception as e:
149+
global errorcount
150+
print("influx.write: ", s20, s21)
151+
152+
if influx.write("octopuslab", solar20 = s20, solar21 = s21):
153+
errorcount = 0
154+
else:
160155
print("influx send_solar Exception: {0}".format(e))
161156
reconect()
162157

0 commit comments

Comments
 (0)