File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import network
2
+ import urequests
3
+ import time
4
+ from machine import ADC , Pin , reset
5
+
6
+ post_url = "https://your.influx.net:8086/write?db=octopuslab&u=usr&p=psw"
7
+ post_data = "solar,place=octopuslab,id=1 keepalive={0},solarVolt={1}"
8
+
9
+ print ("Press CTRL+C to skip booting" )
10
+ for _ in range (0 ,3 ):
11
+ print ("." )
12
+ time .sleep (1 )
13
+
14
+ net = network .WLAN ()
15
+ net .active (1 )
16
+ net .connect ("UPCDC21985" , "fuu2rFefzw6t" )
17
+
18
+ keepalive = 0
19
+ errorcount = 0
20
+
21
+ def wait_connect ():
22
+ retry = 0
23
+ print ("Connecing" )
24
+ while not net .isconnected ():
25
+ print ("." )
26
+ retry += 1
27
+ time .sleep (1 )
28
+
29
+ if retry > 30 :
30
+ break
31
+
32
+ def sendData (keepalive , solarRaw ):
33
+ global errorcount
34
+ try :
35
+ status = urequests .post (post_url , data = post_data .format (keepalive , solarRaw ))
36
+ print (status .status_code )
37
+ status .close ()
38
+ errorcount = 0
39
+ except Exception as e :
40
+ print ("Error no. {}" .format (errorcount ), e )
41
+ errorcount += 1
42
+ if errorcount > 4 :
43
+ machine .reset ()
44
+ else :
45
+ net .disconnect ()
46
+ net .connect ()
47
+ wait_connect ()
48
+
49
+
50
+ wait_connect ()
51
+
52
+ solarVoltAdc = ADC (Pin (34 ))
53
+ solarVoltAdc .atten (ADC .ATTN_11DB )
54
+
55
+ while True :
56
+ solarRaw = solarVoltAdc .read ()
57
+
58
+ sendData (keepalive , solarRaw )
59
+ print ("Solar RAW: {0}, freeMem: {1}" .format (solarRaw , gc .mem_free ()))
60
+ gc .collect ()
61
+ time .sleep (30 )
62
+ keepalive += 1
You can’t perform that action at this time.
0 commit comments