21
21
from gc import mem_free
22
22
23
23
errorcount = 0
24
+ reconnectcount = 0
25
+
24
26
powerMode = False
25
27
26
28
print ("octopusLab solar regulator: " , _ver )
@@ -98,27 +100,17 @@ def solar_adc(d7show = True):
98
100
sleep (1 )
99
101
100
102
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
-
113
103
def reconect ():
114
104
global errorcount
105
+ global reconnectcount
106
+
115
107
errorcount += 1
116
108
if errorcount > 4 :
117
109
machine .reset ()
118
110
else :
119
111
net .sta_if .disconnect ()
120
- net .sta_if . connect ()
121
- wait_connect ()
112
+ net .connect ()
113
+ reconnectcount += 1
122
114
123
115
124
116
def bmp_init ():
@@ -133,30 +125,33 @@ def bmp_init():
133
125
134
126
135
127
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 ))
141
133
142
134
143
135
def send_bmp ():
136
+ global errorcount
144
137
temp = bmp .temperature
145
138
press = bmp .pressure
146
139
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 :
151
144
print ("influx send_bme Exception: {0}" .format (e ))
152
145
reconect ()
153
146
154
147
155
148
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 :
160
155
print ("influx send_solar Exception: {0}" .format (e ))
161
156
reconect ()
162
157
0 commit comments